trace_nearest

trace_nearest(observation: Tensor, trace: Tensor | None, *, decay: float, amplitude: int | float | complex, target: int | float | bool | complex, tolerance: int | float | None = None) Tensor[source]

Performs a trace for a time step, considering the latest match.

\[\begin{split}x(t) = \begin{cases} A & \lvert h(t) - h^* \rvert \leq \epsilon \\ x(t - \Delta t) \alpha & \left[\lvert h(t) - h^* \rvert > \epsilon\right] \end{cases}\end{split}\]

When trace is None, the event mask created will be cast to the datatype of observation.

Parameters:
  • observation (torch.Tensor) – latest state to consider for the trace, \(h\).

  • trace (torch.Tensor | None) – current value of the trace, \(x\), if not the initial condition.

  • decay (float) – decay term of the trace, \(\alpha\), unitless.

  • amplitude (int | float | complex) – value to set trace to for matching elements, \(A\).

  • target (int | float | bool | complex) – target value to set trace to, \(h^*\).

  • tolerance (int | float | None, optional) – allowable absolute difference to still count as a match, \(\epsilon\). Defaults to None.

Returns:

updated trace, incorporating the new observation.

Return type:

torch.Tensor

Important

To compute a regular, exponentially decaying trace, this assumes that decay is precomputed as \(\exp\left(-\frac{\Delta t}{\tau}\right)\) or as \(\exp\left(-\lambda\Delta t\right)\), where \(\Delta t\) is the simulation step time and \(\tau\) is the decay time constant and \(\lambda\) is the decay rate constant.