LinearHomeostasis

class LinearHomeostasis(plasticity: float, target: float | None, param: Literal['weight', 'bias', 'delay'], batch_reduction: Callable[[Tensor, tuple[int, ...]], Tensor] | None = None, **kwargs)[source]

Bases: IndependentCellTrainer

Linear homeostatic regulation.

When param == "weight":

\[w(t + \Delta t) - w(t) = \lambda \frac{r^* - r}{r^*}\]

When param == "bias":

\[b(t + \Delta t) - b(t) = \frac{\lambda}{L} \sum{\frac{r^* - r}{r^*}}\]

When param == "delay":

\[d(t + \Delta t) - d(t) = -\lambda \frac{r^* - r}{r^*}\]

Where:

Times \(t\) is the current time, \(\Delta t\) is the duration of the simulation step, and \(L\) is the number of outputs corresponding to each bias term (for connections with a trainable bias).

Parameters:
  • plasticity (float) – learning rate for updates, \(\lambda\).

  • target (float | None, optional) – target rate for postsynaptic spikes, \(r^*\). Required to be specified on update when None.

  • param (Literal["weight", "bias", "delay"]) – specified parameter to update.

  • batch_reduction (Callable[[torch.Tensor, tuple[int, ...]], torch.Tensor] | None, optional) – function to reduce updates over the batch dimension, torch.mean() when None. Defaults to None.

Caution

The sign of \(\lambda\) is reversed in the case of training "delay" parameters. Generally, the sign of plasticity should be positive for the updater to behave in the manner expected, although this is not enforced.

Note

Updates are averaaged along the “receptive” dimension, i.e. the individual spike rates corresponding to each parameter.

Note

For the purposes of parameter bounding, the update term is split by clamping values. The sequence of operations follows:

  1. The receptive dimension is reduced.

  2. The updates are split into positive and negative parts.

  3. The batch dimension is reduced.

See also

For more details and references, visit Linear Homeostatic Plasticity in the zoo.

forward(target: float | Tensor | None = None, cells: Sequence[str] | None = None) None[source]

Processes update for given layers based on current monitor stored data.

Parameters:
  • target (float | torch.Tensor | None) – target rate for postsynaptic spikes, \(r^*\). Required to be specified on update if the default is None and will try to use the default when None. Defaults to None.

  • cells (Sequence[str] | None) – names of the cells to update, all cells if None. Defaults to None.

Shape

target:

\(B \times N_0 \times \cdots\) or \(1 \times N_0 \times \cdots\)

Where:
  • \(B\) is the batch size.

  • \(N_0, \ldots\) are the dimensions of the postsynaptic spikes.

register_cell(name: str, cell: Cell, /, **kwargs: Any) Unit[source]

Adds a cell with required state.

Parameters:
  • name (str) – name of the cell to add.

  • cell (Cell) – cell to add.

Keyword Arguments:
  • plasticity (float) – learning rate for updates, \(\lambda\).

  • target (float | None, optional) – target rate for postsynaptic spikes, \(r^*\). Required to be specified on update when None.

  • param (Literal["weight", "bias", "delay"]) – specified parameter to update.

  • batch_reduction (Callable[[torch.Tensor, tuple[int, ...]], torch.Tensor] | None) – function to reduce updates over the batch dimension, torch.mean() when None.

Returns:

specified cell, auxiliary state, and monitors.

Return type:

IndependentCellTrainer.Unit

Important

The target parameter can be specified as a tensor here, in which case it won’t need to be passed in on each forward() call but can still have a different value for each output. It must have the same shape as the output spikes of the cell.neuron. The batch dimension can have a size of 1 regardless of the batch sie.

Important

Any specified keyword arguments will override the default hyperparameters set on initialization. See DelayAdjustedSTDP for details.