EventReducer

class EventReducer(step_time: float, criterion: OneToOne[Tensor], initial: Literal['inf', 'zero', 'nan'] = 'inf', duration: float = 0.0, inclusive: bool = False, inplace: bool = False)[source]

Bases: FoldReducer

Stores the length of time since an element of the input matched a criterion.

Parameters:
  • step_time (float) – length of time between observation.

  • criterion (OneToOne[torch.Tensor]) – function to test if the input is considered matches for it to be considered an event.

  • initial (Literal["inf", "zero", "nan"], optional) – initial value to which the tensor should be set. Defaults to "inf".

  • duration (float, optional) – length of time over which results should be stored, in the same units as step_time. 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

The output of criterion must have a datatype (torch.dtype) of torch.bool. The datatype returned by fold() will be the same as that of the reducer itself.

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

Application of last prior event.

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]

Exact value 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