src.canns.trainer.oja¶
Oja’s normalized Hebbian learning trainer.
Classes¶
Oja's normalized Hebbian learning trainer. |
Module Contents¶
- class src.canns.trainer.oja.OjaTrainer(model, learning_rate=0.01, normalize_weights=True, weight_attr='W', compiled=True, **kwargs)[source]¶
Bases:
src.canns.trainer._base.TrainerOja’s normalized Hebbian learning trainer.
Oja’s rule stabilizes pure Hebbian growth by introducing a weight-dependent normalization term, enabling single-neuron principal component extraction without unbounded weight magnitudes.
- Learning Rule:
ΔW_ij = η * (y_i * x_j - y_i^2 * W_ij)
- where:
W_ij is the weight from input j to output i
x_j is the input activity
y_i is the output activity (y = W @ x)
η is the learning rate
- The rule can be rewritten as:
ΔW = η * (y @ x^T - diag(y^2) @ W)
This naturally leads to weight normalization and PCA extraction.
- Reference:
Oja, E. (1982). Simplified neuron model as a principal component analyzer. Journal of Mathematical Biology, 15(3), 267-273.
Initialize Oja trainer.
- Parameters:
model (src.canns.models.brain_inspired.BrainInspiredModel) – The model to train (typically LinearLayer)
learning_rate (float) – Learning rate η for weight updates
normalize_weights (bool) – Whether to normalize weights to unit norm after each update
weight_attr (str) – Name of model attribute holding the connection weights
compiled (bool) – Whether to use JIT-compiled training loop (default: True)
**kwargs – Additional arguments passed to parent Trainer
- predict(pattern, *args, **kwargs)[source]¶
Predict output for a single input pattern.
- Parameters:
pattern – Input pattern of shape (input_size,)
- Returns:
Output pattern of shape (output_size,)
- train(train_data)[source]¶
Train the model using Oja’s rule.
- Parameters:
train_data (collections.abc.Iterable) – Iterable of input patterns (each of shape (input_size,))