66 void AddLayer(
int size,
int nextSize,
float lr,
float ir,
float lmbda,
67 void (*act)(
float *,
size_t),
void (*dAct)(
float *,
size_t,
bool));
80 void AddLayer(
int size,
int nextSize,
float lr,
float ir,
float lmbda,
97 void Clamp(const std::vector<
float> &input);
118 std::vector<std::unique_ptr<SimplePCLayer>> &
GetLayers() noexcept {
return layers; }
122 const std::vector<std::unique_ptr<SimplePCLayer>> &
GetLayers() const noexcept {
return layers; }
135 for (
auto &layer : layers)
136 layer->SetOptimizer(o);
144 float TrainStep(
const std::vector<float> &x,
const std::vector<float> &y,
int inferenceSteps);
150 std::vector<float>
Predict(
const std::vector<float> &x,
int inferenceSteps);
183 int inferenceSteps,
bool computeEnergy = true);
212 bool graphCaptured = false;
213 int capturedInferenceSteps = -1;
225#if defined(DEEPITY_USE_CUDA)
226 std::unique_ptr<DeviceMemoryArena> gpuArena;
A 64-byte-aligned bump-pointer allocator over a single device buffer, mirroring this codebase's host-...
A 64-byte-aligned bump-pointer allocator over a single heap-allocated block, used to pack every layer...
DiscriminativePCLayer with precision entirely removed.
Device-agnostic compute backend interface: every numerical primitive a layer/network needs,...
Definition IComputeBackend.h:14
A 64-byte-aligned bump-pointer allocator over a single contiguous block of host memory....
Definition MemoryArena.h:141
Predictive Coding layer without precision weighting – the simpler, unweighted-energy counterpart to D...
Definition SimplePCLayer.h:79
SimplePCLayer * GetTerminalLayer() noexcept
Returns the network's terminal (final) layer.
Definition SimplePCNetwork.h:114
SimplePCNetwork & operator=(const SimplePCNetwork &)=delete
void UpdateWeights()
Updates each layer's weights.
Definition SimplePCNetwork.cpp:80
std::vector< float > PredictWithProjection(const std::vector< float > &x, int inferenceSteps)
Inference-only counterpart to TrainStepWithProjection(): reset, clamp input, project forward,...
Definition SimplePCNetwork.cpp:205
float CalculateState(bool needEnergy=true)
Calculates the state of each layer.
Definition SimplePCNetwork.cpp:66
int GetBatchSize() const noexcept
Returns the batch size for the network's layers.
Definition SimplePCNetwork.h:126
void UpdateState()
Updates each layer's state.
Definition SimplePCNetwork.cpp:74
float TrainStep(const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps)
Runs a complete training step (clamp, settle, update, unclamp).
Definition SimplePCNetwork.cpp:86
SimplePCNetwork(const SimplePCNetwork &)=delete
void SetOptimizer(OptimizerType o) noexcept
Sets the optimizer used for weight updates on every layer.
Definition SimplePCNetwork.h:133
std::vector< float > Predict(const std::vector< float > &x, int inferenceSteps)
Runs a forward prediction pass (clamp, settle, read).
Definition SimplePCNetwork.cpp:106
void AddLayer(int size, int nextSize, float lr, float ir, float lmbda, void(*act)(float *, size_t), void(*dAct)(float *, size_t, bool))
Adds a layer to the network.
Definition SimplePCNetwork.cpp:15
void Compile()
Loads all layers into one contiguous block of memory (MemoryArena for DEVICE_CPU, DeviceMemoryArena f...
Definition SimplePCNetwork.cpp:232
float TrainStepWithProjection(const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps, bool computeEnergy=true)
Full train step WITH forward-projection initialization, all in ONE call – reset, clamp,...
Definition SimplePCNetwork.cpp:143
DeviceType GetDevice() const noexcept
Returns which device this network's layers run on.
Definition SimplePCNetwork.h:129
void RandomizeWeights(std::mt19937 &rng, const char *distribution)
Randomizes the weights of each layer.
Definition SimplePCNetwork.cpp:43
SimplePCNetwork(int batchSize, DeviceType device=DeviceType::DEVICE_CPU) noexcept
Constructs an empty network with a predetermined batch size.
Definition SimplePCNetwork.cpp:9
std::vector< std::unique_ptr< SimplePCLayer > > & GetLayers() noexcept
Returns every layer in the network, in the order they were added.
Definition SimplePCNetwork.h:118
void SetMuCacheThreshold(float threshold) noexcept
Sets mu-cache threshold on every layer – see SimplePCLayer::SetMuCacheThreshold() for semantics....
Definition SimplePCNetwork.cpp:226
void Clamp(const std::vector< float > &input)
Clamps the input to the first layer, necessary for prediction.
Definition SimplePCNetwork.cpp:61
const std::vector< std::unique_ptr< SimplePCLayer > > & GetLayers() const noexcept
Returns every layer in the network, in the order they were added.
Definition SimplePCNetwork.h:122
~SimplePCNetwork()=default
void ResetState() noexcept
Resets each layer's state without touching learned weights.
Definition SimplePCNetwork.cpp:55
void ProjectForward() noexcept
Runs a single, non-iterative forward pass through current weights, seeding each hidden layer's z from...
Definition SimplePCNetwork.cpp:126
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10
ActivationType
Identifies an activation function or its derivative, for dispatch tables and layer/backend APIs that ...
Definition ActivationType.h:25
OptimizerType
Selects which weight-update rule a layer applies during UpdateWeights().
Definition AdamOptimizer.h:52
DeviceType
Which physical device a Tensor/IComputeBackend pair runs on.
Definition DeviceType.h:8
@ DEVICE_CPU
Definition DeviceType.h:9