CumulativeTraceReducer

class CumulativeTraceReducer(step_time: float, time_constant: float, amplitude: int | float | complex, target: int | float | bool | complex, tolerance: int | float | None = None, *, duration: float = 0.0, inclusive: bool = False, inplace: bool = False)[source]

Bases: FoldReducer

Stores the trace over time, considering all prior matches.

\[x(t) = x(t - \Delta t) \exp \left(-\frac{\Delta t}{\tau_x}\right) + A \left[\lvert h(t) - h^* \rvert \leq \epsilon\right]\]

For the trace (state) \(x\) and observation \(h\).

Parameters:
  • step_time (float) – length of the discrete step time, \(\Delta t\).

  • time_constant (float) – time constant of exponential decay, \(\tau_x\).

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

  • target (int | float | bool | complex) – target value test for when determining if an input is a match, \(h^*\).

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

  • duration (float, optional) – length of time over which results should be stored, in the same units as \(\Delta t\). Defaults to ` 0.0``.

  • inclusive (bool, optional) – if the duration should be inclusive. Defaults to False.

  • inplace (bool, optional) – if write operations should be performed in-place. Defaults to False.

Important

Because the input tensor to fold() is treated as an event condition, it will have its datatype cast to that of the reducer itself.

property dt: float

Length of the simulation time step, in milliseconds.

Parameters:

value (float) – new simulation time step length.

Returns:

length of the simulation time step.

Return type:

float

fold(obs: Tensor, state: Tensor | None) Tensor[source]

Application of cumulative trace.

Parameters:
  • obs (torch.Tensor) – observation to incorporate into state.

  • state (torch.Tensor | None) – state from the prior time step, None if no prior observations.

Returns:

state for the current time step.

Return type:

torch.Tensor

interpolate(prev_data: Tensor, next_data: Tensor, sample_at: Tensor, step_time: float) Tensor[source]

Exponential decay interpolation between observations.

Parameters:
  • prev_data (torch.Tensor) – most recent observation prior to sample time.

  • next_data (torch.Tensor) – most recent observation subsequent to sample time.

  • sample_at (torch.Tensor) – relative time at which to sample data.

  • step_time (float) – length of time between the prior and subsequent observations.

Returns:

interpolated data at sample time.

Return type:

torch.Tensor