![]() |
pydeepity
Python bindings for Deepity
|
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" |
A Sequential Predictive Coding Network using synchronous settling dynamics. Networks are defined declaratively using Linear layers and activation functions, then configured before training.
| None deepity.SimplePCN.SimplePCN.__init__ | ( | self, | |
| *Layer | Activation | architecture, | ||
| Optional[int] | batch_size = None, | ||
| str | device = "cpu" ) |
|
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.
|
protected |
|
protected |
Validate the declarative network architecture.
| None deepity.SimplePCN.SimplePCN.compile | ( | self | ) |
Allocate backend buffers for the network built by _build_backend(). Called automatically by 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()).
| "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.
| "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.
| 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.
| 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).
| None deepity.SimplePCN.SimplePCN.set_inference_rate | ( | self, | |
| float | ir ) |
Set the inference/settling rate on every layer.
| None deepity.SimplePCN.SimplePCN.set_learning_rate | ( | self, | |
| float | lr ) |
Set the learning rate on every layer.
| 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.
| None deepity.SimplePCN.SimplePCN.set_optimizer | ( | self, | |
| str | optimizer ) |
Set the optimizer used for the forward weights: SGD, ADAM, or ADAMW.
| 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`.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
| deepity.SimplePCN.SimplePCN.architecture = architecture |
| deepity.SimplePCN.SimplePCN.device = device |
| deepity.SimplePCN.SimplePCN.layers |