src.canns.trainer.stdp¶
STDP (Spike-Timing-Dependent Plasticity) trainer.
Classes¶
STDP (Spike-Timing-Dependent Plasticity) trainer. |
Module Contents¶
- class src.canns.trainer.stdp.STDPTrainer(model, learning_rate=0.01, A_plus=0.005, A_minus=0.00525, weight_attr='W', w_min=0.0, w_max=1.0, compiled=True, **kwargs)[source]¶
Bases:
src.canns.trainer._base.TrainerSTDP (Spike-Timing-Dependent Plasticity) trainer.
STDP is a biologically-inspired learning rule that adjusts synaptic weights based on the precise timing of pre- and post-synaptic spikes. Synapses are strengthened when pre-synaptic spikes precede post-synaptic spikes (LTP), and weakened when the order is reversed (LTD).
- Trace-based Learning Rule:
ΔW_ij = A_plus * trace_pre[j] * spike_post[i] - A_minus * trace_post[i] * spike_pre[j]
- where:
W_ij is the weight from input j to neuron i
spike_pre[j] is the presynaptic spike (0 or 1)
spike_post[i] is the postsynaptic spike (0 or 1)
trace_pre[j] is the exponential trace of presynaptic spikes
trace_post[i] is the exponential trace of postsynaptic spikes
A_plus controls LTP (long-term potentiation) magnitude
A_minus controls LTD (long-term depression) magnitude
- The spike traces evolve as:
trace = decay * trace + spike
This provides a temporal window for spike-timing correlations.
References
Gerstner & Kistler (2002): Spiking Neuron Models
Morrison et al. (2008): Phenomenological models of synaptic plasticity
Bi & Poo (1998): Synaptic modifications in cultured hippocampal neurons
Initialize STDP trainer.
- Parameters:
model (src.canns.models.brain_inspired.BrainInspiredModel) – The spiking model to train (typically SpikingLayer)
learning_rate (float) – Global learning rate multiplier (default: 0.01)
A_plus (float) – LTP magnitude (default: 0.005)
A_minus (float) – LTD magnitude (default: 0.00525, slightly > A_plus for stability)
weight_attr (str) – Name of model attribute holding the connection weights
w_min (float) – Minimum weight value (default: 0.0 for excitatory synapses)
w_max (float) – Maximum weight value (default: 1.0)
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 spikes for a single input spike pattern.
- Parameters:
pattern – Input spike pattern of shape (input_size,)
- Returns:
Output spike pattern of shape (output_size,) with binary values (0 or 1)
- train(train_data)[source]¶
Train the model using STDP rule.
- Parameters:
train_data (collections.abc.Iterable) – Iterable of input spike patterns (each of shape (input_size,)) Each pattern should contain binary values (0 or 1)