Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
Deep::GaussSeidelPCLayer Class Reference

PC layer with Gauss-Seidel (sequential-sweep) settling dynamics, in place of the usual simultaneous update. Not yet gradient-checked – see the file-level warning above. More...

#include <GaussSeidelPCLayer.h>

Inheritance diagram for Deep::GaussSeidelPCLayer:
Deep::Layer

Public Member Functions

 GaussSeidelPCLayer (int size, int nextSize, int 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)
 Constructor for a GaussSeidelPCLayer.
 GaussSeidelPCLayer (int size, int nextSize, int batchSize=1, float learningRate=1e-6f, float inferenceRate=0.1f, float lmbda=1e-2f, ActivationType aType=ActivationType::RELU, ActivationType dType=ActivationType::dRELU)
 Constructor using a named ActivationType instead of raw function pointers.
float CalculateState () noexcept override
 Step 1 of a Gauss-Seidel timestep: updates z using mu/e_above HELD OVER from the end of the previous timestep. Does NOT mutate mu – computes its derivative into a separate scratch buffer.
void UpdateState () noexcept override
 Step 1: the actual z-update. See class-level docs for the required three-sweep calling order.
void ComputePrediction () noexcept
 Step 2 of a Gauss-Seidel timestep: recomputes mu fresh, using the z JUST updated by UpdateState() in this same timestep. Call on EVERY layer before any layer's ComputeError().
float ComputeError () noexcept
 Step 3 of a Gauss-Seidel timestep: recomputes e fresh, using this layer's own (just-updated) z as the target and layerBelow's FRESH mu (from its ComputePrediction() call) as the prediction.
void UpdateWeights () noexcept override
 Computes weight updates via gradient descent, with L2 weight decay. Called once after the full settling loop completes, matching ngc-learn's evolve_process.
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.
void UnclampState () noexcept
 Releases a previous ClampState() call.
float * GetBeliefs () noexcept override
 Returns this layer's belief buffer.
const float * GetMu () const noexcept
 Returns this layer's outgoing prediction buffer.
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 a read-only version of the stored weights.
float * GetWeights () noexcept
 Returns a mutable version of the stored weights.
const float * GetBiases () const noexcept
 Returns a read-only version of the stored biases.
float * GetBiases () noexcept
 Returns a mutable version of the stored biases.
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.
void SetLayerAbove (GaussSeidelPCLayer *above) noexcept
 Sets the layer immediately above this one in the network.
void SetLayerBelow (GaussSeidelPCLayer *below) noexcept
 Sets the layer immediately below this one in the network.
void ResetState () noexcept
 Resets beliefs/errors/predictions back to their initial values, without touching learned weights.
const GaussSeidelPCLayer & GetLayerAbove () const noexcept
 Returns the layer immediately above this one.
const GaussSeidelPCLayer & GetLayerBelow () const noexcept
 Returns the layer immediately below this one.
void RandomizeWeights (std::mt19937 &twister) noexcept
 Randomizes this layer's weights (and the E feedback-alignment matrix) 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.
void BindMemory (MemoryArena &arena)
 Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any other operation.
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 GaussSeidelPCNDiagnostics

Additional Inherited Members

Protected Attributes inherited from Deep::Layer
size_t size
 Size of input.
size_t nextSize
 Size of output.

Detailed Description

PC layer with Gauss-Seidel (sequential-sweep) settling dynamics, in place of the usual simultaneous update. Not yet gradient-checked – see the file-level warning above.

Constructor & Destructor Documentation

◆ GaussSeidelPCLayer() [1/2]

Deep::GaussSeidelPCLayer::GaussSeidelPCLayer ( int size,
int nextSize,
int 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 )

Constructor for a GaussSeidelPCLayer.

Parameters
sizeSize of this layer's own belief (z)
nextSizeSize of the layer above's belief (this layer's outgoing prediction target); 0 marks a terminal layer
batchSizeBatch size
learningRateLearning rate for weight updates
inferenceRateInference rate (Euler integration step size)
lmbdaWeight decay (L2 regularization) coefficient
actActivation function
dActDerivative of activation function

◆ GaussSeidelPCLayer() [2/2]

Deep::GaussSeidelPCLayer::GaussSeidelPCLayer ( int size,
int nextSize,
int batchSize = 1,
float learningRate = 1e-6f,
float inferenceRate = 0.1f,
float lmbda = 1e-2f,
ActivationType aType = ActivationType::RELU,
ActivationType dType = ActivationType::dRELU )

Constructor using a named ActivationType instead of raw function pointers.

Parameters
sizeSize of this layer's own belief (z)
nextSizeSize of the layer above's belief (this layer's outgoing prediction target); 0 marks a terminal layer
batchSizeBatch size
learningRateLearning rate for weight updates
inferenceRateInference rate (Euler integration step size)
lmbdaWeight decay (L2 regularization) coefficient
aTypeActivation type
dTypeActivation derivative type

Member Function Documentation

◆ BindMemory()

void Deep::GaussSeidelPCLayer::BindMemory ( MemoryArena & arena)

Binds this layer's weight/state/scratch buffers into the supplied arena. Must be called before any other operation.

Parameters
arenaThe MemoryArena to bind into.

◆ CalculateState()

float Deep::GaussSeidelPCLayer::CalculateState ( )
inlineoverridevirtualnoexcept

Step 1 of a Gauss-Seidel timestep: updates z using mu/e_above HELD OVER from the end of the previous timestep. Does NOT mutate mu – computes its derivative into a separate scratch buffer.

Returns
Always 0.0f – energy is only meaningful from ComputeError(), kept for Layer interface conformance.

Implements Deep::Layer.

◆ ClampState()

void Deep::GaussSeidelPCLayer::ClampState ( const std::vector< float > & inputData)
noexcept

Clamps this layer's beliefs to externally-provided data.

Parameters
inputDataFlattened input data of length size.

◆ ComputeError()

float Deep::GaussSeidelPCLayer::ComputeError ( )
noexcept

Step 3 of a Gauss-Seidel timestep: recomputes e fresh, using this layer's own (just-updated) z as the target and layerBelow's FRESH mu (from its ComputePrediction() call) as the prediction.

Returns
This layer's energy contribution at the current state.

◆ ComputePrediction()

void Deep::GaussSeidelPCLayer::ComputePrediction ( )
noexcept

Step 2 of a Gauss-Seidel timestep: recomputes mu fresh, using the z JUST updated by UpdateState() in this same timestep. Call on EVERY layer before any layer's ComputeError().

◆ Flush()

void Deep::GaussSeidelPCLayer::Flush ( )
inlineoverridevirtualnoexcept

No-op; exists for Layer interface conformance.

Reimplemented from Deep::Layer.

◆ GetActivationType()

ActivationType Deep::GaussSeidelPCLayer::GetActivationType ( ) const
inlinenoexcept

Returns this layer's configured activation type.

Returns
ActivationType

◆ GetBatchSize()

size_t Deep::GaussSeidelPCLayer::GetBatchSize ( ) const
inlineoverridevirtualnoexcept

Returns the batch size this layer was constructed with.

Returns
size_t batchSize

Implements Deep::Layer.

◆ GetBeliefs()

float * Deep::GaussSeidelPCLayer::GetBeliefs ( )
inlineoverridevirtualnoexcept

Returns this layer's belief buffer.

Returns
Pointer to this layer's beliefs.

Implements Deep::Layer.

◆ GetBiases() [1/2]

const float * Deep::GaussSeidelPCLayer::GetBiases ( ) const
inlinenoexcept

Returns a read-only version of the stored biases.

Returns
const float *b

◆ GetBiases() [2/2]

float * Deep::GaussSeidelPCLayer::GetBiases ( )
inlinenoexcept

Returns a mutable version of the stored biases.

Returns
float *b

◆ GetDerivativeType()

ActivationType Deep::GaussSeidelPCLayer::GetDerivativeType ( ) const
inlinenoexcept

Returns this layer's configured activation-derivative type.

Returns
ActivationType

◆ GetErrors()

const float * Deep::GaussSeidelPCLayer::GetErrors ( ) const
inlineoverridevirtualnoexcept

Returns this layer's prediction-error buffer.

Returns
const float *e

Implements Deep::Layer.

◆ GetInferenceRate()

float Deep::GaussSeidelPCLayer::GetInferenceRate ( ) const
inlinenoexcept

Returns the inference rate (Euler integration step size).

Returns
float ir

◆ GetInputSize()

size_t Deep::GaussSeidelPCLayer::GetInputSize ( ) const
inlineoverridevirtualnoexcept

Returns this layer's own belief size.

Returns
size_t size

Implements Deep::Layer.

◆ GetLambda()

float Deep::GaussSeidelPCLayer::GetLambda ( ) const
inlinenoexcept

Returns the weight-decay (L2 regularization) coefficient.

Returns
float lmbda

◆ GetLayerAbove()

const GaussSeidelPCLayer & Deep::GaussSeidelPCLayer::GetLayerAbove ( ) const
inlinenoexcept

Returns the layer immediately above this one.

Warning
Dereferences layerAbove without a null check; only valid if SetLayerAbove() was previously called with a non-null pointer.

◆ GetLayerBelow()

const GaussSeidelPCLayer & Deep::GaussSeidelPCLayer::GetLayerBelow ( ) const
inlinenoexcept

Returns the layer immediately below this one.

Warning
Dereferences layerBelow without a null check; only valid if SetLayerBelow() was previously called with a non-null pointer.

◆ GetLearningRate()

float Deep::GaussSeidelPCLayer::GetLearningRate ( ) const
inlinenoexcept

Returns the learning rate used for weight updates.

Returns
float lr

◆ GetMu()

const float * Deep::GaussSeidelPCLayer::GetMu ( ) const
inlinenoexcept

Returns this layer's outgoing prediction buffer.

Returns
const float *mu

◆ GetOutputSize()

size_t Deep::GaussSeidelPCLayer::GetOutputSize ( ) const
inlineoverridevirtualnoexcept

Returns this layer's outgoing prediction size (0 for a terminal layer).

Returns
size_t nextSize

Implements Deep::Layer.

◆ GetRequiredFloats()

size_t Deep::GaussSeidelPCLayer::GetRequiredFloats ( ) const
noexcept

Computes the total number of floats this layer requires from a MemoryArena.

Returns
The required float count.

◆ GetWeights() [1/2]

const float * Deep::GaussSeidelPCLayer::GetWeights ( ) const
inlinenoexcept

Returns a read-only version of the stored weights.

Returns
const float *W

◆ GetWeights() [2/2]

float * Deep::GaussSeidelPCLayer::GetWeights ( )
inlinenoexcept

Returns a mutable version of the stored weights.

Returns
float *W

◆ RandomizeWeights()

void Deep::GaussSeidelPCLayer::RandomizeWeights ( std::mt19937 & twister)
noexcept

Randomizes this layer's weights (and the E feedback-alignment matrix) in place.

Parameters
twisterThe classic Mersenne Twister

◆ ResetState()

void Deep::GaussSeidelPCLayer::ResetState ( )
noexcept

Resets beliefs/errors/predictions back to their initial values, without touching learned weights.

◆ SetInferenceRate()

void Deep::GaussSeidelPCLayer::SetInferenceRate ( float ir)
inlinenoexcept

Sets the inference rate (Euler integration step size).

Parameters
irThe new inference rate.

◆ SetLambda()

void Deep::GaussSeidelPCLayer::SetLambda ( float l)
inlinenoexcept

Sets the weight-decay (L2 regularization) coefficient.

Parameters
lThe new lambda value.

◆ SetLayerAbove()

void Deep::GaussSeidelPCLayer::SetLayerAbove ( GaussSeidelPCLayer * above)
inlinenoexcept

Sets the layer immediately above this one in the network.

Parameters
abovePointer to the layer above; may be nullptr for a terminal layer.

◆ SetLayerBelow()

void Deep::GaussSeidelPCLayer::SetLayerBelow ( GaussSeidelPCLayer * below)
inlinenoexcept

Sets the layer immediately below this one in the network.

Parameters
belowPointer to the layer below; may be nullptr for the input layer.

◆ SetLearningRate()

void Deep::GaussSeidelPCLayer::SetLearningRate ( float lr)
inlinenoexcept

Sets the learning rate used for weight updates.

Parameters
lrThe new learning rate.

◆ SetOptimizer()

void Deep::GaussSeidelPCLayer::SetOptimizer ( const OptimizerType o)
inlinenoexcept

Selects the optimizer used for weight updates.

Parameters
oThe optimizer type to use.

◆ UnclampState()

void Deep::GaussSeidelPCLayer::UnclampState ( )
noexcept

Releases a previous ClampState() call.

◆ UpdateState()

void Deep::GaussSeidelPCLayer::UpdateState ( )
overridevirtualnoexcept

Step 1: the actual z-update. See class-level docs for the required three-sweep calling order.

Implements Deep::Layer.

◆ UpdateWeights()

void Deep::GaussSeidelPCLayer::UpdateWeights ( )
overridevirtualnoexcept

Computes weight updates via gradient descent, with L2 weight decay. Called once after the full settling loop completes, matching ngc-learn's evolve_process.

Implements Deep::Layer.

◆ GaussSeidelPCNDiagnostics

friend class GaussSeidelPCNDiagnostics
friend

The documentation for this class was generated from the following files: