experiments.equilibrium_propagation package
Submodules
experiments.equilibrium_propagation.models module
Adapted from https://github.com/Laborieux-Axel/Equilibrium-Propagation/blob/master/model_utils.py
- class experiments.equilibrium_propagation.models.P_MLP(archi, activation=<built-in method tanh of type object>)[source]
Bases:
ModuleLayered equilibrium-propagation multilayer perceptron.
- Parameters:
archi – Sequence of layer widths including input and output sizes.
activation – Activation used for hidden-state updates.
- Phi(x, y, neurons, beta, criterion)[source]
Compute the primitive energy for the current network state.
- Parameters:
x – Input batch.
y – Target labels.
neurons – Current layer-state tensors.
beta – Nudging coefficient for the loss term.
criterion – Loss function used when
betais non-zero.
- Returns:
Primitive value per sample.
- compute_syn_grads(x, y, neurons_1, neurons_2, betas, criterion)[source]
Compute synaptic gradients from two EP steady states.
- Parameters:
x – Input batch.
y – Target labels.
neurons_1 – First steady-state neurons.
neurons_2 – Second steady-state neurons.
betas – Pair of nudging coefficients.
criterion – Loss function used by the primitive.
- forward(x, y, neurons, T, beta=0.0, criterion=MSELoss())[source]
Run fixed-point dynamics for
Tsteps.- Parameters:
x – Input batch.
y – Target labels.
neurons – Initial layer-state tensors.
T – Number of dynamics steps.
beta – Nudging coefficient.
criterion – Loss function used by the primitive.
- Returns:
Updated neuron states.
- class experiments.equilibrium_propagation.models.RON(archi, device, activation=<built-in method tanh of type object>, tau=1, epsilon_min=0, epsilon_max=1, gamma_min=0, gamma_max=1, learn_oscillators=True)[source]
Bases:
ModuleEquilibrium-propagation Random Oscillator Network.
- Parameters:
archi – Sequence of layer widths including input and output sizes.
device – Torch device for parameters and states.
activation – Activation used by the state updates.
tau – Oscillator integration scale.
epsilon_min – Minimum initial epsilon value.
epsilon_max – Maximum initial epsilon value.
gamma_min – Minimum initial gamma value.
gamma_max – Maximum initial gamma value.
learn_oscillators – If
True, learn gamma and epsilon.
- Phi(x, y, neuronsz, neuronsy, beta, criterion)[source]
Compute the full RON primitive for gradient updates.
- Parameters:
x – Input batch.
y – Target labels.
neuronsz – Current
zstate tensors.neuronsy – Current
ystate tensors.beta – Nudging coefficient.
criterion – Loss function used by the primitive.
- Returns:
Primitive value per sample.
- Phi_statey(neuronsz, neuronsy)[source]
Compute the primitive used for the
yoscillator update.- Parameters:
neuronsz – Current
zstate tensors.neuronsy – Current
ystate tensors.
- Returns:
Primitive value per sample.
- Phi_statez(x, y, neuronsy, beta, criterion)[source]
Compute the primitive used for the
zoscillator update.- Parameters:
x – Input batch.
y – Target labels.
neuronsy – Current
ystate tensors.beta – Nudging coefficient.
criterion – Loss function used by the primitive.
- Returns:
Primitive value per sample.
- compute_syn_grads(x, y, neurons_1, neurons_2, betas, criterion)[source]
Compute synaptic gradients from two RON EP steady states.
- Parameters:
x – Input batch.
y – Target labels.
neurons_1 – First
(z, y)steady state.neurons_2 – Second
(z, y)steady state.betas – Pair of nudging coefficients.
criterion – Loss function used by the primitive.
- forward(x, y, neuronsz, neuronsy, T, beta=0.0, criterion=MSELoss())[source]
Run RON fixed-point dynamics for
Tsteps.- Parameters:
x – Input batch.
y – Target labels.
neuronsz – Initial
zstate tensors.neuronsy – Initial
ystate tensors.T – Number of dynamics steps.
beta – Nudging coefficient.
criterion – Loss function used by the primitive.
- Returns:
Tuple
(neuronsz, neuronsy)after the updates.
- experiments.equilibrium_propagation.models.copy(neurons)[source]
Clone neuron state tensors while preserving gradient tracking.
- Parameters:
neurons – Iterable of state tensors.
- Returns:
List of detached tensor copies with
requires_gradenabled.
- experiments.equilibrium_propagation.models.ctrd_hard_sig(x)[source]
Apply a centered hard-sigmoid-like activation.
- Parameters:
x – Input tensor.
- Returns:
Activated tensor centered around zero.
- experiments.equilibrium_propagation.models.evaluate(model, loader, T, device, ron=False)[source]
Evaluate classification accuracy for fixed-point dynamics.
- Parameters:
model – EP model to evaluate.
loader – Data loader yielding evaluation batches.
T – Number of dynamics steps.
device – Torch device for batches and states.
ron – If
True, use two-state RON dynamics.
- Returns:
Accuracy in
[0, 1].
- experiments.equilibrium_propagation.models.evaluate_TS(model, loader, T, device, ron=False)[source]
Evaluate classification accuracy on time-series data.
- Parameters:
model – EP model to evaluate.
loader – Data loader yielding sequence batches.
T – Number of dynamics steps per time step.
device – Torch device for batches and states.
ron – If
True, use two-state RON dynamics.
- Returns:
Accuracy in
[0, 1].
- experiments.equilibrium_propagation.models.hard_sigmoid(x)[source]
Apply a hard-sigmoid activation on
[0, 1].- Parameters:
x – Input tensor.
- Returns:
Activated tensor.
- experiments.equilibrium_propagation.models.make_pools(letters)[source]
Build pooling layers from a compact letter specification.
- Parameters:
letters – String where
mmeans max pool,aaverage pool, andiidentity.- Returns:
List of Torch pooling/identity modules.
- experiments.equilibrium_propagation.models.my_hard_sig(x)[source]
Apply the alternate hard-sigmoid activation used in experiments.
- Parameters:
x – Input tensor.
- Returns:
Activated tensor.
- experiments.equilibrium_propagation.models.my_init(scale)[source]
Create a scaled initializer for convolutional and linear layers.
- Parameters:
scale – Multiplicative factor applied after Kaiming/uniform initialization.
- Returns:
Initializer function suitable for
Module.apply.
- experiments.equilibrium_propagation.models.my_sigmoid(x)[source]
Apply the shifted sigmoid activation used by the EP examples.
- Parameters:
x – Input tensor.
- Returns:
Activated tensor.
- experiments.equilibrium_propagation.models.train_epoch(model, optimizer, epoch_number, train_loader, T1, T2, betas, device, criterion, alg='EP', random_sign=False, thirdphase=False, cep_debug=False, ron=False, id=None)[source]
Train one epoch with EP, CEP, or BPTT dynamics.
- Parameters:
model – EP model to train.
optimizer – Torch optimizer.
epoch_number – Current epoch index used for logging.
train_loader – Loader yielding training batches.
T1 – Number of first-phase dynamics steps.
T2 – Number of second-phase dynamics steps.
betas – Pair of nudging coefficients.
device – Torch device for batches and states.
criterion – Loss function used by the primitive.
alg – Training algorithm, such as
EP,CEP, orBPTT.random_sign – If
True, randomly flip the second beta sign.thirdphase – If
True, run the third-phase correction.cep_debug – If
True, apply CEP debug scaling.ron – If
True, use two-state RON dynamics.id – Optional trial id that suppresses progress printing.
- experiments.equilibrium_propagation.models.train_epoch_TS(model, optimizer, epoch_number, train_loader, T1, T2, betas, device, criterion, reset_factor=0.0, id=None, ron=False)[source]
Train one epoch on time-series data with per-timestep updates.
- Parameters:
model – EP model to train.
optimizer – Torch optimizer.
epoch_number – Current epoch index used for logging.
train_loader – Loader yielding sequence batches.
T1 – Number of first-phase dynamics steps per time step.
T2 – Number of second-phase dynamics steps per time step.
betas – Pair of nudging coefficients.
device – Torch device for batches and states.
criterion – Loss function used by the primitive.
reset_factor – Scale applied to carried state between time steps.
id – Optional trial id that suppresses progress printing.
ron – If
True, use two-state RON dynamics.
- experiments.equilibrium_propagation.models.visualize_convergence(model, loader, T_ep, device, ron=False, name=None)[source]
Plot fixed-point convergence for non-time-series dynamics.
- Parameters:
model – EP model to evaluate.
loader – Data loader used to fetch one batch.
T_ep – Number of single-step EP iterations to visualize.
device – Torch device for batches and states.
ron – If
True, use two-state RON dynamics.name – Optional plot title.
- Returns:
Mean L2 differences between consecutive states.
- experiments.equilibrium_propagation.models.visualize_convergence_TS(model, loader, T_ep, device, ron=False, name=None)[source]
Plot fixed-point convergence for time-series dynamics.
- Parameters:
model – EP model to evaluate.
loader – Data loader used to fetch one sequence batch.
T_ep – Number of single-step EP iterations per time step.
device – Torch device for batches and states.
ron – If
True, use two-state RON dynamics.name – Optional plot title.
- Returns:
Mean L2 differences across all time steps and EP iterations.
experiments.equilibrium_propagation.pendigits_dataset module
Module contents
Equilibrium-propagation experiment models and datasets.