![]() |
Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
|
Predictive Coding layer without precision weighting – the simpler, unweighted-energy counterpart to DiscriminativePCLayer. More...
#include <SimplePCLayer.h>
Public Member Functions | |
| SimplePCLayer (size_t size, size_t nextSize, size_t 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, IComputeBackend *backend=nullptr) | |
| Constructor for a SimplePCLayer. | |
| SimplePCLayer (size_t size, size_t nextSize, size_t batchSize=1, float learningRate=1e-6f, float inferenceRate=0.1f, float lmbda=1e-2f, ActivationType aType=ActivationType::RELU, ActivationType dType=ActivationType::dRELU, IComputeBackend *backend=nullptr) | |
| Constructor for a SimplePCLayer, using a named ActivationType instead of raw function pointers. | |
| float | CalculateState (bool needEnergy=true) noexcept |
| Calculates the total network energy state, and this layer's outgoing prediction (mu). | |
| float | CalculateState () noexcept override |
| Calculates the internal state of the layer. | |
| void | UpdateState () noexcept override |
| Computes the state derivatives for inference. | |
| void | UpdateWeights () noexcept override |
| Computes weight updates via gradient descent, with L2 weight decay. | |
| void | Flush () noexcept override |
| No-op; exists for Layer interface conformance. | |
| void | ClampState (const std::vector< float > &inputData) noexcept |
| Clamps this layer's beliefs to externally-provided data, preventing them from being updated by UpdateState(). | |
| void | UnclampState () noexcept |
| Releases a previous ClampState() call, allowing this layer's beliefs to update normally again. | |
| bool | IsClamped () const noexcept |
| Whether ClampState() is currently active on this layer. | |
| float * | GetBeliefs () noexcept override |
| Returns this layer's belief buffer. | |
| const float * | GetMu () const noexcept |
| Returns a prediction buffer exposed specifically for forward-projection initialization (seeding the next layer's z from a genuine, current-weights forward pass, rather than zero-init). nullptr for a terminal layer (nextSize=0). | |
| const float * | GetErrors () const noexcept override |
| Returns this layer's prediction-error buffer. | |
| size_t | GetInputSize () const noexcept override |
| Returns this layer's own belief size. | |
| size_t | GetOutputSize () const noexcept override |
| Returns this layer's outgoing prediction size (0 for a terminal layer). | |
| size_t | GetBatchSize () const noexcept override |
| Returns the batch size this layer was constructed with. | |
| const float * | GetWeights () const noexcept |
| Returns this layer's weight buffer. | |
| float * | GetWeights () noexcept |
| Returns this layer's weight buffer. | |
| const float * | GetBiases () const noexcept |
| Returns this layer's bias buffer. | |
| float * | GetBiases () noexcept |
| Returns this layer's bias buffer. | |
| float | GetLearningRate () const noexcept |
| Returns the learning rate used for weight updates. | |
| float | GetInferenceRate () const noexcept |
| Returns the inference rate (Euler integration step size). | |
| float | GetLambda () const noexcept |
| Returns the weight-decay (L2 regularization) coefficient. | |
| void | SetLearningRate (float lr) noexcept |
| Sets the learning rate used for weight updates. | |
| void | SetInferenceRate (float ir) noexcept |
| Sets the inference rate (Euler integration step size). | |
| void | SetLambda (float l) noexcept |
| Sets the weight-decay (L2 regularization) coefficient. | |
| void | SetOptimizer (const OptimizerType o) noexcept |
| Selects the optimizer used for weight updates (SGD or Adam). Adam's moment buffers are lazily allocated on first use. | |
| void | SetMuCacheThreshold (float threshold) noexcept |
| Sets the mu-cache staleness threshold: mu is recomputed only when ||z - z_at_last_recompute|| / (||z_at_last_recompute||. | |
| float | GetMuCacheThreshold () const noexcept |
| Returns the current mu-cache staleness threshold – see SetMuCacheThreshold() above. | |
| void | ComputeMuOnly () noexcept |
| Computes only mu (forward prediction), skipping error/energy entirely. Extracted from CalculateState() for callers (like ProjectForward()) that don't need the discarded error/energy values. Computes zF=phi(z) internally and uses it for the GEMM, matching the activate-before-transform convention (mu=W@phi(z)+b). | |
| void | SetLayerAbove (SimplePCLayer *above) noexcept |
| Sets the layer immediately above this one in the network. | |
| void | SetLayerBelow (SimplePCLayer *below) noexcept |
| Sets the layer immediately below this one in the network. | |
| void | ResetState () noexcept |
| Resets this layer's beliefs/errors back to their initial values, without touching learned weights. | |
| const SimplePCLayer & | GetLayerAbove () const noexcept |
| Returns the layer immediately above this one. | |
| const SimplePCLayer & | GetLayerBelow () const noexcept |
| Returns the layer immediately below this one. | |
| void | RandomizeWeights (std::mt19937 &twister, const char *distribution="normal") noexcept |
| Randomizes this layer's weights (and biases) in place. | |
| ActivationType | GetActivationType () const noexcept |
| Returns this layer's configured activation type. | |
| ActivationType | GetDerivativeType () const noexcept |
| Returns this layer's configured activation-derivative type. | |
| size_t | GetRequiredFloats () const noexcept |
| Computes the total number of floats this layer requires from a MemoryArena (weights, biases, beliefs, errors, scratch buffers, and, if Adam is selected, its moment buffers). | |
| template<typename ArenaT> | |
| void | BindMemory (ArenaT &arena) |
| Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any other operation. Templated so either MemoryArena (CPU) or DeviceMemoryArena (GPU) can be bound, resolved entirely at compile time – see the .cpp's explicit instantiations for the two concrete types actually used. | |
| Public Member Functions inherited from Deep::Layer | |
| virtual | ~Layer ()=default |
| virtual std::map< std::string, TensorDescriptor > | GetStateDict () const |
| Returns a dictionary of this. | |
Friends | |
| class | SimplePCNDiagnostics |
Additional Inherited Members | |
| Protected Attributes inherited from Deep::Layer | |
| size_t | size |
| Size of input. | |
| size_t | nextSize |
| Size of output. | |
Predictive Coding layer without precision weighting – the simpler, unweighted-energy counterpart to DiscriminativePCLayer.
| Deep::SimplePCLayer::SimplePCLayer | ( | size_t | size, |
| size_t | nextSize, | ||
| size_t | 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, | ||
| IComputeBackend * | backend = nullptr ) |
Constructor for a SimplePCLayer.
| size | Size of this layer's own belief (z) |
| nextSize | Size of the layer above's belief (this layer's outgoing prediction target); 0 marks a terminal layer |
| batchSize | Batch size |
| learningRate | Learning rate for weight updates |
| inferenceRate | Inference rate (Euler integration step size) |
| lmbda | Weight decay (L2 regularization) coefficient |
| act | Activation function |
| dAct | Derivative of activation function |
| backend | Compute backend to route all math through. Defaults to nullptr, in which case this layer constructs and owns its own CPUBackend internally – existing callers don't need to change anything. Pass a real backend (owned elsewhere, e.g. by the network) to run this layer on GPU. |
| Deep::SimplePCLayer::SimplePCLayer | ( | size_t | size, |
| size_t | nextSize, | ||
| size_t | batchSize = 1, | ||
| float | learningRate = 1e-6f, | ||
| float | inferenceRate = 0.1f, | ||
| float | lmbda = 1e-2f, | ||
| ActivationType | aType = ActivationType::RELU, | ||
| ActivationType | dType = ActivationType::dRELU, | ||
| IComputeBackend * | backend = nullptr ) |
Constructor for a SimplePCLayer, using a named ActivationType instead of raw function pointers.
| size | Size of this layer's own belief (z) |
| nextSize | Size of the layer above's belief (this layer's outgoing prediction target); 0 marks a terminal layer |
| batchSize | Batch size |
| learningRate | Learning rate for weight updates |
| inferenceRate | Inference rate (Euler integration step size) |
| lmbda | Weight decay (L2 regularization) coefficient |
| aType | Activation type |
| dType | Activation derivative type |
| backend | Compute backend to route all math through. See the other constructor's doc for the default-nullptr behavior. |
| template void Deep::SimplePCLayer::BindMemory< DeviceMemoryArena > | ( | ArenaT & | arena | ) |
Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any other operation. Templated so either MemoryArena (CPU) or DeviceMemoryArena (GPU) can be bound, resolved entirely at compile time – see the .cpp's explicit instantiations for the two concrete types actually used.
| arena | The arena to bind into. |
|
inlineoverridevirtualnoexcept |
|
noexcept |
Calculates the total network energy state, and this layer's outgoing prediction (mu).
\[E = \sum_l 1/2 ||z^{(l)} - \mu^{(l)}||^2 \]
mu is now computed as mu = W @ phi(z) + b – activation applied to z BEFORE the linear transform, matching ngc-learn's documented convention exactly (was previously mu = phi(W@z+b), activation AFTER the transform). (No precision weighting – see file-level note.)
| needEnergy | Asks for energy |
|
noexcept |
Clamps this layer's beliefs to externally-provided data, preventing them from being updated by UpdateState().
| inputData | Flattened input data of length size. |
|
noexcept |
Computes only mu (forward prediction), skipping error/energy entirely. Extracted from CalculateState() for callers (like ProjectForward()) that don't need the discarded error/energy values. Computes zF=phi(z) internally and uses it for the GEMM, matching the activate-before-transform convention (mu=W@phi(z)+b).
|
inlineoverridevirtualnoexcept |
No-op; exists for Layer interface conformance.
Reimplemented from Deep::Layer.
|
inlinenoexcept |
Returns this layer's configured activation type.
|
inlineoverridevirtualnoexcept |
Returns the batch size this layer was constructed with.
Implements Deep::Layer.
|
inlineoverridevirtualnoexcept |
Returns this layer's belief buffer.
Implements Deep::Layer.
|
inlinenoexcept |
Returns this layer's bias buffer.
|
inlinenoexcept |
Returns this layer's bias buffer.
|
inlinenoexcept |
Returns this layer's configured activation-derivative type.
|
inlineoverridevirtualnoexcept |
Returns this layer's prediction-error buffer.
Implements Deep::Layer.
|
inlinenoexcept |
Returns the inference rate (Euler integration step size).
|
inlineoverridevirtualnoexcept |
Returns this layer's own belief size.
Implements Deep::Layer.
|
inlinenoexcept |
Returns the weight-decay (L2 regularization) coefficient.
|
inlinenoexcept |
Returns the layer immediately above this one.
|
inlinenoexcept |
Returns the layer immediately below this one.
|
inlinenoexcept |
Returns the learning rate used for weight updates.
|
inlinenoexcept |
Returns a prediction buffer exposed specifically for forward-projection initialization (seeding the next layer's z from a genuine, current-weights forward pass, rather than zero-init). nullptr for a terminal layer (nextSize=0).
|
inlinenoexcept |
Returns the current mu-cache staleness threshold – see SetMuCacheThreshold() above.
|
inlineoverridevirtualnoexcept |
Returns this layer's outgoing prediction size (0 for a terminal layer).
Implements Deep::Layer.
|
noexcept |
Computes the total number of floats this layer requires from a MemoryArena (weights, biases, beliefs, errors, scratch buffers, and, if Adam is selected, its moment buffers).
|
inlinenoexcept |
Returns this layer's weight buffer.
|
inlinenoexcept |
Returns this layer's weight buffer.
|
inlinenoexcept |
Whether ClampState() is currently active on this layer.
|
noexcept |
Randomizes this layer's weights (and biases) in place.
| twister | The classic Mersenne Twister |
| distribution | The distribution of the randomization: (normal, uniform) |
|
noexcept |
Resets this layer's beliefs/errors back to their initial values, without touching learned weights.
|
inlinenoexcept |
Sets the inference rate (Euler integration step size).
| ir | The new inference rate. |
|
inlinenoexcept |
Sets the weight-decay (L2 regularization) coefficient.
| l | The new lambda value. |
|
inlinenoexcept |
Sets the layer immediately above this one in the network.
| above | Pointer to the layer above; may be nullptr for a terminal layer. |
|
inlinenoexcept |
Sets the layer immediately below this one in the network.
| below | Pointer to the layer below; may be nullptr for the input layer. |
|
noexcept |
Sets the learning rate used for weight updates.
| lr | The new learning rate. |
|
inlinenoexcept |
Sets the mu-cache staleness threshold: mu is recomputed only when ||z - z_at_last_recompute|| / (||z_at_last_recompute||.
|
inlinenoexcept |
Selects the optimizer used for weight updates (SGD or Adam). Adam's moment buffers are lazily allocated on first use.
| o | The optimizer type to use. |
|
noexcept |
Releases a previous ClampState() call, allowing this layer's beliefs to update normally again.
|
overridevirtualnoexcept |
Computes the state derivatives for inference.
\[\frac{dz^{(l)}}{dt} = -e^{(l)} + \sigma'(z^{(l)}) \odot (W^{(l-1)})^T e^{(l-1)} \]
The derivative multiply now applies AFTER the W transform, using f'(z) (this layer's OWN state derivative), not f'(mu) applied before – matching the activate-before-transform convention.
Implements Deep::Layer.
|
overridevirtualnoexcept |
Computes weight updates via gradient descent, with L2 weight decay.
Implements Deep::Layer.
|
friend |