pydeepity
Python bindings for Deepity
Loading...
Searching...
No Matches
deepity.SimplePCN.SimplePCN Class Reference
Inheritance diagram for deepity.SimplePCN.SimplePCN:

Public Member Functions

None __init__ (self, *Layer|Activation architecture, Optional[int] batch_size=None, str device="cpu")
None configure (self, float learning_rate=1e-4, float inference_rate=1e-4, float lmbda=0.0001, str optimizer="SGD", Optional[int] seed=None, str dist="normal")
None set_learning_rate (self, float lr)
None set_inference_rate (self, float ir)
None set_optimizer (self, str optimizer)
None compile (self)
None randomize_weights (self, Optional[int] seed=None, str dist="normal")
float train_step (self, npt.NDArray[np.float32] X, npt.NDArray[np.float32] Y, int steps)
npt.NDArray[np.float32] predict (self, npt.NDArray[np.float32] X, int steps)
"SimplePCN" fit (self, npt.NDArray[np.float32] X, npt.NDArray[np.float32] Y, int epochs, int steps, Optional[float] initial_lr=None, float decay_rate=1.0, bool shuffle=True)
None set_mu_cache_threshold (self, float threshold)
"SimplePCN" fit_iavg (self, npt.NDArray[np.float32] X, npt.NDArray[np.float32] Y, npt.NDArray[np.int32] labels, int epochs, int steps, int per_class, int num_classes, list[tuple[int, int]] cache_layers, Optional[float] initial_lr=None, float decay_rate=1.0, bool reset_cache_per_epoch=True)

Public Attributes

 architecture = architecture
 device = device
 layers

Protected Member Functions

None _validate_architecture (self)
None _build_backend (self)
None _require_configured (self)

Protected Attributes

bool _configured = False
int _learning_rate = 1e-4
int _inference_rate = 1e-4
float _lambda = 0.0001
str _optimizer = "SGD"

Detailed Description

A Sequential Predictive Coding Network using synchronous settling dynamics.

Networks are defined declaratively using Linear layers and activation
functions, then configured before training.

Constructor & Destructor Documentation

◆ __init__()

None deepity.SimplePCN.SimplePCN.__init__ ( self,
*Layer | Activation architecture,
Optional[int] batch_size = None,
str device = "cpu" )

Member Function Documentation

◆ _build_backend()

None deepity.SimplePCN.SimplePCN._build_backend ( self)
protected
Translate the declarative architecture into backend PC layers.

Each Linear layer becomes a backend layer. If an Activation follows
it, that activation is attached to the backend layer. A final
terminal (sink) layer is appended so that the network's last layer
holds the OUTPUT dimension's beliefs, not the last Linear's input
dimension. See DKPPCN._build_backend() for the same pattern.

◆ _require_configured()

None deepity.SimplePCN.SimplePCN._require_configured ( self)
protected

◆ _validate_architecture()

None deepity.SimplePCN.SimplePCN._validate_architecture ( self)
protected
Validate the declarative network architecture.

◆ compile()

None deepity.SimplePCN.SimplePCN.compile ( self)
Allocate backend buffers for the network built by
_build_backend(). Called automatically by configure().

◆ configure()

None deepity.SimplePCN.SimplePCN.configure ( self,
float learning_rate = 1e-4,
float inference_rate = 1e-4,
float lmbda = 0.0001,
str optimizer = "SGD",
Optional[int] seed = None,
str dist = "normal" )
Configure the network and build its backend layers.

Parameters
----------
learning_rate:
    Weight-learning rate.

inference_rate:
    State-inference rate used during settling.

lmbda:
    Precision/regularization parameter for PC layers.

optimizer:
    Optimizer to use: SGD, ADAM, or ADAMW.

seed:
    Optional seed for weight randomization, for reproducible
    runs. None (the default) uses a nondeterministic seed.

dist:
    Distribution for W's init, e.g. "normal(0,1)" or
    "uniform(-0.3,0.3)". The default "normal" has no "(a,b)"
    and so deliberately falls back to each layer's own
    existing default (see RandomizeWeights()).

◆ fit()

"SimplePCN" deepity.SimplePCN.SimplePCN.fit ( self,
npt.NDArray[np.float32] X,
npt.NDArray[np.float32] Y,
int epochs,
int steps,
Optional[float] initial_lr = None,
float decay_rate = 1.0,
bool shuffle = True )
Run multi-epoch training with a live Rich progress display.

If initial_lr is omitted, the learning rate supplied to configure()
is used.

◆ fit_iavg()

"SimplePCN" deepity.SimplePCN.SimplePCN.fit_iavg ( self,
npt.NDArray[np.float32] X,
npt.NDArray[np.float32] Y,
npt.NDArray[np.int32] labels,
int epochs,
int steps,
int per_class,
int num_classes,
list[tuple[int, int]] cache_layers,
Optional[float] initial_lr = None,
float decay_rate = 1.0,
bool reset_cache_per_epoch = True )
Specialized training loop using Class-Average Caching (I_avg).

Each requested hidden layer receives its own independent per-class
cache. The terminal layer should not be included in cache_layers.

◆ predict()

npt.NDArray[np.float32] deepity.SimplePCN.SimplePCN.predict ( self,
npt.NDArray[np.float32] X,
int steps )
Run inference on `X`, settling for `steps` iterations.
@return The terminal layer's beliefs.

◆ randomize_weights()

None deepity.SimplePCN.SimplePCN.randomize_weights ( self,
Optional[int] seed = None,
str dist = "normal" )
Randomize all network weights. `seed` gives a reproducible run;
`dist` e.g. "normal(0,1)" or "uniform(-0.3,0.3)" (the default
"normal" has no "(a,b)" and so deliberately falls back to each
layer's own existing init).

◆ set_inference_rate()

None deepity.SimplePCN.SimplePCN.set_inference_rate ( self,
float ir )
Set the inference/settling rate on every layer.

◆ set_learning_rate()

None deepity.SimplePCN.SimplePCN.set_learning_rate ( self,
float lr )
Set the learning rate on every layer.

◆ set_mu_cache_threshold()

None deepity.SimplePCN.SimplePCN.set_mu_cache_threshold ( self,
float threshold )
Set the mu-cache staleness threshold on every layer.

-1 disables caching.
 0 enables exact clamped-only caching.
>0 extends caching to unclamped layers as an approximation.

◆ set_optimizer()

None deepity.SimplePCN.SimplePCN.set_optimizer ( self,
str optimizer )
Set the optimizer used for the forward weights: SGD, ADAM, or ADAMW.

◆ train_step()

float deepity.SimplePCN.SimplePCN.train_step ( self,
npt.NDArray[np.float32] X,
npt.NDArray[np.float32] Y,
int steps )
Run one training step on a single batch, settling for
`steps` iterations before updating weights.
@return Total settling energy accumulated over `steps`.

Member Data Documentation

◆ _configured

bool deepity.SimplePCN.SimplePCN._configured = False
protected

◆ _inference_rate

int deepity.SimplePCN.SimplePCN._inference_rate = 1e-4
protected

◆ _lambda

float deepity.SimplePCN.SimplePCN._lambda = 0.0001
protected

◆ _learning_rate

int deepity.SimplePCN.SimplePCN._learning_rate = 1e-4
protected

◆ _optimizer

deepity.SimplePCN.SimplePCN._optimizer = "SGD"
protected

◆ architecture

deepity.SimplePCN.SimplePCN.architecture = architecture

◆ device

deepity.SimplePCN.SimplePCN.device = device

◆ layers

deepity.SimplePCN.SimplePCN.layers

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