pyhgf.model.hybrid.EquinoxAdapter#

class pyhgf.model.hybrid.EquinoxAdapter(forward_fn, backward_fn)[source]#

A frozen part: a fixed calculation that routes errors but never learns.

Declares a forward function and its hand-derived backward companion — no automatic differentiation is involved at any point:

  • forward_fn(x) -> (y, cache) computes the output for a batch and returns whatever the backward formula needs;

  • backward_fn(cache, error) -> error_in translates the error at the output into the error at the input, using only the cache.

Error convention

Both forward_fn and backward_fn use the descent-error convention (see pyhgf.model.error_types):

  • forward_fn receives arrays in the pipeline’s usual format

  • backward_fn receives DescentError (positive = signal too high) and returns the same convention

The hand-derived backward formula must respect this convention: if the function is y = f(x) and loss is L(y), then backward_fn should return ∂L/∂x = (∂L/∂y) @ (∂y/∂x)^T.

Use the ready-made constructors gelu_adapter() and layer_norm_adapter() for the standard Transformer pieces.

Parameters:
  • forward_fn (Callable[[jnp.ndarray], tuple[jnp.ndarray, tuple]])

  • backward_fn (Callable[[tuple, DescentError], DescentError])

__init__(forward_fn, backward_fn)[source]#
Parameters:

Methods

__init__(forward_fn, backward_fn)

init_state()

Return the empty state pytree (frozen parts have no state).