PC layer combining muPC scaling, optional residual connections, and DKP direct feedback – every extra OFF by default, so plain defaults reproduce DirectKPPCLayer exactly. See the file-level note above for the full design rationale.
More...
|
| | FullPCLayer (size_t size, size_t nextSize, size_t terminalSize, size_t batchSize, float learningRate, float inferenceRate, float feedback, float lmbda, ActivationType aType, ActivationType dType, IComputeBackend *backend=nullptr) |
| | ~FullPCLayer () override=default |
| template<typename ArenaT> |
| void | BindMemory (ArenaT &arena) |
| | Binds this layer's buffers into a pre-allocated arena (MemoryArena for CPU, DeviceMemoryArena for GPU).
|
| size_t | GetRequiredFloats () const noexcept |
| | Total floats this layer needs from its MemoryArena.
|
| void | RandomizeWeights (std::mt19937 &seedGenerator) noexcept |
| | Randomizes W and Psi.
|
| std::map< std::string, TensorDescriptor > | GetStateDict () const override |
| | Returns a dictionary of this.
|
| void | SetLayerAbove (FullPCLayer *l) noexcept |
| | Sets the layer immediately above this one in the network.
|
| void | SetLayerBelow (FullPCLayer *l) noexcept |
| | Sets the layer immediately below this one in the network.
|
| void | SetTerminalLayer (FullPCLayer *l) noexcept |
| | Sets the network's terminal layer, for DirectFeedbackUpdate().
|
| void | SetMuPCScale (float a) noexcept |
| | Set by the owning network at Compile() time, once the full layer_sizes list (and therefore d_in/N/L) is known. 1.0 (the default) reproduces plain, unscaled PC.
|
| float | GetMuPCScale () const noexcept |
| | Returns the current muPC forward-scaling factor – see SetMuPCScale().
|
| void | SetResidual (bool enabled) noexcept |
| | Set by the owning network at Compile() time. Requires size == nextSize (checked at the point it's actually used, not here, since nextSize may not be finalized yet when this is called). false (the default) reproduces plain PC.
|
| bool | GetResidual () const noexcept |
| | Returns whether the residual connection is enabled – see SetResidual().
|
| void | SetCrossEntropy (bool enabled) noexcept |
| | Enables softmax cross-entropy energy for THIS layer's error against layerBelow's mu (i.e. this only makes sense set on the terminal layer, against the second-to-last layer's logits – NOT looped over every layer the way SetMuPCScale/SetResidual/ SetMomentum's network-level setters are). OFF by default (plain Gaussian energy, matching DirectKPPCLayer exactly).
|
| bool | GetCrossEntropy () const noexcept |
| | Returns whether softmax cross-entropy energy is enabled – see SetCrossEntropy().
|
| float | CalculateState () noexcept override |
| | Matches Layer's virtual interface exactly (always computes real energy).
|
| float | CalculateState (bool needEnergy) noexcept |
| | NOT a virtual override – see SimplePCLayer's identical pattern. Lets the settling loop skip the energy reduction (and its capture-time sync) when the caller doesn't need the value.
|
| void | ComputeMuOnly () noexcept |
| | Computes only mu (forward prediction), skipping error/energy.
|
| void | UpdateState () noexcept override |
| | Updates the states after calculation.
|
| void | UpdateWeights () noexcept override |
| | Updates the weights after state updates.
|
| void | DirectFeedbackUpdate () noexcept |
| | Perturbs W using the layer above's Psi and the terminal layer's error – the DFA phase, run once per batch before settling begins.
|
| void | ClampState (const std::vector< float > &inputData) noexcept |
| | Clamps this layer's beliefs to inputData, fixing them against UpdateState() until UnclampState() is called.
|
| void | UnclampState () noexcept |
| | Releases a previous ClampState() call.
|
| void | ResetState () noexcept |
| | Resets this layer's beliefs (z) without touching learned weights.
|
| bool | IsClamped () const noexcept |
| | Whether ClampState() is currently active on this layer.
|
| void | InvalidateMuCache () noexcept |
| | Forces the next ComputeMuOnly() call to recompute mu from scratch, even if this layer is clamped. Needed under iPC: weights change every settling step, so a clamped layer's cached mu (valid under the standard, two-phase assumption that W is fixed throughout settling) goes stale the moment UpdateWeights() runs mid-loop.
|
| void | SetMomentum (bool enabled, float beta=0.9f) noexcept |
| | Enables momentum (inertial) settling: the update direction is EMA-smoothed (decay beta) before being applied to z, instead of applied directly each step. OFF by default. v is allocated unconditionally in BindMemory() regardless of this flag's value at that time (same reasoning as biasGradScratch – cheap, and avoids an ordering hazard if this is called after Compile()). Reset to zero at the start of every TrainStep()/Predict() call, same as z.
|
| bool | GetMomentum () const noexcept |
| | Returns whether momentum settling is enabled – see SetMomentum().
|
| float | GetMomentumBeta () const noexcept |
| | Returns the momentum EMA decay rate – see SetMomentum().
|
| void | SetOptimizer (OptimizerType o) noexcept |
| | Sets the optimizer for W. Call before Compile().
|
| void | SetPsiOptimizer (OptimizerType o) noexcept |
| | Sets the optimizer for Psi. Call before Compile().
|
| void | SetLearningRate (float learningRate) noexcept |
| | Sets the learning rate, propagating it to the optimizer state.
|
| void | SetInferenceRate (float inferenceRate) noexcept |
| | Sets the inference rate.
|
| void | SetFeedbackRate (float feedbackRate) noexcept |
| | Sets the feedback rate, propagating it to the optimizer state.
|
| void | SetLambda (float lmbda) noexcept |
| | Sets the weight decay coefficient.
|
| float * | GetBeliefs () noexcept override |
| | Should return belief state z.
|
| const float * | GetErrors () const noexcept override |
| | Should return errors e.
|
| const float * | GetMu () const noexcept |
| | Returns this layer's forward prediction buffer.
|
| const float * | GetWeights () const noexcept |
| | Returns the weight matrix W, shape [nextSize, size].
|
| const float * | GetDirectFeedbackWeights () const noexcept |
| | Returns the direct feedback (DFA) weight matrix Psi, shape [size, terminalSize].
|
| const float * | GetBiases () const noexcept |
| | Returns the bias vector, length nextSize.
|
| size_t | GetBatchSize () const noexcept override |
| | Should return batch size.
|
| size_t | GetInputSize () const noexcept override |
| | Should return input size.
|
| size_t | GetOutputSize () const noexcept override |
| | Should return output size.
|
| size_t | GetTerminalSize () const noexcept |
| | Returns the network's final output layer size, as given at construction.
|
| virtual | ~Layer ()=default |
| virtual void | Flush () noexcept |
| | Flushes remaining batches.
|
|
| size_t | size |
| | This layer's own belief (z) size.
|
| size_t | nextSize |
| | Size of the layer above (0 marks a terminal layer).
|
| size_t | terminalSize |
| | Size of the network's final output layer.
|
| size_t | batchSize |
| | Batch size.
|
| float | lr |
| | Learning rate for W.
|
| float | ir |
| | Inference rate (Euler integration step size).
|
| float | fl |
| | Feedback rate for Psi.
|
| float | lmbda |
| | Weight decay (L2 regularization) coefficient, shared between W and Psi.
|
| float | a = 1.0f |
| | muPC forward-scaling factor – see SetMuPCScale().
|
| bool | useResidual = false |
| | Whether the residual/skip connection is enabled – see SetResidual().
|
| bool | isClamped = false |
| | Whether ClampState() is currently active.
|
| bool | muCacheValid = false |
| | Whether cachedMu holds a valid, up-to-date value.
|
| FullPCLayer * | layerAbove = nullptr |
| | The next layer up, or nullptr if this is terminal.
|
| FullPCLayer * | layerBelow = nullptr |
| | The next layer down, or nullptr if this is the input layer.
|
| FullPCLayer * | terminalLayer = nullptr |
| | The network's terminal layer, for DirectFeedbackUpdate().
|
| ActivationType | activationType |
| | This layer's activation type.
|
| OptimizerType | opt = OptimizerType::SGD |
| | Optimizer for W/b.
|
| OptimizerType | optPsi = OptimizerType::SGD |
| | Optimizer for Psi.
|
| std::unique_ptr< IComputeBackend, BackendDeleter > | backend |
| | This layer's compute backend.
|
| float * | z = nullptr |
| | This layer's belief buffer, shape [batchSize, size].
|
| float * | e = nullptr |
| | This layer's error buffer, shape [batchSize, size].
|
| float * | W = nullptr |
| | Weight matrix, shape [nextSize, size].
|
| float * | b = nullptr |
| | Bias vector, length nextSize.
|
| float * | mu = nullptr |
| | Forward prediction buffer, shape [batchSize, nextSize].
|
| float * | cachedMu = nullptr |
| | Cached mu, valid when muCacheValid is true.
|
| float * | Psi = nullptr |
| | Direct feedback (DFA) weight matrix, shape [size, terminalSize].
|
| float * | proj = nullptr |
| | Scratch buffer: terminal error projected back through layerAbove's Psi, for DirectFeedbackUpdate()'s W update.
|
| float * | grad_W = nullptr |
| | W's gradient scratch buffer.
|
| float * | grad_b = nullptr |
| | b's gradient scratch buffer.
|
| float * | m_W = nullptr |
| | Adam/AdamW first-moment buffer for W.
|
| float * | v_W = nullptr |
| | Adam/AdamW second-moment buffer for W.
|
| float * | m_b = nullptr |
| | Adam/AdamW first-moment buffer for b.
|
| float * | v_b = nullptr |
| | Adam/AdamW second-moment buffer for b.
|
| float * | grad_Psi = nullptr |
| | Psi's gradient scratch buffer.
|
| float * | m_Psi = nullptr |
| | Adam/AdamW first-moment buffer for Psi.
|
| float * | v_Psi = nullptr |
| | Adam/AdamW second-moment buffer for Psi.
|
| int * | t_device = nullptr |
| | Device-resident Adam/AdamW step count for W/b, for graph-captured steps.
|
| float * | lr_device = nullptr |
| | Device-resident mirror of lr.
|
| int * | tPsi_device = nullptr |
| | Device-resident Adam/AdamW step count for Psi.
|
| float * | fl_device = nullptr |
| | Device-resident mirror of fl.
|
| float * | zF = nullptr |
| | Activated belief, phi(z), used as the forward GEMM's input.
|
| float * | zFDeriv = nullptr |
| | Activation derivative at z, for the feedback term.
|
| float * | feedbackScratch = nullptr |
| | Scratch buffer for the feedback GEMM's output.
|
| float * | v = nullptr |
| | Momentum buffer for the settling update – see SetMomentum().
|
| bool | useMomentum = false |
| | Whether momentum settling is enabled – see SetMomentum().
|
| float | momentumBeta = 0.9f |
| | Momentum EMA decay rate – see SetMomentum().
|
| bool | useCrossEntropy = false |
| | Whether softmax cross-entropy energy is enabled – see SetCrossEntropy().
|
| float * | rowEnergies = nullptr |
| | Per-row energy scratch for the cross-entropy path, length batchSize.
|
| float * | biasGradScratch = nullptr |
| | nextSize-length scratch for SumRows' output in UpdateWeights()'s SGD branch (accumulate, which SumRows alone can't express). Same reasoning as DirectKPPCLayer's identical buffer.
|
| std::unique_ptr< MemoryArena > | localArena |
| | This layer's own arena, used when it isn't bound into a network-wide one.
|
| size_t | size |
| | Size of input.
|
| size_t | nextSize |
| | Size of output.
|
PC layer combining muPC scaling, optional residual connections, and DKP direct feedback – every extra OFF by default, so plain defaults reproduce DirectKPPCLayer exactly. See the file-level note above for the full design rationale.