79 class GaussSeidelPCNDiagnostics;
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);
114 float learningRate = 1e-6f,
float inferenceRate = 0.1f,
float lmbda = 1e-2f,
156 void ClampState(
const std::vector<float> &inputData)
noexcept;
165 const float *
GetMu() const noexcept {
return mu; }
168 const float *
GetErrors() const noexcept
override {
return e; }
305 bool isClamped = false;
321 float *grad_W =
nullptr;
323 float *grad_b =
nullptr;
325 float *m_W =
nullptr;
327 float *v_W =
nullptr;
329 float *m_b =
nullptr;
331 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 heap-allocated block, used to pack every layer...
PC layer with Gauss-Seidel (sequential-sweep) settling dynamics, in place of the usual simultaneous u...
Definition GaussSeidelPCLayer.h:85
size_t GetOutputSize() const noexcept override
Returns this layer's outgoing prediction size (0 for a terminal layer).
Definition GaussSeidelPCLayer.h:175
void RandomizeWeights(std::mt19937 &twister) noexcept
Randomizes this layer's weights (and the E feedback-alignment matrix) in place.
Definition GaussSeidelPCLayer.cpp:250
float * GetBiases() noexcept
Returns a mutable version of the stored biases.
Definition GaussSeidelPCLayer.h:191
float * GetWeights() noexcept
Returns a mutable version of the stored weights.
Definition GaussSeidelPCLayer.h:185
float * GetBeliefs() noexcept override
Returns this layer's belief buffer.
Definition GaussSeidelPCLayer.h:162
void SetOptimizer(const OptimizerType o) noexcept
Selects the optimizer used for weight updates.
Definition GaussSeidelPCLayer.h:214
const float * GetWeights() const noexcept
Returns a read-only version of the stored weights.
Definition GaussSeidelPCLayer.h:182
const float * GetBiases() const noexcept
Returns a read-only version of the stored biases.
Definition GaussSeidelPCLayer.h:188
float CalculateState() noexcept override
Step 1 of a Gauss-Seidel timestep: updates z using mu/e_above HELD OVER from the end of the previous ...
Definition GaussSeidelPCLayer.h:123
GaussSeidelPCLayer(int size, int nextSize, int 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)
Constructor for a GaussSeidelPCLayer.
Definition GaussSeidelPCLayer.cpp:14
void SetInferenceRate(float ir) noexcept
Sets the inference rate (Euler integration step size).
Definition GaussSeidelPCLayer.h:208
float GetLearningRate() const noexcept
Returns the learning rate used for weight updates.
Definition GaussSeidelPCLayer.h:195
ActivationType GetDerivativeType() const noexcept
Returns this layer's configured activation-derivative type.
Definition GaussSeidelPCLayer.h:250
void ComputePrediction() noexcept
Step 2 of a Gauss-Seidel timestep: recomputes mu fresh, using the z JUST updated by UpdateState() in ...
Definition GaussSeidelPCLayer.cpp:117
void ClampState(const std::vector< float > &inputData) noexcept
Clamps this layer's beliefs to externally-provided data.
Definition GaussSeidelPCLayer.cpp:41
const GaussSeidelPCLayer & GetLayerBelow() const noexcept
Returns the layer immediately below this one.
Definition GaussSeidelPCLayer.h:238
void ResetState() noexcept
Resets beliefs/errors/predictions back to their initial values, without touching learned weights.
Definition GaussSeidelPCLayer.cpp:53
const float * GetMu() const noexcept
Returns this layer's outgoing prediction buffer.
Definition GaussSeidelPCLayer.h:165
friend class GaussSeidelPCNDiagnostics
Definition GaussSeidelPCLayer.h:335
void UpdateWeights() noexcept override
Computes weight updates via gradient descent, with L2 weight decay. Called once after the full settli...
Definition GaussSeidelPCLayer.cpp:185
const float * GetErrors() const noexcept override
Returns this layer's prediction-error buffer.
Definition GaussSeidelPCLayer.h:168
ActivationType GetActivationType() const noexcept
Returns this layer's configured activation type.
Definition GaussSeidelPCLayer.h:247
const GaussSeidelPCLayer & GetLayerAbove() const noexcept
Returns the layer immediately above this one.
Definition GaussSeidelPCLayer.h:233
void Flush() noexcept override
No-op; exists for Layer interface conformance.
Definition GaussSeidelPCLayer.h:152
float GetInferenceRate() const noexcept
Returns the inference rate (Euler integration step size).
Definition GaussSeidelPCLayer.h:198
void SetLambda(float l) noexcept
Sets the weight-decay (L2 regularization) coefficient.
Definition GaussSeidelPCLayer.h:211
void SetLayerBelow(GaussSeidelPCLayer *below) noexcept
Sets the layer immediately below this one in the network.
Definition GaussSeidelPCLayer.h:223
void BindMemory(MemoryArena &arena)
Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any ot...
Definition GaussSeidelPCLayer.cpp:324
size_t GetInputSize() const noexcept override
Returns this layer's own belief size.
Definition GaussSeidelPCLayer.h:171
size_t GetRequiredFloats() const noexcept
Computes the total number of floats this layer requires from a MemoryArena.
Definition GaussSeidelPCLayer.cpp:294
float ComputeError() noexcept
Step 3 of a Gauss-Seidel timestep: recomputes e fresh, using this layer's own (just-updated) z as the...
Definition GaussSeidelPCLayer.cpp:160
void SetLearningRate(float lr) noexcept
Sets the learning rate used for weight updates.
Definition GaussSeidelPCLayer.h:205
float GetLambda() const noexcept
Returns the weight-decay (L2 regularization) coefficient.
Definition GaussSeidelPCLayer.h:201
void UpdateState() noexcept override
Step 1: the actual z-update. See class-level docs for the required three-sweep calling order.
Definition GaussSeidelPCLayer.cpp:67
void UnclampState() noexcept
Releases a previous ClampState() call.
Definition GaussSeidelPCLayer.cpp:48
size_t GetBatchSize() const noexcept override
Returns the batch size this layer was constructed with.
Definition GaussSeidelPCLayer.h:178
void SetLayerAbove(GaussSeidelPCLayer *above) noexcept
Sets the layer immediately above this one in the network.
Definition GaussSeidelPCLayer.h:219
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
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
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