Predictive Coding layer using Direct Kolen-Pollack feedback alignment (DFA): a per-layer feedback matrix Psi, trained to gradually correlate with W's transpose chain, replaces symmetric weight transport for the feedback term. See DirectKPPCNetwork.h's class docs and the paper's Appendix A.1.
More...
|
| | DirectKPPCLayer (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) |
| | ~DirectKPPCLayer () 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 (DirectKPPCLayer *l) noexcept |
| | Sets the layer immediately above this one in the network.
|
| void | SetLayerBelow (DirectKPPCLayer *l) noexcept |
| | Sets the layer immediately below this one in the network.
|
| void | SetTerminalLayer (DirectKPPCLayer *l) noexcept |
| | Sets the network's terminal layer, for DirectFeedbackUpdate().
|
| 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 cublasSdot-based 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 this layer is currently clamped – needed so DirectKPPCNetwork::ProjectForward() can skip overwriting an already-clamped layer's z with a forward-projected guess. Same real bug SimplePCNetwork::ProjectForward() had; fixed here for the same reason, before it gets exercised for the first time by moving ProjectForward() inside graph capture.
|
| 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.
|
| bool | isClamped = false |
| | Whether ClampState() is currently active.
|
| bool | muCacheValid = false |
| | Whether cachedMu holds a valid, up-to-date value.
|
| DirectKPPCLayer * | layerAbove = nullptr |
| | The next layer up, or nullptr if this is terminal.
|
| DirectKPPCLayer * | layerBelow = nullptr |
| | The next layer down, or nullptr if this is the input layer.
|
| DirectKPPCLayer * | terminalLayer = nullptr |
| | The network's terminal layer, for DirectFeedbackUpdate().
|
| ActivationType | activationType |
| | This layer's activation type.
|
| ActivationFn | activation |
| | Resolved function pointer for activationType.
|
| DerivativeFn | activationDerivative |
| | Resolved function pointer for the derivative.
|
| DerivativeFn2 | activationDerivativeInto |
| | Two-buffer variant of activationDerivative.
|
| OptimizerType | opt = OptimizerType::SGD |
| | Optimizer for W/b.
|
| OptimizerType | optPsi = OptimizerType::SGD |
| | Optimizer for Psi.
|
| int | t = 0 |
| | Adam/AdamW step count for W/b.
|
| int | tPsi = 0 |
| | Adam/AdamW step count 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 mirror of t, for graph-captured Adam steps.
|
| float * | lr_device = nullptr |
| | Device-resident mirror of lr.
|
| int * | tPsi_device = nullptr |
| | Device-resident mirror of tPsi.
|
| 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 * | biasGradScratch = nullptr |
| | nextSize-length scratch buffer for SumRows' output in UpdateWeights()'s SGD branch – SGD needs b += lr_batch *
sum(local_grad), an accumulate, which SumRows alone can't express (it only overwrites). Allocated unconditionally (regardless of which optimizer is selected) since it's cheap – at most nextSize floats – and simpler than branching allocation on optimizer choice for this one small 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.
|
Predictive Coding layer using Direct Kolen-Pollack feedback alignment (DFA): a per-layer feedback matrix Psi, trained to gradually correlate with W's transpose chain, replaces symmetric weight transport for the feedback term. See DirectKPPCNetwork.h's class docs and the paper's Appendix A.1.