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

Convolutional Predictive Coding Network built from SimpleConvPCLayer – precision-free, AdamW-capable, device-aware. More...

#include <SimpleConvPCNetwork.h>

Public Member Functions

 SimpleConvPCNetwork (int batchSize, DeviceType device=DeviceType::DEVICE_CPU) noexcept
 Constructs an empty network; add layers via AddLayer(), then Compile() before use.
 SimpleConvPCNetwork (const SimpleConvPCNetwork &)=delete
SimpleConvPCNetwork & operator= (const SimpleConvPCNetwork &)=delete
 ~SimpleConvPCNetwork ()=default
void AddLayer (int inChannels, int outChannels, int inHeight, int inWidth, int kernelH, int kernelW, int strideH=1, int strideW=1, int padH=0, int padW=0, float lr=1e-6f, float ir=0.1f, float lmbda=1e-2f, ActivationType aType=ActivationType::RELU, ActivationType dType=ActivationType::dRELU)
 Adds a convolutional layer. Pass outChannels=0 to mark a terminal layer (no outgoing prediction), matching SimpleConvPCLayer's nextSize=0 convention.
void SetOptimizer (OptimizerType opt) noexcept
 Sets the optimizer for EVERY layer added so far. Safe to call any time before Compile() – unlike using SimpleConvPCLayer standalone, memory allocation is deferred to Compile(), not the constructor, so this doesn't require a manual rebind.
void Compile ()
 Sums every layer's required float count into a single contiguous arena and binds each layer into it. Call after all AddLayer()/SetOptimizer() calls, before RandomizeWeights().
void RandomizeWeights (std::mt19937 &rng) noexcept
 Initializes every layer's weights randomly.
void ResetState () noexcept
 Resets the beliefs (z) on every layer.
void Clamp (const std::vector< float > &input) noexcept
 Clamps the flattened, batched input to the first (input) layer.
float CalculateState () noexcept
 Computes and returns the network's total energy at the current state, without changing it.
void UpdateState () noexcept
 Runs one settling step on every layer.
void UpdateWeights () noexcept
 Calls UpdateWeights() on every layer except the terminal one (each layer's own UpdateWeights() is also self-guarded against outChannels==0, so this is belt-and-suspenders).
SimpleConvPCLayer * GetTerminalLayer () noexcept
 Returns the last layer (outChannels==0, the terminal one).
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 given at construction.
float TrainStep (const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps)
 Full train step: clamp input+target, settle for inferenceSteps, update weights once, return the final energy.
std::vector< float > Predict (const std::vector< float > &x, int inferenceSteps)
 Clamps input only, settles, and returns the terminal layer's settled beliefs (flattened, batched).
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 TrainStepWithProjection (const std::vector< float > &x, const std::vector< float > &y, int inferenceSteps)
 Full train step with forward-projection init: clamp input, project forward, clamp target, settle, update weights, return the final energy.
std::vector< float > PredictWithProjection (const std::vector< float > &x, int inferenceSteps)
 Inference-only counterpart to TrainStepWithProjection(): clamp input, project forward, settle, read out the terminal layer's beliefs. No target clamp, no weight update.

Friends

class PCNDiagnostics

Detailed Description

Convolutional Predictive Coding Network built from SimpleConvPCLayer – precision-free, AdamW-capable, device-aware.

Constructor & Destructor Documentation

◆ SimpleConvPCNetwork() [1/2]

Deep::SimpleConvPCNetwork::SimpleConvPCNetwork ( int batchSize,
DeviceType device = DeviceType::DEVICE_CPU )
explicitnoexcept

Constructs an empty network; add layers via AddLayer(), then Compile() before use.

Parameters
batchSizeFixed batch size for every layer.
deviceWhich device this network's layers run on.

◆ SimpleConvPCNetwork() [2/2]

Deep::SimpleConvPCNetwork::SimpleConvPCNetwork ( const SimpleConvPCNetwork & )
delete

◆ ~SimpleConvPCNetwork()

Deep::SimpleConvPCNetwork::~SimpleConvPCNetwork ( )
default

Member Function Documentation

◆ AddLayer()

void Deep::SimpleConvPCNetwork::AddLayer ( int inChannels,
int outChannels,
int inHeight,
int inWidth,
int kernelH,
int kernelW,
int strideH = 1,
int strideW = 1,
int padH = 0,
int padW = 0,
float lr = 1e-6f,
float ir = 0.1f,
float lmbda = 1e-2f,
ActivationType aType = ActivationType::RELU,
ActivationType dType = ActivationType::dRELU )

Adds a convolutional layer. Pass outChannels=0 to mark a terminal layer (no outgoing prediction), matching SimpleConvPCLayer's nextSize=0 convention.

◆ CalculateState()

float Deep::SimpleConvPCNetwork::CalculateState ( )
noexcept

Computes and returns the network's total energy at the current state, without changing it.

◆ Clamp()

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

Clamps the flattened, batched input to the first (input) layer.

◆ Compile()

void Deep::SimpleConvPCNetwork::Compile ( )

Sums every layer's required float count into a single contiguous arena and binds each layer into it. Call after all AddLayer()/SetOptimizer() calls, before RandomizeWeights().

◆ GetBatchSize()

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

Returns the batch size given at construction.

◆ GetLayers()

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

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

◆ GetTerminalLayer()

SimpleConvPCLayer * Deep::SimpleConvPCNetwork::GetTerminalLayer ( )
inlinenoexcept

Returns the last layer (outChannels==0, the terminal one).

◆ operator=()

SimpleConvPCNetwork & Deep::SimpleConvPCNetwork::operator= ( const SimpleConvPCNetwork & )
delete

◆ Predict()

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

Clamps input only, settles, and returns the terminal layer's settled beliefs (flattened, batched).

◆ PredictWithProjection()

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

Inference-only counterpart to TrainStepWithProjection(): clamp input, project forward, settle, read out the terminal layer's beliefs. No target clamp, no weight update.

◆ ProjectForward()

void Deep::SimpleConvPCNetwork::ProjectForward ( )
noexcept

Seeds hidden layers from a genuine forward pass through current weights, instead of zero-init. Call after Clamp(), before the settling loop.

◆ RandomizeWeights()

void Deep::SimpleConvPCNetwork::RandomizeWeights ( std::mt19937 & rng)
noexcept

Initializes every layer's weights randomly.

◆ ResetState()

void Deep::SimpleConvPCNetwork::ResetState ( )
noexcept

Resets the beliefs (z) on every layer.

◆ SetOptimizer()

void Deep::SimpleConvPCNetwork::SetOptimizer ( OptimizerType opt)
noexcept

Sets the optimizer for EVERY layer added so far. Safe to call any time before Compile() – unlike using SimpleConvPCLayer standalone, memory allocation is deferred to Compile(), not the constructor, so this doesn't require a manual rebind.

◆ TrainStep()

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

Full train step: clamp input+target, settle for inferenceSteps, update weights once, return the final energy.

◆ TrainStepWithProjection()

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

Full train step with forward-projection init: clamp input, project forward, clamp target, settle, update weights, return the final energy.

◆ UpdateState()

void Deep::SimpleConvPCNetwork::UpdateState ( )
noexcept

Runs one settling step on every layer.

◆ UpdateWeights()

void Deep::SimpleConvPCNetwork::UpdateWeights ( )
noexcept

Calls UpdateWeights() on every layer except the terminal one (each layer's own UpdateWeights() is also self-guarded against outChannels==0, so this is belt-and-suspenders).

◆ PCNDiagnostics

friend class PCNDiagnostics
friend

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