![]() |
Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
|
Predictive Coding network built from DirectKPPCLayer, using Direct Kolen-Pollack feedback alignment (DFA) instead of symmetric weight transport. See the file-level warning above on its current verification status. More...
#include <DirectKPPCNetwork.h>
Public Member Functions | |
| DirectKPPCNetwork (int batchSize, DeviceType device=DeviceType::DEVICE_CPU) noexcept | |
| Constructs an empty network with a predetermined batch size. | |
| ~DirectKPPCNetwork ()=default | |
| Default destructor. | |
| DirectKPPCNetwork (const DirectKPPCNetwork &)=delete | |
| Copy construction is disabled; a network owns its layers' memory arena and is not meant to be duplicated. | |
| DirectKPPCNetwork & | operator= (const DirectKPPCNetwork &)=delete |
| Copy assignment is disabled; see the copy constructor. | |
| void | AddLayer (size_t size, size_t nextSize, size_t terminalSize, float lr, float ir, float fl, float lmbda, ActivationType aType, ActivationType dType) |
| Adds a layer to the network. | |
| void | RandomizeWeights (std::mt19937 &rng) |
| Randomizes the weights (W and Psi) of each layer. | |
| void | ResetState () noexcept |
| Resets each layer's state without touching learned weights. | |
| void | Clamp (const std::vector< float > &input) |
| Clamps the input to the first layer. | |
| void | ProjectForward () noexcept |
| Seeds every hidden layer's z from a genuine forward pass through current weights. Assumes layers[0] is already clamped. | |
| float | CalculateTerminalError () noexcept |
| Phase 0's final step: computes the terminal layer's error alone, producing a real, non-zero epsilon_L. Call AFTER clamping the target onto the terminal layer, and BEFORE DirectFeedbackUpdate(). | |
| void | DirectFeedbackUpdate () noexcept |
| Phase 1: runs DirectFeedbackUpdate() on every non-terminal layer. Order among layers does not matter (see class-level docs) – unlike GaussSeidelPCNetwork, no sweep ordering is required here. Still sequential in this revision; see class-level warning. | |
| float | Step (bool computeEnergy=true) noexcept |
| Phase 2: runs one ordinary PC settling step (CalculateState() + UpdateState()) across every layer. | |
| void | UpdateWeights () noexcept |
| Phase 3: updates every non-terminal layer's W and Psi. Called once after the settling loop completes. | |
| void | SetOptimizer (OptimizerType o) noexcept |
| Sets the optimizer used for W updates, on every layer. | |
| void | SetPsiOptimizer (OptimizerType o) noexcept |
| Sets the optimizer used for Psi updates, on every layer. | |
| void | SetLearningRate (float lr) noexcept |
| Sets the learning rate used for W updates, on every layer. | |
| void | SetFeedbackRate (float fl) noexcept |
| Sets the learning rate used for Psi updates, on every layer. | |
| DirectKPPCLayer * | GetTerminalLayer () noexcept |
| Returns the network's terminal (final) layer. | |
| std::vector< std::unique_ptr< DirectKPPCLayer > > & | GetLayers () noexcept |
| Returns every layer in the network, in the order they were added. | |
| const std::vector< std::unique_ptr< DirectKPPCLayer > > & | GetLayers () const noexcept |
| Returns every layer in the network, in the order they were added. | |
| int | GetBatchSize () const noexcept |
| Returns the batch size for the network's layers. | |
| DeviceType | GetDevice () const noexcept |
| Returns which device this network's layers run on. | |
| float | TrainStep (const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps=1) |
| Full train step: reset, clamp input+target, run all four DKP-PC phases in order, unclamp. | |
| std::vector< float > | Predict (const std::vector< float > &x, int inferenceSteps) |
| Forward prediction: clamp input, settle with no DFA perturbation and no target clamped, read the terminal's beliefs. | |
| void | Compile () |
| Loads all layers into one contiguous block of memory (MemoryArena for DEVICE_CPU, DeviceMemoryArena for DEVICE_GPU), and wires layerAbove/layerBelow/terminalLayer across every layer. | |
Predictive Coding network built from DirectKPPCLayer, using Direct Kolen-Pollack feedback alignment (DFA) instead of symmetric weight transport. See the file-level warning above on its current verification status.
|
explicitnoexcept |
Constructs an empty network with a predetermined batch size.
| batchSize | Batch size |
| device | Which device this network's layers should run on. Defaults to DEVICE_CPU, preserving existing behavior exactly for anyone not explicitly requesting DEVICE_GPU. |
|
default |
Default destructor.
|
delete |
Copy construction is disabled; a network owns its layers' memory arena and is not meant to be duplicated.
| void Deep::DirectKPPCNetwork::AddLayer | ( | size_t | size, |
| size_t | nextSize, | ||
| size_t | terminalSize, | ||
| float | lr, | ||
| float | ir, | ||
| float | fl, | ||
| float | lmbda, | ||
| ActivationType | aType, | ||
| ActivationType | dType ) |
Adds a layer to the network.
| size | input size |
| nextSize | output size (0 marks a terminal layer) |
| terminalSize | the size of the network's final output layer (e.g. 10 for MNIST) – required on every AddLayer call, not inferred, since the true terminal layer isn't known until the whole network has been assembled. Compile() sanity-checks this against the actual last layer's size. |
| lr | learning rate for W |
| ir | inference rate (Euler integration step size) |
| fl | feedback rate (see Layer implementatio) |
| lmbda | weight decay (L2 regularization) coefficient, shared between W and Psi |
| aType | activation type |
| dType | activation derivative type |
|
noexcept |
Phase 0's final step: computes the terminal layer's error alone, producing a real, non-zero epsilon_L. Call AFTER clamping the target onto the terminal layer, and BEFORE DirectFeedbackUpdate().
| void Deep::DirectKPPCNetwork::Clamp | ( | const std::vector< float > & | input | ) |
Clamps the input to the first layer.
| input | Reference to the input vector. |
| void Deep::DirectKPPCNetwork::Compile | ( | ) |
Loads all layers into one contiguous block of memory (MemoryArena for DEVICE_CPU, DeviceMemoryArena for DEVICE_GPU), and wires layerAbove/layerBelow/terminalLayer across every layer.
|
noexcept |
Phase 1: runs DirectFeedbackUpdate() on every non-terminal layer. Order among layers does not matter (see class-level docs) – unlike GaussSeidelPCNetwork, no sweep ordering is required here. Still sequential in this revision; see class-level warning.
|
inlinenoexcept |
Returns the batch size for the network's layers.
|
inlinenoexcept |
Returns which device this network's layers run on.
|
inlinenoexcept |
Returns every layer in the network, in the order they were added.
|
inlinenoexcept |
Returns every layer in the network, in the order they were added.
|
inlinenoexcept |
Returns the network's terminal (final) layer.
|
delete |
Copy assignment is disabled; see the copy constructor.
| std::vector< float > Deep::DirectKPPCNetwork::Predict | ( | const std::vector< float > & | x, |
| int | inferenceSteps ) |
Forward prediction: clamp input, settle with no DFA perturbation and no target clamped, read the terminal's beliefs.
|
noexcept |
Seeds every hidden layer's z from a genuine forward pass through current weights. Assumes layers[0] is already clamped.
| void Deep::DirectKPPCNetwork::RandomizeWeights | ( | std::mt19937 & | rng | ) |
Randomizes the weights (W and Psi) of each layer.
| rng | The classic Mersenne Twister |
|
noexcept |
Resets each layer's state without touching learned weights.
|
inlinenoexcept |
Sets the learning rate used for Psi updates, on every layer.
|
inlinenoexcept |
Sets the learning rate used for W updates, on every layer.
|
inlinenoexcept |
Sets the optimizer used for W updates, on every layer.
|
inlinenoexcept |
Sets the optimizer used for Psi updates, on every layer.
|
noexcept |
Phase 2: runs one ordinary PC settling step (CalculateState() + UpdateState()) across every layer.
| computeEnergy | asks for energy to be returned |
| float Deep::DirectKPPCNetwork::TrainStep | ( | const std::vector< float > & | x, |
| const std::vector< float > & | y, | ||
| int | inferenceSteps = 1 ) |
Full train step: reset, clamp input+target, run all four DKP-PC phases in order, unclamp.
| x | Flattened input batch, clamped to the input layer. |
| y | Flattened target batch, clamped to the terminal layer. |
| inferenceSteps | Number of settling steps for phase 2. Defaults to 1, matching the paper's own headline result – unlike this codebase's other PC variants, DKP-PC's entire point is that a single step is enough BECAUSE of the DFA phase, so defaulting to a larger value here would silently waste most of the intended speed advantage. |
|
noexcept |
Phase 3: updates every non-terminal layer's W and Psi. Called once after the settling loop completes.