![]() |
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 precision_rate=0.01, float lmbda=1e-2, str optimizer="SGD") |
| None | set_learning_rate (self, float lr) |
| None | set_inference_rate (self, float ir) |
| None | set_precision_rate (self, float pr) |
| None | set_lambda (self, float lmbda) |
| None | set_optimizer (self, str optimizer) |
| 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) |
| "SequentialPCN" | 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) |
| "SequentialPCN" | 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) |
| bool | save (self, str dir_path) |
| bool | load (self, str dir_path) |
Public Attributes | |
| architecture = architecture | |
Protected Member Functions | |
| None | _validate_architecture (self) |
| None | _build_backend (self) |
| None | _require_configured (self) |
Protected Attributes | |
| Optional[float] | _learning_rate = None |
| Optional[float] | _inference_rate = None |
| Optional[float] | _precision_rate = None |
| Optional[float] | _lambda = None |
| Optional[str] | _optimizer = None |
| bool | _configured = False |
Sequential Predictive Coding Network. The architecture is declared using Linear and Activation objects, while optimization and inference parameters are supplied through configure().
| None deepity.SequentialPCN.SequentialPCN.__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. 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 -- same pattern as SimplePCN._build_backend().
|
protected |
|
protected |
| None deepity.SequentialPCN.SequentialPCN.configure | ( | self, | |
| float | learning_rate = 1e-6, | ||
| float | inference_rate = 0.1, | ||
| float | precision_rate = 0.01, | ||
| float | lmbda = 1e-2, | ||
| str | optimizer = "SGD" ) |
Configure network hyperparameters and initialize the backend. Must be called once, before train_step()/predict(). @param learning_rate Learning rate for the forward weights. @param inference_rate Inference/settling rate. @param precision_rate Learning rate for precision weighting. @param lmbda Regularization parameter. @param optimizer Optimizer used for the forward weights.
| "SequentialPCN" deepity.SequentialPCN.SequentialPCN.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 ) |
Train for multiple epochs over (X, Y), batching by `self.batch_size` and printing a progress bar.
| "SequentialPCN" deepity.SequentialPCN.SequentialPCN.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 ) |
Train using I_avg initialization: each requested layer's beliefs are seeded from that layer's per-class running mean from the previous batch where that class appeared, instead of zero-init every batch. @param labels Integer class label per sample, same row order as X/Y. @param per_class Examples per class per batch; see StreamAlignedBatcher. @param num_classes Total number of distinct classes in labels. @param cache_layers List of (layer_index, layer_size) pairs to seed from their per-class cache. @param reset_cache_per_epoch If True, clear every cache at the start of each epoch; if False, caches persist across epochs.
| bool deepity.SequentialPCN.SequentialPCN.load | ( | self, | |
| str | dir_path ) |
Load the network's weights from `dir_path`.
| npt.NDArray[np.float32] deepity.SequentialPCN.SequentialPCN.predict | ( | self, | |
| npt.NDArray[np.float32] | X, | ||
| int | steps ) |
Run inference on `X`, settling for `steps` iterations. @return The terminal layer's beliefs.
| bool deepity.SequentialPCN.SequentialPCN.save | ( | self, | |
| str | dir_path ) |
Save the network's weights to `dir_path`.
| None deepity.SequentialPCN.SequentialPCN.set_inference_rate | ( | self, | |
| float | ir ) |
Set the inference/settling rate on every layer.
| None deepity.SequentialPCN.SequentialPCN.set_lambda | ( | self, | |
| float | lmbda ) |
Set the regularization parameter on every layer.
| None deepity.SequentialPCN.SequentialPCN.set_learning_rate | ( | self, | |
| float | lr ) |
Set the learning rate for the forward weights.
| None deepity.SequentialPCN.SequentialPCN.set_optimizer | ( | self, | |
| str | optimizer ) |
Set the optimizer used for the forward weights.
| None deepity.SequentialPCN.SequentialPCN.set_precision_rate | ( | self, | |
| float | pr ) |
Set the precision-weighting learning rate on every layer.
| float deepity.SequentialPCN.SequentialPCN.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 |
|
protected |
| deepity.SequentialPCN.SequentialPCN.architecture = architecture |