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

Convolutional Predictive Coding layer (im2col-based). See the file-level warning above before enabling an unclamped middle layer. More...

#include <ConvPCLayer.h>

Inheritance diagram for Deep::ConvPCLayer:
Deep::Layer

Public Member Functions

 ConvPCLayer (int inChannels, int outChannels, int inHeight, int inWidth, int kernelH, int kernelW, int strideH=1, int strideW=1, int padH=0, int padW=0, int batchSize=1, float learningRate=1e-6f, float inferenceRate=0.1f, float precisionRate=0.01f, float lmbda=1e-2f, ActivationType aType=ActivationType::RELU, ActivationType dType=ActivationType::dRELU)
 Constructor for a convolutional PC layer.
float CalculateState () noexcept override
 Calculate energy/prediction errors for this layer.
void UpdateState () noexcept override
 Update latent beliefs (z/r) via inference gradient.
void UpdateWeights () noexcept override
 Hebbian/gradient weight update.
void UpdatePrecision () noexcept
 Updates this layer's precision estimate from current prediction errors, using the configured precision rate (pr).
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.
float * GetBeliefs () noexcept override
 Returns this layer's belief buffer.
const float * GetErrors () const noexcept override
 Returns this layer's prediction-error buffer.
const float * GetMu () const noexcept
 Returns this layer's top-down prediction buffer.
size_t GetInputSize () const noexcept override
 Flattened element count per batch item (inChannels*H*W).
size_t GetOutputSize () const noexcept override
 Flattened element count of this layer's OUTGOING prediction (outChannels*outH*outW), 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.
const float * GetPrecisions () const noexcept
 Returns this layer's precision buffer.
float GetLearningRate () const noexcept
 Returns the learning rate used for weight updates.
float GetInferenceRate () const noexcept
 Returns the learning rate used for internal-state updates.
float GetPrecisionRate () const noexcept
 Returns the learning rate used for precision updates.
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 learning rate used for internal-state updates.
void SetPrecisionRate (float pr) noexcept
 Sets the learning rate used for precision updates.
void SetLambda (float l) noexcept
 Sets the weight-decay (L2 regularization) coefficient.
void SetLayerAbove (ConvPCLayer *above) noexcept
 Sets the layer immediately above this one in the network.
void SetLayerBelow (ConvPCLayer *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.
void RandomizeWeights (std::mt19937 &twister) noexcept
 Randomizes this layer's weights (and biases) in place.
std::map< std::string, TensorDescriptor > GetStateDict () const override
 Returns a dictionary of this.
void ResyncLogPrecision () noexcept
 Rebuilds log_p from p – required after a checkpoint load that only persists p (mirrors DiscriminativePCLayer's fix for the same p/log_p desync issue found in ModelIO::Load()).
void ComputeMuOnly () noexcept
 Fast-path forward projection that skips state initialization.
ActivationType GetActivationType () const noexcept
 Returns this layer's configured activation type.
ActivationType GetDerivativeType () const noexcept
 Returns this layer's configured activation-derivative type.
int GetInChannels () const noexcept
 Returns the number of input channels.
int GetOutChannels () const noexcept
 Returns the number of output channels (0 for a terminal layer).
int GetInHeight () const noexcept
 Returns the input feature-map height.
int GetInWidth () const noexcept
 Returns the input feature-map width.
int GetOutHeight () const noexcept
 Returns the output feature-map height.
int GetOutWidth () const noexcept
 Returns the output feature-map width.
int GetKernelH () const noexcept
 Returns the convolution kernel height.
int GetKernelW () const noexcept
 Returns the convolution kernel width.
size_t GetRequiredFloats () const noexcept
 Computes the total number of floats this layer requires from a MemoryArena (weights, biases, beliefs, errors, and every scratch buffer combined).
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

Friends

class PCNDiagnostics

Additional Inherited Members

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

Detailed Description

Convolutional Predictive Coding layer (im2col-based). See the file-level warning above before enabling an unclamped middle layer.

Constructor & Destructor Documentation

◆ ConvPCLayer()

Deep::ConvPCLayer::ConvPCLayer ( int inChannels,
int outChannels,
int inHeight,
int inWidth,
int kernelH,
int kernelW,
int strideH = 1,
int strideW = 1,
int padH = 0,
int padW = 0,
int batchSize = 1,
float learningRate = 1e-6f,
float inferenceRate = 0.1f,
float precisionRate = 0.01f,
float lmbda = 1e-2f,
ActivationType aType = ActivationType::RELU,
ActivationType dType = ActivationType::dRELU )

Constructor for a convolutional PC layer.

Parameters
inChannelsNumber of input channels
outChannelsNumber of output channels (0 marks a terminal layer, matching DiscriminativePCLayer's convention where nextSize=0 means "no outgoing prediction")
inHeightInput feature-map height
inWidthInput feature-map width
kernelHKernel height
kernelWKernel width
strideHVertical stride
strideWHorizontal stride
padHVertical zero-padding
padWHorizontal zero-padding
batchSizeBatch size
learningRateLearning rate for weights
inferenceRateLearning rate for internal state
precisionRateLearning rate for precision
lmbdaWeight decay (L2 regularization) coefficient
aTypeActivation type
dTypeActivation derivative type

Member Function Documentation

◆ BindMemory()

void Deep::ConvPCLayer::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::ConvPCLayer::CalculateState ( )
overridevirtualnoexcept

Calculate energy/prediction errors for this layer.

Warning
Weight-gradient path verified; feedback term NOT YET verified—see file-level warning.
Returns
This layer's energy contribution at the current state.

Implements Deep::Layer.

◆ ClampState()

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

Clamps this layer's beliefs to externally-provided data, preventing them from being updated by UpdateState().

Parameters
inputDataFlattened input data matching (inChannels, inHeight, inWidth) per batch item.

◆ ComputeMuOnly()

void Deep::ConvPCLayer::ComputeMuOnly ( )
noexcept

Fast-path forward projection that skips state initialization.

◆ Flush()

void Deep::ConvPCLayer::Flush ( )
inlineoverridevirtualnoexcept

No-op; exists for Layer interface conformance.

Reimplemented from Deep::Layer.

◆ GetActivationType()

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

Returns this layer's configured activation type.

Returns
The activation type.

◆ GetBatchSize()

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

Returns the batch size this layer was constructed with.

Returns
The batch size.

Implements Deep::Layer.

◆ GetBeliefs()

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

Returns this layer's belief buffer.

Returns
Pointer to (outChannels, outHeight, outWidth) beliefs per batch item.

Implements Deep::Layer.

◆ GetBiases() [1/2]

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

Returns this layer's bias buffer.

Returns
Pointer to (outChannels,) biases.

◆ GetBiases() [2/2]

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

Returns this layer's bias buffer.

Returns
Pointer to (outChannels,) biases.

◆ GetDerivativeType()

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

Returns this layer's configured activation-derivative type.

Returns
The activation-derivative type.

◆ GetErrors()

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

Returns this layer's prediction-error buffer.

Returns
Pointer to (outChannels, outHeight, outWidth) errors per batch item.

Implements Deep::Layer.

◆ GetInChannels()

int Deep::ConvPCLayer::GetInChannels ( ) const
inlinenoexcept

Returns the number of input channels.

◆ GetInferenceRate()

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

Returns the learning rate used for internal-state updates.

Returns
The inference rate.

◆ GetInHeight()

int Deep::ConvPCLayer::GetInHeight ( ) const
inlinenoexcept

Returns the input feature-map height.

◆ GetInputSize()

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

Flattened element count per batch item (inChannels*H*W).

Implements Deep::Layer.

◆ GetInWidth()

int Deep::ConvPCLayer::GetInWidth ( ) const
inlinenoexcept

Returns the input feature-map width.

◆ GetKernelH()

int Deep::ConvPCLayer::GetKernelH ( ) const
inlinenoexcept

Returns the convolution kernel height.

◆ GetKernelW()

int Deep::ConvPCLayer::GetKernelW ( ) const
inlinenoexcept

Returns the convolution kernel width.

◆ GetLambda()

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

Returns the weight-decay (L2 regularization) coefficient.

Returns
Lambda.

◆ GetLearningRate()

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

Returns the learning rate used for weight updates.

Returns
The learning rate.

◆ GetMu()

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

Returns this layer's top-down prediction buffer.

◆ GetOutChannels()

int Deep::ConvPCLayer::GetOutChannels ( ) const
inlinenoexcept

Returns the number of output channels (0 for a terminal layer).

◆ GetOutHeight()

int Deep::ConvPCLayer::GetOutHeight ( ) const
inlinenoexcept

Returns the output feature-map height.

◆ GetOutputSize()

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

Flattened element count of this layer's OUTGOING prediction (outChannels*outH*outW), 0 for a terminal layer.

Implements Deep::Layer.

◆ GetOutWidth()

int Deep::ConvPCLayer::GetOutWidth ( ) const
inlinenoexcept

Returns the output feature-map width.

◆ GetPrecisionRate()

float Deep::ConvPCLayer::GetPrecisionRate ( ) const
inlinenoexcept

Returns the learning rate used for precision updates.

Returns
The precision rate.

◆ GetPrecisions()

const float * Deep::ConvPCLayer::GetPrecisions ( ) const
inlinenoexcept

Returns this layer's precision buffer.

Returns
Pointer to (outChannels,) precisions.

◆ GetRequiredFloats()

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

Computes the total number of floats this layer requires from a MemoryArena (weights, biases, beliefs, errors, and every scratch buffer combined).

Returns
The required float count.

◆ GetStateDict()

std::map< std::string, TensorDescriptor > Deep::ConvPCLayer::GetStateDict ( ) const
overridevirtual

Returns a dictionary of this.

Reimplemented from Deep::Layer.

◆ GetWeights() [1/2]

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

Returns this layer's weight buffer.

Returns
Pointer to (outChannels, inChannels*kernelH*kernelW) weights.

◆ GetWeights() [2/2]

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

Returns this layer's weight buffer.

Returns
Pointer to (outChannels, inChannels*kernelH*kernelW) weights.

◆ RandomizeWeights()

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

Randomizes this layer's weights (and biases) in place.

Parameters
twisterThe classic Mersenne Twister

◆ ResetState()

void Deep::ConvPCLayer::ResetState ( )
noexcept

Resets this layer's beliefs/errors back to their initial values, without touching learned weights.

◆ ResyncLogPrecision()

void Deep::ConvPCLayer::ResyncLogPrecision ( )
noexcept

Rebuilds log_p from p – required after a checkpoint load that only persists p (mirrors DiscriminativePCLayer's fix for the same p/log_p desync issue found in ModelIO::Load()).

◆ SetInferenceRate()

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

Sets the learning rate used for internal-state updates.

Parameters
irThe new inference rate.

◆ SetLambda()

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

Sets the weight-decay (L2 regularization) coefficient.

Parameters
lThe new lambda value.

◆ SetLayerAbove()

void Deep::ConvPCLayer::SetLayerAbove ( ConvPCLayer * 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::ConvPCLayer::SetLayerBelow ( ConvPCLayer * 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::ConvPCLayer::SetLearningRate ( float lr)
inlinenoexcept

Sets the learning rate used for weight updates.

Parameters
lrThe new learning rate.

◆ SetPrecisionRate()

void Deep::ConvPCLayer::SetPrecisionRate ( float pr)
inlinenoexcept

Sets the learning rate used for precision updates.

Parameters
prThe new precision rate.

◆ UnclampState()

void Deep::ConvPCLayer::UnclampState ( )
noexcept

Releases a previous ClampState() call, allowing this layer's beliefs to update normally again.

◆ UpdatePrecision()

void Deep::ConvPCLayer::UpdatePrecision ( )
noexcept

Updates this layer's precision estimate from current prediction errors, using the configured precision rate (pr).

◆ UpdateState()

void Deep::ConvPCLayer::UpdateState ( )
overridevirtualnoexcept

Update latent beliefs (z/r) via inference gradient.

Warning
Feedback term not yet verified—see file-level warning.

Implements Deep::Layer.

◆ UpdateWeights()

void Deep::ConvPCLayer::UpdateWeights ( )
overridevirtualnoexcept

Hebbian/gradient weight update.

Warning
Weight-gradient path verified; feedback term NOT YET verified—see file-level warning.

Implements Deep::Layer.

◆ PCNDiagnostics

friend class PCNDiagnostics
friend

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