33 class SimpleConvPCNDiagnostics;
55 int inHeight,
int inWidth,
56 int kernelH,
int kernelW,
57 int strideH = 1,
int strideW = 1,
58 int padH = 0,
int padW = 0,
60 float learningRate = 1e-6f,
float inferenceRate = 0.1f,
70 void Flush() noexcept
override {}
74 void ClampState(
const std::vector<float> &inputData)
noexcept;
79 const float *
GetErrors() const noexcept
override {
return e; }
80 size_t GetInputSize() const noexcept
override {
return (
size_t)inChannels * inHeight * inWidth; }
83 return outChannels > 0 ? (size_t)outChannels * outHeight * outWidth : 0;
85 size_t GetBatchSize() const noexcept
override {
return batchSize; }
92 const float *
GetBiases() const noexcept {
return b; }
133 const float *
GetMu() const noexcept {
return mu; }
157 template <typename ArenaT>
163 int inChannels, outChannels;
164 int inHeight, inWidth;
165 int outHeight, outWidth;
166 int kernelH, kernelW;
167 int strideH, strideW;
176 float *dz_dt =
nullptr;
179 float *colBuffer =
nullptr;
180 float *feedbackScratch =
nullptr;
181 float *bottom_up_cols =
nullptr;
182 float *colsRepacked =
nullptr;
183 float *lgRepacked =
nullptr;
184 float *muRepacked =
nullptr;
190 float *onesVector =
nullptr;
192 float *cachedMu =
nullptr;
193 bool muCacheValid = false;
195 float *grad_W =
nullptr;
196 float *grad_b =
nullptr;
197 float *m_W =
nullptr;
198 float *v_W =
nullptr;
199 float *m_b =
nullptr;
200 float *v_b =
nullptr;
206 int *t_device =
nullptr;
207 float *lr_device =
nullptr;
210 bool isClamped = false;
Defines the activation functions of a predictive coding model.
Vectorized AdamW update, operating per-element over an array of weights (or biases) – NOT the single-...
A 64-byte-aligned bump-pointer allocator over a single device buffer, mirroring this codebase's host-...
Standalone im2col / col2im utilities: convolution expressed as matrix multiplication,...
A 64-byte-aligned bump-pointer allocator over a single heap-allocated block, used to pack every layer...
Device-agnostic compute backend interface: every numerical primitive a layer/network needs,...
Definition IComputeBackend.h:14
A deepity layer virtual class.
Definition Layer.h:40
A 64-byte-aligned bump-pointer allocator over a single contiguous block of host memory....
Definition MemoryArena.h:141
Convolutional PC layer, precision-free, AdamW-capable, routed through IComputeBackend for GPU portabi...
Definition SimpleConvPCLayer.h:39
void SetOptimizer(const OptimizerType o) noexcept
Sets the weight optimizer. Call BEFORE Compile().
Definition SimpleConvPCLayer.h:110
void Flush() noexcept override
Flushes remaining batches.
Definition SimpleConvPCLayer.h:70
void BindMemory(ArenaT &arena)
Binds this layer's buffers into a pre-allocated arena (MemoryArena for CPU, DeviceMemoryArena for GPU...
Definition SimpleConvPCLayer.cpp:93
int GetOutHeight() const noexcept
Returns the output height.
Definition SimpleConvPCLayer.h:143
float * GetBiases() noexcept
Mutable overload of GetBiases() above.
Definition SimpleConvPCLayer.h:94
void SetInferenceRate(float ir) noexcept
Sets the inference rate.
Definition SimpleConvPCLayer.h:106
void SetLambda(float l) noexcept
Sets the weight decay coefficient.
Definition SimpleConvPCLayer.h:108
int GetInWidth() const noexcept
Returns the input width.
Definition SimpleConvPCLayer.h:141
size_t GetBatchSize() const noexcept override
Should return batch size.
Definition SimpleConvPCLayer.h:85
int GetKernelH() const noexcept
Returns the kernel height.
Definition SimpleConvPCLayer.h:147
size_t GetInputSize() const noexcept override
Should return input size.
Definition SimpleConvPCLayer.h:80
int GetOutWidth() const noexcept
Returns the output width.
Definition SimpleConvPCLayer.h:145
ActivationType GetActivationType() const noexcept
Returns this layer's activation type.
Definition SimpleConvPCLayer.h:128
int GetInHeight() const noexcept
Returns the input height.
Definition SimpleConvPCLayer.h:139
const float * GetErrors() const noexcept override
Should return errors e.
Definition SimpleConvPCLayer.h:79
void SetLearningRate(float lr) noexcept
Sets the learning rate, propagating it to the optimizer state.
Definition SimpleConvPCLayer.cpp:43
float GetLambda() const noexcept
Returns the current weight decay coefficient.
Definition SimpleConvPCLayer.h:101
int GetKernelW() const noexcept
Returns the kernel width.
Definition SimpleConvPCLayer.h:149
void ClampState(const std::vector< float > &inputData) noexcept
Clamps this layer's beliefs to inputData, fixing them against UpdateState() until UnclampState() is c...
Definition SimpleConvPCLayer.cpp:405
size_t GetRequiredFloats() const noexcept
Total floats this layer needs from its MemoryArena.
Definition SimpleConvPCLayer.cpp:50
size_t GetOutputSize() const noexcept override
Should return output size.
Definition SimpleConvPCLayer.h:81
void SetLayerAbove(SimpleConvPCLayer *above) noexcept
Sets the layer immediately above this one in the network.
Definition SimpleConvPCLayer.h:115
float GetLearningRate() const noexcept
Returns the current learning rate.
Definition SimpleConvPCLayer.h:97
int GetInChannels() const noexcept
Returns the input channel count.
Definition SimpleConvPCLayer.h:135
void UpdateState() noexcept override
Updates the states after calculation.
Definition SimpleConvPCLayer.cpp:268
void SetLayerBelow(SimpleConvPCLayer *below) noexcept
Sets the layer immediately below this one in the network.
Definition SimpleConvPCLayer.h:117
friend class SimpleConvPCNDiagnostics
Definition SimpleConvPCLayer.h:221
float * GetBeliefs() noexcept override
Should return belief state z.
Definition SimpleConvPCLayer.h:78
float GetInferenceRate() const noexcept
Returns the current inference rate.
Definition SimpleConvPCLayer.h:99
void ResetState() noexcept
Resets this layer's beliefs (z) without touching learned weights.
Definition SimpleConvPCLayer.cpp:399
SimpleConvPCLayer(int inChannels, int outChannels, int inHeight, int inWidth, int kernelH, int kernelW, int strideH=1, int strideW=1, int padH=0, int padW=0, int batchSize=1, float learningRate=1e-6f, float inferenceRate=0.1f, float lmbda=1e-2f, ActivationType aType=ActivationType::RELU, ActivationType dType=ActivationType::dRELU, IComputeBackend *backend=nullptr)
Definition SimpleConvPCLayer.cpp:14
void UpdateWeights() noexcept override
Updates the weights after state updates.
Definition SimpleConvPCLayer.cpp:316
ActivationType GetDerivativeType() const noexcept
Returns this layer's activation derivative type.
Definition SimpleConvPCLayer.h:130
const float * GetBiases() const noexcept
Returns the bias vector, length outChannels.
Definition SimpleConvPCLayer.h:92
const float * GetWeights() const noexcept
Returns the weight tensor, shape [outChannels, inChannels*kernelH*kernelW].
Definition SimpleConvPCLayer.h:88
float CalculateState() noexcept override
Calculates the internal state of the layer.
Definition SimpleConvPCLayer.cpp:202
const float * GetMu() const noexcept
Returns this layer's forward prediction buffer.
Definition SimpleConvPCLayer.h:133
void UnclampState() noexcept
Releases a previous ClampState() call.
Definition SimpleConvPCLayer.cpp:414
void RandomizeWeights(std::mt19937 &twister) noexcept
Randomizes W/b.
Definition SimpleConvPCLayer.cpp:187
bool IsClamped() const noexcept
Whether ClampState() is currently active on this layer.
Definition SimpleConvPCLayer.h:112
float * GetWeights() noexcept
Mutable overload of GetWeights() above.
Definition SimpleConvPCLayer.h:90
void ComputeMuOnly() noexcept
Computes only mu (forward prediction), skipping error/energy.
Definition SimpleConvPCLayer.cpp:223
int GetOutChannels() const noexcept
Returns the output channel count (0 for a terminal layer).
Definition SimpleConvPCLayer.h:137
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
@ RELU
Definition ActivationType.h:26
@ dRELU
Definition ActivationType.h:27
OptimizerType
Selects which weight-update rule a layer applies during UpdateWeights().
Definition AdamOptimizer.h:52
@ SGD
Plain stochastic gradient descent (this codebase's existing cblas-based update).
Definition AdamOptimizer.h:53