KappaFilter#

class braintrace.KappaFilter#

Low-pass filter helper state.

EProp no longer uses this class directly — it filters the eligibility trace internally instead. KappaFilter remains public and available for user-side filtering of an output-side (or any other) signal outside the algorithm’s own hooks.

The filter smooths the signal following \(x_{\mathrm{filt}} \leftarrow (1-\kappa) \cdot x + \kappa \cdot x_{\mathrm{filt}}\).

Parameters:
  • init_value (jax.Array) – Initial value; also dictates the shape and dtype of the filtered state.

  • kappa (float) – Decay factor \(\kappa\) in [0, 1). A value of 0 disables filtering.

Raises:

ValueError – If kappa is not inside the half-open interval [0, 1).

Examples

>>> import jax.numpy as jnp
>>> import braintrace
>>> filt = braintrace.KappaFilter(jnp.zeros(3), kappa=0.5)
>>> out = filt.update(jnp.ones(3))
>>> print(out)
[0.5 0.5 0.5]
>>> out = filt.update(jnp.ones(3))
>>> print(out)
[0.75 0.75 0.75]
update(x)#

Apply one low-pass step \(x_{\mathrm{filt}} \leftarrow (1-\kappa) x + \kappa\, x_{\mathrm{filt}}\).

Parameters:

x (jax.Array) – The new input mixed into the filtered state.

Returns:

jax.Array – The updated, filtered value.

KappaFilter.__init__(init_value, kappa)#

Initialize a new HiddenState instance.

This constructor sets up the initial state for a hidden state in a dynamic model, handling various input types and metadata.

Parameters:
  • value (Union[PyTree[ArrayLike], StateMetadata[PyTree[ArrayLike]]]) – The initial value for the hidden state. Can be a PyTree of array-like objects or a StateMetadata object containing both value and metadata.

  • name (Optional[str], optional) – A name for the hidden state. Defaults to None.

  • **metadata – Additional metadata to be stored with the hidden state, including: - tag (Optional[str]): A tag for categorizing or grouping states. - Any other custom metadata fields.

Notes

This method initializes the hidden state, processes the input value and metadata, sets up internal attributes, and records the state initialization.