68 ConvPCLayer(
int inChannels,
int outChannels,
int inHeight,
int inWidth,
69 int kernelH,
int kernelW,
int strideH = 1,
int strideW = 1,
70 int padH = 0,
int padW = 0,
int batchSize = 1,
71 float learningRate = 1e-6f,
float inferenceRate = 0.1f,
72 float precisionRate = 0.01f,
float lmbda = 1e-2f,
93 void Flush() noexcept
override {}
99 void ClampState(
const std::vector<float> &inputData)
noexcept;
111 const float *
GetErrors() const noexcept
override {
return e; }
114 const float *
GetMu() const noexcept {
return mu; }
118 return (
size_t)inChannels * inHeight * inWidth;
123 return outChannels > 0 ? (size_t)outChannels * outHeight * outWidth : 0;
206 return To_AType(activationDerivative);
241 int inChannels, outChannels;
242 int inHeight, inWidth;
243 int outHeight, outWidth;
244 int kernelH, kernelW;
245 int strideH, strideW;
259 float *dz_dt =
nullptr;
262 float *log_p =
nullptr;
274 float *colBuffer =
nullptr;
279 float *feedbackScratch =
nullptr;
284 float *bottom_up_cols =
nullptr;
290 float *colsRepacked =
nullptr;
293 float *lgRepacked =
nullptr;
296 float *muRepacked =
nullptr;
300 float *cachedMu =
nullptr;
302 bool muCacheValid = false;
304 float lr, ir, pr, lmbda;
305 bool isClamped = false;
Defines the activation functions of a predictive coding model.
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...
Convolutional Predictive Coding layer (im2col-based). See the file-level warning above before enablin...
Definition ConvPCLayer.h:46
const float * GetMu() const noexcept
Returns this layer's top-down prediction buffer.
Definition ConvPCLayer.h:114
const float * GetErrors() const noexcept override
Returns this layer's prediction-error buffer.
Definition ConvPCLayer.h:111
float * GetBiases() noexcept
Returns this layer's bias buffer.
Definition ConvPCLayer.h:140
void UpdateWeights() noexcept override
Hebbian/gradient weight update.
Definition ConvPCLayer.cpp:331
void SetPrecisionRate(float pr) noexcept
Sets the learning rate used for precision updates.
Definition ConvPCLayer.h:166
const float * GetPrecisions() const noexcept
Returns this layer's precision buffer.
Definition ConvPCLayer.h:143
void SetLayerAbove(ConvPCLayer *above) noexcept
Sets the layer immediately above this one in the network.
Definition ConvPCLayer.h:174
float GetLambda() const noexcept
Returns the weight-decay (L2 regularization) coefficient.
Definition ConvPCLayer.h:156
int GetKernelH() const noexcept
Returns the convolution kernel height.
Definition ConvPCLayer.h:222
void SetLambda(float l) noexcept
Sets the weight-decay (L2 regularization) coefficient.
Definition ConvPCLayer.h:169
void ResyncLogPrecision() noexcept
Rebuilds log_p from p – required after a checkpoint load that only persists p (mirrors Discriminative...
Definition ConvPCLayer.cpp:452
void SetLayerBelow(ConvPCLayer *below) noexcept
Sets the layer immediately below this one in the network.
Definition ConvPCLayer.h:178
int GetOutHeight() const noexcept
Returns the output feature-map height.
Definition ConvPCLayer.h:218
friend class PCNDiagnostics
Definition ConvPCLayer.h:313
int GetInHeight() const noexcept
Returns the input feature-map height.
Definition ConvPCLayer.h:214
float GetPrecisionRate() const noexcept
Returns the learning rate used for precision updates.
Definition ConvPCLayer.h:153
void UpdatePrecision() noexcept
Updates this layer's precision estimate from current prediction errors, using the configured precisio...
Definition ConvPCLayer.cpp:409
ActivationType GetActivationType() const noexcept
Returns this layer's configured activation type.
Definition ConvPCLayer.h:200
size_t GetOutputSize() const noexcept override
Flattened element count of this layer's OUTGOING prediction (outChannels*outH*outW),...
Definition ConvPCLayer.h:122
float GetLearningRate() const noexcept
Returns the learning rate used for weight updates.
Definition ConvPCLayer.h:147
int GetOutWidth() const noexcept
Returns the output feature-map width.
Definition ConvPCLayer.h:220
size_t GetBatchSize() const noexcept override
Returns the batch size this layer was constructed with.
Definition ConvPCLayer.h:127
int GetInWidth() const noexcept
Returns the input feature-map width.
Definition ConvPCLayer.h:216
int GetOutChannels() const noexcept
Returns the number of output channels (0 for a terminal layer).
Definition ConvPCLayer.h:212
void UnclampState() noexcept
Releases a previous ClampState() call, allowing this layer's beliefs to update normally again.
Definition ConvPCLayer.cpp:447
void SetLearningRate(float lr) noexcept
Sets the learning rate used for weight updates.
Definition ConvPCLayer.h:160
const float * GetBiases() const noexcept
Returns this layer's bias buffer.
Definition ConvPCLayer.h:137
std::map< std::string, TensorDescriptor > GetStateDict() const override
Returns a dictionary of this.
Definition ConvPCLayer.cpp:76
void ClampState(const std::vector< float > &inputData) noexcept
Clamps this layer's beliefs to externally-provided data, preventing them from being updated by Update...
Definition ConvPCLayer.cpp:438
float * GetWeights() noexcept
Returns this layer's weight buffer.
Definition ConvPCLayer.h:134
float CalculateState() noexcept override
Calculate energy/prediction errors for this layer.
Definition ConvPCLayer.cpp:170
size_t GetInputSize() const noexcept override
Flattened element count per batch item (inChannels*H*W).
Definition ConvPCLayer.h:117
ActivationType GetDerivativeType() const noexcept
Returns this layer's configured activation-derivative type.
Definition ConvPCLayer.h:205
void ResetState() noexcept
Resets this layer's beliefs/errors back to their initial values, without touching learned weights.
Definition ConvPCLayer.cpp:432
void RandomizeWeights(std::mt19937 &twister) noexcept
Randomizes this layer's weights (and biases) in place.
Definition ConvPCLayer.cpp:146
float GetInferenceRate() const noexcept
Returns the learning rate used for internal-state updates.
Definition ConvPCLayer.h:150
const float * GetWeights() const noexcept
Returns this layer's weight buffer.
Definition ConvPCLayer.h:131
int GetInChannels() const noexcept
Returns the number of input channels.
Definition ConvPCLayer.h:210
void SetInferenceRate(float ir) noexcept
Sets the learning rate used for internal-state updates.
Definition ConvPCLayer.h:163
size_t GetRequiredFloats() const noexcept
Computes the total number of floats this layer requires from a MemoryArena (weights,...
Definition ConvPCLayer.cpp:43
int GetKernelW() const noexcept
Returns the convolution kernel width.
Definition ConvPCLayer.h:224
void BindMemory(MemoryArena &arena)
Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any ot...
Definition ConvPCLayer.cpp:83
ConvPCLayer(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 precisionRate=0.01f, float lmbda=1e-2f, ActivationType aType=ActivationType::RELU, ActivationType dType=ActivationType::dRELU)
Constructor for a convolutional PC layer.
Definition ConvPCLayer.cpp:15
float * GetBeliefs() noexcept override
Returns this layer's belief buffer.
Definition ConvPCLayer.h:107
void ComputeMuOnly() noexcept
Fast-path forward projection that skips state initialization.
Definition ConvPCLayer.cpp:213
void UpdateState() noexcept override
Update latent beliefs (z/r) via inference gradient.
Definition ConvPCLayer.cpp:265
void Flush() noexcept override
No-op; exists for Layer interface conformance.
Definition ConvPCLayer.h:93
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
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10
static ActivationType To_AType(ActivationFn fn)
Reverse lookup of To_Fn(): maps a function pointer back to its ActivationType, by identity comparison...
Definition ActivationDispatch.h:152
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
void(*)(float *, size_t, bool) DerivativeFn
Pointer to an in-place activation derivative: f(buf, n, activated).
Definition ActivationDispatch.h:20
void(*)(float *, size_t) ActivationFn
Pointer to an in-place activation function: f(buf, n).
Definition ActivationDispatch.h:18
A named, shaped view into a layer's weight/bias data, for ModelIO's save/load (see Layer::GetStateDic...
Definition Layer.h:34