74 class SimplePCNDiagnostics;
98 float learningRate = 1e-6f,
float inferenceRate = 0.1f,
float lmbda = 1e-2f,
99 void (*act)(
float *,
size_t) =
relu,
100 void (*dAct)(
float *,
size_t,
bool) =
dRelu,
118 float learningRate = 1e-6f,
float inferenceRate = 0.1f,
float lmbda = 1e-2f,
159 void ClampState(
const std::vector<float> &inputData)
noexcept;
176 const float *
GetMu() const noexcept {
return mu; }
180 const float *
GetErrors() const noexcept
override {
return e; }
270 void RandomizeWeights(std::mt19937 &twister,
const char *distribution =
"normal") noexcept;
289 template <typename ArenaT>
329 float *feedbackScratch;
338 bool isClamped = false;
340 int *t_device =
nullptr;
341 float *lr_device =
nullptr;
343 float muCacheThreshold = -1.0f;
347 bool muCacheValid = false;
361 float *grad_W =
nullptr;
362 float *grad_b =
nullptr;
363 float *m_W =
nullptr;
364 float *v_W =
nullptr;
365 float *m_b =
nullptr;
366 float *v_b =
nullptr;
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-...
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
size_t nextSize
Size of output.
Definition Layer.h:76
size_t size
Size of input.
Definition Layer.h:74
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
void UnclampState() noexcept
Releases a previous ClampState() call, allowing this layer's beliefs to update normally again.
Definition SimplePCLayer.cpp:245
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 SimplePCLayer.cpp:238
ActivationType GetDerivativeType() const noexcept
Returns this layer's configured activation-derivative type.
Definition SimplePCLayer.h:275
const float * GetWeights() const noexcept
Returns this layer's weight buffer.
Definition SimplePCLayer.h:190
void ResetState() noexcept
Resets this layer's beliefs/errors back to their initial values, without touching learned weights.
Definition SimplePCLayer.cpp:233
size_t GetRequiredFloats() const noexcept
Computes the total number of floats this layer requires from a MemoryArena (weights,...
Definition SimplePCLayer.cpp:247
float GetInferenceRate() const noexcept
Returns the inference rate (Euler integration step size).
Definition SimplePCLayer.h:201
ActivationType GetActivationType() const noexcept
Returns this layer's configured activation type.
Definition SimplePCLayer.h:273
float GetMuCacheThreshold() const noexcept
Returns the current mu-cache staleness threshold – see SetMuCacheThreshold() above.
Definition SimplePCLayer.h:234
void UpdateState() noexcept override
Computes the state derivatives for inference.
Definition SimplePCLayer.cpp:158
const float * GetMu() const noexcept
Returns a prediction buffer exposed specifically for forward-projection initialization (seeding the n...
Definition SimplePCLayer.h:176
friend class SimplePCNDiagnostics
Definition SimplePCLayer.h:369
void RandomizeWeights(std::mt19937 &twister, const char *distribution="normal") noexcept
Randomizes this layer's weights (and biases) in place.
Definition SimplePCLayer.cpp:83
const SimplePCLayer & GetLayerAbove() const noexcept
Returns the layer immediately above this one.
Definition SimplePCLayer.h:260
size_t GetOutputSize() const noexcept override
Returns this layer's outgoing prediction size (0 for a terminal layer).
Definition SimplePCLayer.h:185
void SetInferenceRate(float ir) noexcept
Sets the inference rate (Euler integration step size).
Definition SimplePCLayer.h:210
size_t GetInputSize() const noexcept override
Returns this layer's own belief size.
Definition SimplePCLayer.h:182
void SetOptimizer(const OptimizerType o) noexcept
Selects the optimizer used for weight updates (SGD or Adam). Adam's moment buffers are lazily allocat...
Definition SimplePCLayer.h:218
float CalculateState() noexcept override
Calculates the internal state of the layer.
Definition SimplePCLayer.h:137
void UpdateWeights() noexcept override
Computes weight updates via gradient descent, with L2 weight decay.
Definition SimplePCLayer.cpp:184
float * GetBeliefs() noexcept override
Returns this layer's belief buffer.
Definition SimplePCLayer.h:169
float * GetWeights() noexcept
Returns this layer's weight buffer.
Definition SimplePCLayer.h:192
void SetLayerAbove(SimplePCLayer *above) noexcept
Sets the layer immediately above this one in the network.
Definition SimplePCLayer.h:246
const float * GetBiases() const noexcept
Returns this layer's bias buffer.
Definition SimplePCLayer.h:194
void BindMemory(ArenaT &arena)
Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any ot...
Definition SimplePCLayer.cpp:279
void ComputeMuOnly() noexcept
Computes only mu (forward prediction), skipping error/energy entirely. Extracted from CalculateState(...
Definition SimplePCLayer.cpp:133
SimplePCLayer(size_t size, size_t nextSize, size_t batchSize=1, float learningRate=1e-6f, float inferenceRate=0.1f, float lmbda=1e-2f, void(*act)(float *, size_t)=relu, void(*dAct)(float *, size_t, bool)=dRelu, IComputeBackend *backend=nullptr)
Constructor for a SimplePCLayer.
Definition SimplePCLayer.cpp:43
float GetLambda() const noexcept
Returns the weight-decay (L2 regularization) coefficient.
Definition SimplePCLayer.h:203
float GetLearningRate() const noexcept
Returns the learning rate used for weight updates.
Definition SimplePCLayer.h:199
void SetMuCacheThreshold(float threshold) noexcept
Sets the mu-cache staleness threshold: mu is recomputed only when ||z - z_at_last_recompute|| / (||z_...
Definition SimplePCLayer.h:231
bool IsClamped() const noexcept
Whether ClampState() is currently active on this layer.
Definition SimplePCLayer.h:165
const SimplePCLayer & GetLayerBelow() const noexcept
Returns the layer immediately below this one.
Definition SimplePCLayer.h:265
float * GetBiases() noexcept
Returns this layer's bias buffer.
Definition SimplePCLayer.h:196
size_t GetBatchSize() const noexcept override
Returns the batch size this layer was constructed with.
Definition SimplePCLayer.h:187
void SetLayerBelow(SimplePCLayer *below) noexcept
Sets the layer immediately below this one in the network.
Definition SimplePCLayer.h:250
void SetLearningRate(float lr) noexcept
Sets the learning rate used for weight updates.
Definition SimplePCLayer.cpp:274
void SetLambda(float l) noexcept
Sets the weight-decay (L2 regularization) coefficient.
Definition SimplePCLayer.h:213
void Flush() noexcept override
No-op; exists for Layer interface conformance.
Definition SimplePCLayer.h:154
const float * GetErrors() const noexcept override
Returns this layer's prediction-error buffer.
Definition SimplePCLayer.h:180
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
void(*)(float *RESTRICT, const float *RESTRICT, size_t) DerivativeFn2
Pointer to a two-buffer activation derivative: reads src, writes the derivative into dst,...
Definition ActivationDispatch.h:27
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
static void relu(float *, size_t) noexcept
See Relu.h.
void(*)(float *, size_t, bool) DerivativeFn
Pointer to an in-place activation derivative: f(buf, n, activated).
Definition ActivationDispatch.h:20
static void dRelu(float *, size_t, bool) noexcept
See Relu.h.
void(*)(float *, size_t) ActivationFn
Pointer to an in-place activation function: f(buf, n).
Definition ActivationDispatch.h:18