![]() |
pydeepity
Python bindings for Deepity
|
Public Member Functions | |
| None | __init__ (self, *Layer|Activation architecture, Optional[int] batch_size=None) |
| None | configure (self, float learning_rate=1e-6, float inference_rate=0.1, float lmbda=1e-2, str optimizer="SGD") |
| None | set_optimizer (self, str optimizer) |
| None | set_learning_rate (self, float lr) |
| None | set_inference_rate (self, float ir) |
| 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) |
| float | train_step_with_projection (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) |
| "GaussSeidelPCN" | 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) |
Public Attributes | |
| architecture = architecture | |
| 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-6 |
| float | _inference_rate = 0.1 |
| int | _lambda = 1e-2 |
| str | _optimizer = "SGD" |
A Predictive Coding Network with Gauss-Seidel (sequential-sweep)
settling dynamics.
Unlike the fully-synchronous (Jacobi) dynamics used by other PCN
implementations, Gauss-Seidel settling allows later layers to see
already-updated values from earlier layers within the same step.
A full settling step consists of three sweeps:
1. Update z states.
2. Recompute predictions using the fresh z states.
3. Recompute errors using the fresh predictions.
Feedback goes through E, an independently-initialized, never-updated
feedback-alignment matrix (Lillicrap et al.), not W transposed, so
this is feedback alignment, not backprop-style symmetric weight
transport. The weight update itself (dE/dW) is a true gradient,
independently verified via finite-difference check
(tGaussSeidelPCLayerVerify.cpp). E's role in the state-settling
feedback term is deliberately not a gradient and isn't checked
against one, matching DirectKPPCN's own Psi.
Precision-free and AdamW-capable, matching SimplePCN's conventions.
| None deepity.GaussSeidelPCN.GaussSeidelPCN.__init__ | ( | self, | |
| *Layer | Activation | architecture, | ||
| Optional[int] | batch_size = None ) |
|
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.
|
protected |
|
protected |
Validate the declarative network architecture.
| None deepity.GaussSeidelPCN.GaussSeidelPCN.compile | ( | self | ) |
Compile the backend network.
| None deepity.GaussSeidelPCN.GaussSeidelPCN.configure | ( | self, | |
| float | learning_rate = 1e-6, | ||
| float | inference_rate = 0.1, | ||
| float | lmbda = 1e-2, | ||
| str | optimizer = "SGD" ) |
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.
| "GaussSeidelPCN" deepity.GaussSeidelPCN.GaussSeidelPCN.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.
| npt.NDArray[np.float32] deepity.GaussSeidelPCN.GaussSeidelPCN.predict | ( | self, | |
| npt.NDArray[np.float32] | X, | ||
| int | steps ) |
Settle the network and return the terminal-layer beliefs.
| None deepity.GaussSeidelPCN.GaussSeidelPCN.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.GaussSeidelPCN.GaussSeidelPCN.set_inference_rate | ( | self, | |
| float | ir ) |
Set the inference rate on every backend layer.
| None deepity.GaussSeidelPCN.GaussSeidelPCN.set_learning_rate | ( | self, | |
| float | lr ) |
Set the learning rate on every backend layer.
| None deepity.GaussSeidelPCN.GaussSeidelPCN.set_optimizer | ( | self, | |
| str | optimizer ) |
Set the optimizer: SGD, ADAM, or ADAMW.
| float deepity.GaussSeidelPCN.GaussSeidelPCN.train_step | ( | self, | |
| npt.NDArray[np.float32] | X, | ||
| npt.NDArray[np.float32] | Y, | ||
| int | steps ) |
Perform one training step using zero-initialized hidden states. Hidden layers are reset for each batch and then settled using Gauss-Seidel dynamics.
| float deepity.GaussSeidelPCN.GaussSeidelPCN.train_step_with_projection | ( | self, | |
| npt.NDArray[np.float32] | X, | ||
| npt.NDArray[np.float32] | Y, | ||
| int | steps ) |
Perform one training step using forward-projection initialization. Hidden layers are initialized from a genuine forward pass through the current weights before Gauss-Seidel settling.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
| deepity.GaussSeidelPCN.GaussSeidelPCN.architecture = architecture |
| deepity.GaussSeidelPCN.GaussSeidelPCN.layers |