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

An abstracted class for an array of DiscriminativePCLayer. More...

#include <DiscriminativePCNetwork.h>

Public Member Functions

 DiscriminativePCNetwork ()
 Default constructor.
 DiscriminativePCNetwork (int batchSize)
 Batched constructor.
 ~DiscriminativePCNetwork ()=default
 Default constructor; deletes each layer.
 DiscriminativePCNetwork (DiscriminativePCNetwork &&other) noexcept=default
 Move constructor.
DiscriminativePCNetwork & operator= (DiscriminativePCNetwork &&other) noexcept=default
 Move assignment operator.
void AddLayer (int size, int nextSize, float lr, float ir, float pr, float lmbda, void(*act)(float *, size_t), void(*dAct)(float *, size_t, bool))
 Adds a layer to the network.
void AddLayer (int size, int nextSize, float lr, float ir, float pr, float lmbda, Deep::ActivationType aType, Deep::ActivationType dType)
 Adds a layer to the network, using a named ActivationType instead of raw function pointers.
void RandomizeWeights (std::mt19937 &rng)
 Randomizes the weights of each layer.
void Clamp (const std::vector< float > &input)
 Clamps the input to the first layer, necessary for prediction.
float CalculateState ()
 Calculates the state of each layer.
void UpdateState ()
 Updates each layer's state.
void UpdateWeights ()
 Updates each layer's weights.
void UpdatePrecision ()
 Updates each layer's precision weighting.
void ProjectForward () noexcept
 Seeds every hidden layer's belief from a genuine forward pass through current weights, rather than zero-init. Assumes the input layer is already clamped.
float TrainStepWithProjection (const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps)
 Same as TrainStep(), but with ProjectForward() called once after clamping the input, before the settling loop.
std::vector< float > PredictWithProjection (const std::vector< float > &x, int inferenceSteps)
 Same as Predict(), but with ProjectForward() called once after clamping the input, before the settling loop.
void ResetState () noexcept
 Resets each layer's state without touching learned weights.
const auto & 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.
DiscriminativePCLayer * GetTerminalLayer () const
 Returns the network's terminal (final) layer.
void SetLearningRate (float lr)
 Sets the learning rate used for weight updates, on every layer.
void SetInferenceRate (float ir)
 Sets the inference rate used for state updates, on every layer.
void SetPrecisionRate (float pr)
 Sets the learning rate used for precision updates, on every layer.
void SetLambda (float l)
 Sets the weight-decay (L2 regularization) coefficient, on every layer.
void SetOptimizer (OptimizerType opt) noexcept
 Sets the optimizer used for weight updates, on every layer.
float TrainStep (const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps)
 Runs a complete training step (clamp, settle, update, unclamp).
std::vector< float > Predict (const std::vector< float > &x, int inferenceSteps)
 Runs a forward prediction pass (clamp, settle, read).
bool Save (const std::string &filename) const noexcept
 Saves the network's learned parameters to disk.
bool Load (const std::string &filename) noexcept
 Loads the network's learned parameters from disk.
void Compile ()
 Loads all layers into one contiguous block of memory.

Friends

class PCNDiagnostics

Detailed Description

An abstracted class for an array of DiscriminativePCLayer.

See also
https://arxiv.org/pdf/2506.06332

Constructor & Destructor Documentation

◆ DiscriminativePCNetwork() [1/3]

Deep::DiscriminativePCNetwork::DiscriminativePCNetwork ( )
inline

Default constructor.

Initializes the network with auto-batch size detection.

◆ DiscriminativePCNetwork() [2/3]

Deep::DiscriminativePCNetwork::DiscriminativePCNetwork ( int batchSize)
inline

Batched constructor.

Parameters
batchSizeBatch size

Initializes the network with a predetermined batch size.

◆ ~DiscriminativePCNetwork()

Deep::DiscriminativePCNetwork::~DiscriminativePCNetwork ( )
default

Default constructor; deletes each layer.

◆ DiscriminativePCNetwork() [3/3]

Deep::DiscriminativePCNetwork::DiscriminativePCNetwork ( DiscriminativePCNetwork && other)
defaultnoexcept

Move constructor.

Member Function Documentation

◆ AddLayer() [1/2]

void Deep::DiscriminativePCNetwork::AddLayer ( int size,
int nextSize,
float lr,
float ir,
float pr,
float lmbda,
Deep::ActivationType aType,
Deep::ActivationType dType )

Adds a layer to the network, using a named ActivationType instead of raw function pointers.

Parameters
sizeinput size
nextSizeoutput size
lrlearning rate for beliefs
irlearning rate for weights
prlearning rate for precision
lmbdaweight decay (L2 regularization) coefficient
aTypeactivation type
dTypeactivation derivative type

◆ AddLayer() [2/2]

void Deep::DiscriminativePCNetwork::AddLayer ( int size,
int nextSize,
float lr,
float ir,
float pr,
float lmbda,
void(* act )(float *, size_t),
void(* dAct )(float *, size_t, bool) )

Adds a layer to the network.

Parameters
sizeinput size
nextSizeoutput size
lrlearning rate for beliefs
irlearning rate for weights
prlearning rate for precision
lmbdaweight decay (L2 regularization) coefficient
actactivation function
dActderivative of previous activation function

◆ CalculateState()

float Deep::DiscriminativePCNetwork::CalculateState ( )

Calculates the state of each layer.

Returns
Returns total energy

◆ Clamp()

void Deep::DiscriminativePCNetwork::Clamp ( const std::vector< float > & input)

Clamps the input to the first layer, necessary for prediction.

Parameters
inputreference to input vector

◆ Compile()

void Deep::DiscriminativePCNetwork::Compile ( )

Loads all layers into one contiguous block of memory.

◆ GetBatchSize()

int Deep::DiscriminativePCNetwork::GetBatchSize ( ) const
inlinenoexcept

Returns the batch size for the network's layers.

Returns
size_t batchSize

◆ GetLayers()

const auto & Deep::DiscriminativePCNetwork::GetLayers ( ) const
inlinenoexcept

Returns every layer in the network, in the order they were added.

Returns
A const reference to the internal layer list.

◆ GetTerminalLayer()

DiscriminativePCLayer * Deep::DiscriminativePCNetwork::GetTerminalLayer ( ) const
inline

Returns the network's terminal (final) layer.

Returns
Pointer to the last layer added via AddLayer(), or nullptr if no layers have been added.

◆ Load()

bool Deep::DiscriminativePCNetwork::Load ( const std::string & filename)
noexcept

Loads the network's learned parameters from disk.

Parameters
filenameThe source file path.
Returns
True on success, false otherwise.

◆ operator=()

DiscriminativePCNetwork & Deep::DiscriminativePCNetwork::operator= ( DiscriminativePCNetwork && other)
defaultnoexcept

Move assignment operator.

◆ Predict()

std::vector< float > Deep::DiscriminativePCNetwork::Predict ( const std::vector< float > & x,
int inferenceSteps )

Runs a forward prediction pass (clamp, settle, read).

Parameters
xThe batched input data
inferenceStepsThe number of relaxation iterations
Returns
A vector containing the batched predictions

◆ PredictWithProjection()

std::vector< float > Deep::DiscriminativePCNetwork::PredictWithProjection ( const std::vector< float > & x,
int inferenceSteps )

Same as Predict(), but with ProjectForward() called once after clamping the input, before the settling loop.

Parameters
xThe batched input data
inferenceStepsThe number of relaxation iterations
Returns
A vector containing the batched predictions

◆ ProjectForward()

void Deep::DiscriminativePCNetwork::ProjectForward ( )
noexcept

Seeds every hidden layer's belief from a genuine forward pass through current weights, rather than zero-init. Assumes the input layer is already clamped.

◆ RandomizeWeights()

void Deep::DiscriminativePCNetwork::RandomizeWeights ( std::mt19937 & rng)

Randomizes the weights of each layer.

Parameters
rngThe classic Mersenne Twister

◆ ResetState()

void Deep::DiscriminativePCNetwork::ResetState ( )
noexcept

Resets each layer's state without touching learned weights.

◆ Save()

bool Deep::DiscriminativePCNetwork::Save ( const std::string & filename) const
noexcept

Saves the network's learned parameters to disk.

Parameters
filenameThe destination file path.
Returns
True on success, false otherwise.

◆ SetInferenceRate()

void Deep::DiscriminativePCNetwork::SetInferenceRate ( float ir)
inline

Sets the inference rate used for state updates, on every layer.

Parameters
irThe new inference rate.

◆ SetLambda()

void Deep::DiscriminativePCNetwork::SetLambda ( float l)
inline

Sets the weight-decay (L2 regularization) coefficient, on every layer.

Parameters
lThe new lambda value.

◆ SetLearningRate()

void Deep::DiscriminativePCNetwork::SetLearningRate ( float lr)
inline

Sets the learning rate used for weight updates, on every layer.

Parameters
lrThe new learning rate.

◆ SetOptimizer()

void Deep::DiscriminativePCNetwork::SetOptimizer ( OptimizerType opt)
inlinenoexcept

Sets the optimizer used for weight updates, on every layer.

Parameters
optThe optimizer type to apply.

◆ SetPrecisionRate()

void Deep::DiscriminativePCNetwork::SetPrecisionRate ( float pr)
inline

Sets the learning rate used for precision updates, on every layer.

Parameters
prThe new precision rate.

◆ TrainStep()

float Deep::DiscriminativePCNetwork::TrainStep ( const std::vector< float > & x,
const std::vector< float > & y,
int inferenceSteps )

Runs a complete training step (clamp, settle, update, unclamp).

Parameters
xThe batched input data
yThe batched target data
inferenceStepsThe number of relaxation iterations
Returns
The final energy state of the network before weight updates

◆ TrainStepWithProjection()

float Deep::DiscriminativePCNetwork::TrainStepWithProjection ( const std::vector< float > & x,
const std::vector< float > & y,
int inferenceSteps )

Same as TrainStep(), but with ProjectForward() called once after clamping the input, before the settling loop.

Parameters
xThe batched input data
yThe batched target data
inferenceStepsThe number of relaxation iterations
Returns
The final energy state of the network before weight updates

◆ UpdatePrecision()

void Deep::DiscriminativePCNetwork::UpdatePrecision ( )

Updates each layer's precision weighting.

◆ UpdateState()

void Deep::DiscriminativePCNetwork::UpdateState ( )

Updates each layer's state.

◆ UpdateWeights()

void Deep::DiscriminativePCNetwork::UpdateWeights ( )

Updates each layer's weights.

◆ PCNDiagnostics

friend class PCNDiagnostics
friend

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