src.canns.trainer.sanger¶
Sanger’s rule for sequential principal component extraction.
Classes¶
Sanger's rule (Generalized Hebbian Algorithm) for multiple PC extraction. |
Module Contents¶
- class src.canns.trainer.sanger.SangerTrainer(model, learning_rate=0.01, normalize_weights=True, weight_attr='W', compiled=True, **kwargs)[source]¶
Bases:
src.canns.trainer._base.TrainerSanger’s rule (Generalized Hebbian Algorithm) for multiple PC extraction.
Extends Oja’s rule with Gram-Schmidt orthogonalization to extract multiple principal components. Each neuron learns to be orthogonal to all previous ones.
- Learning Rule:
ΔW_i = η * (y_i * x - y_i * Σ_{j≤i} y_j * W_j)
- where:
W_i is the i-th neuron’s weight vector
y = W @ x is the output vector
The sum enforces orthogonality (Gram-Schmidt process)
This allows sequential extraction of orthogonal principal components, with neuron i converging to the i-th principal component.
- Reference:
Sanger, T. D. (1989). Optimal unsupervised learning in a single-layer linear feedforward neural network. Neural Networks, 2(6), 459-473.
Initialize Sanger 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 Sanger’s rule.
- Parameters:
train_data (collections.abc.Iterable) – Iterable of input patterns (each of shape (input_size,))