![]() |
Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
|
Predictive Coding network combining muPC scaling, optional residual connections, and DKP direct feedback – see the file-level note above for how its defaults reproduce DirectKPPCNetwork exactly. More...
#include <FullPCNetwork.h>
Public Member Functions | |
| FullPCNetwork (int batchSize, DeviceType device=DeviceType::DEVICE_CPU) noexcept | |
| Constructs an empty network; add layers via AddLayer(), then Compile() before use. | |
| ~FullPCNetwork ()=default | |
| FullPCNetwork (const FullPCNetwork &)=delete | |
| FullPCNetwork & | operator= (const FullPCNetwork &)=delete |
| 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 | SetUseMuPCScaling (bool enabled) noexcept |
| Enables muPC-style per-layer forward scaling (Table 1 of the muPC paper). OFF by default. Must be called before Compile() – Compile() is what actually computes and applies each layer's a, once the full architecture (every AddLayer call) is known. | |
| void | SetUseResidualConnections (bool enabled) noexcept |
| Enables residual/skip connections on middle hidden layers (muPC's "1-skip" ResNet formulation – see that paper's A.2.4). OFF by default. Requires every middle hidden layer to have the SAME width as its neighbor; Compile() throws std::invalid_argument if that's violated, rather than silently skipping the mismatched connection (a silent skip risks masking a real configuration mistake). | |
| 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 hidden layers from a genuine forward pass through current weights, instead of zero-init. Call after Clamp(), before the settling loop. | |
| float | CalculateTerminalError () noexcept |
| Computes the terminal layer's error/energy against its clamped target. Call AFTER clamping the target onto the terminal layer, and BEFORE DirectFeedbackUpdate(). | |
| void | DirectFeedbackUpdate () noexcept |
| Runs the DFA phase on every non-terminal layer: perturbs each layer's W using the layer above's Psi and the terminal layer's error. | |
| float | Step (bool computeEnergy=true) noexcept |
| Runs one settling step on every layer. | |
| void | UpdateWeights () noexcept |
| Applies weight updates to every layer. | |
| void | SetOptimizer (OptimizerType o) noexcept |
| Sets the weight optimizer (W) on every layer. | |
| void | SetPsiOptimizer (OptimizerType o) noexcept |
| Sets the feedback-weight optimizer (Psi) on every layer. | |
| void | SetLearningRate (float lr) noexcept |
| Sets the learning rate (W) on every layer. | |
| void | SetFeedbackRate (float fl) noexcept |
| Sets the feedback rate (Psi) on every layer. | |
| FullPCLayer * | GetTerminalLayer () noexcept |
| Returns the last layer (nextSize==0, the terminal one). | |
| std::vector< std::unique_ptr< FullPCLayer > > & | GetLayers () noexcept |
| Returns every layer in the network, in the order they were added. | |
| const std::vector< std::unique_ptr< FullPCLayer > > & | GetLayers () const noexcept |
| const overload of GetLayers() above. | |
| int | GetBatchSize () const noexcept |
| Returns the batch size given at construction. | |
| 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, wires layerAbove/layerBelow/terminalLayer across every layer – same as DirectKPPCNetwork::Compile() – PLUS: if useMuPCScaling, computes and applies each layer's a (Table 1) from the full, now-known architecture; if useResidualConnections, applies SetResidual(true) to every middle hidden layer after checking width match (throws std::invalid_argument on mismatch). | |
| void | SetUseIPC (bool enabled) noexcept |
| Enables iPC: UpdateWeights() runs every settling step instead of once after settling completes. OFF by default – TrainStep() matches DirectKPPCNetwork's standard, two-phase behavior exactly when this is false. | |
| void | SetUseMomentum (bool enabled, float beta=0.9f) noexcept |
| Enables momentum (inertial) settling on every layer. Loops over layers and calls each one's own SetMomentum() – same pattern as SetLearningRate/SetFeedbackRate. OFF by default. | |
| void | SetUseCrossEntropy (bool enabled) noexcept |
| Enables softmax cross-entropy energy on the TERMINAL layer only (unlike the other Set* toggles, this does NOT loop over every layer – cross-entropy only ever makes sense on the final output, against a one-hot/class-probability target). OFF by default (plain Gaussian energy everywhere, matching DirectKPPCNetwork). | |
Predictive Coding network combining muPC scaling, optional residual connections, and DKP direct feedback – see the file-level note above for how its defaults reproduce DirectKPPCNetwork exactly.
|
explicitnoexcept |
Constructs an empty network; add layers via AddLayer(), then Compile() before use.
| batchSize | Fixed batch size for every layer. |
| device | Which device this network's layers run on. |
|
default |
|
delete |
| void Deep::FullPCNetwork::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 FullPCLayer's own docs) |
| lmbda | weight decay (L2 regularization) coefficient, shared between W and Psi |
| aType | activation type |
| dType | activation derivative type |
|
noexcept |
Computes the terminal layer's error/energy against its clamped target. Call AFTER clamping the target onto the terminal layer, and BEFORE DirectFeedbackUpdate().
| void Deep::FullPCNetwork::Clamp | ( | const std::vector< float > & | input | ) |
Clamps the input to the first layer.
| input | Reference to the input vector. |
| void Deep::FullPCNetwork::Compile | ( | ) |
Loads all layers into one contiguous block of memory, wires layerAbove/layerBelow/terminalLayer across every layer – same as DirectKPPCNetwork::Compile() – PLUS: if useMuPCScaling, computes and applies each layer's a (Table 1) from the full, now-known architecture; if useResidualConnections, applies SetResidual(true) to every middle hidden layer after checking width match (throws std::invalid_argument on mismatch).
|
noexcept |
Runs the DFA phase on every non-terminal layer: perturbs each layer's W using the layer above's Psi and the terminal layer's error.
|
inlinenoexcept |
Returns the batch size given at construction.
|
inlinenoexcept |
Returns which device this network's layers run on.
|
inlinenoexcept |
const overload of GetLayers() above.
|
inlinenoexcept |
Returns every layer in the network, in the order they were added.
|
inlinenoexcept |
Returns the last layer (nextSize==0, the terminal one).
|
delete |
| std::vector< float > Deep::FullPCNetwork::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 hidden layers from a genuine forward pass through current weights, instead of zero-init. Call after Clamp(), before the settling loop.
| void Deep::FullPCNetwork::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 feedback rate (Psi) on every layer.
|
inlinenoexcept |
Sets the learning rate (W) on every layer.
|
inlinenoexcept |
Sets the weight optimizer (W) on every layer.
|
inlinenoexcept |
Sets the feedback-weight optimizer (Psi) on every layer.
|
inlinenoexcept |
Enables softmax cross-entropy energy on the TERMINAL layer only (unlike the other Set* toggles, this does NOT loop over every layer – cross-entropy only ever makes sense on the final output, against a one-hot/class-probability target). OFF by default (plain Gaussian energy everywhere, matching DirectKPPCNetwork).
|
inlinenoexcept |
Enables iPC: UpdateWeights() runs every settling step instead of once after settling completes. OFF by default – TrainStep() matches DirectKPPCNetwork's standard, two-phase behavior exactly when this is false.
|
inlinenoexcept |
Enables momentum (inertial) settling on every layer. Loops over layers and calls each one's own SetMomentum() – same pattern as SetLearningRate/SetFeedbackRate. OFF by default.
|
inlinenoexcept |
|
inlinenoexcept |
Enables residual/skip connections on middle hidden layers (muPC's "1-skip" ResNet formulation – see that paper's A.2.4). OFF by default. Requires every middle hidden layer to have the SAME width as its neighbor; Compile() throws std::invalid_argument if that's violated, rather than silently skipping the mismatched connection (a silent skip risks masking a real configuration mistake).
|
noexcept |
Runs one settling step on every layer.
| computeEnergy | asks for energy to be returned |
| float Deep::FullPCNetwork::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. |
|
noexcept |
Applies weight updates to every layer.