rxmc.transforms.Transform#

class rxmc.transforms.Transform(fn: Callable, params: Sequence[Parameter] = (), *, contextual: bool = False, derivative: Callable | None = None, inverse=None, name: str | None = None)[source]#

Bases: object

A numpy-style transform with optional parameters.

Parameters:
  • fn (callable) – fn(a, *values) -> np.ndarray; when contextual is True, fn(context, a, *values) where context is whatever the owner passes (the Observation for model transforms).

  • params (sequence of Parameter, optional) – Parameters whose sampled values are passed as *values.

  • contextual (bool, optional) – Whether fn takes the owner’s context as its first argument.

  • derivative (callable, optional) – derivative(a, *values) -> np.ndarray, \(\partial fn/\partial a\) elementwise. Used for delta-method error propagation and Jacobians.

  • inverse (Transform or callable, optional) – The inverse transform (parameter-free transforms only).

  • name (str, optional) – Human-readable name.

__init__(fn: Callable, params: Sequence[Parameter] = (), *, contextual: bool = False, derivative: Callable | None = None, inverse=None, name: str | None = None)[source]#

Methods

__init__(fn[, params, contextual, ...])

derivative(a, *values[, context])

Elementwise derivative \(\partial fn/\partial a\) at a.

Attributes

inverse

The inverse transform, or None if unknown.

is_identity

Whether this is the module-level identity singleton.

n_params

property n_params: int#
property is_identity: bool#

Whether this is the module-level identity singleton.

An object-identity test, not a semantic one: Transform(lambda a: a) or log | exp are not recognised and take no identity fast path.

property inverse: Transform | None#

The inverse transform, or None if unknown.

Only meaningful for parameter-free transforms (a parametric inverse would need the same values, which are not carried along).

derivative(a, *values, context=None)[source]#

Elementwise derivative \(\partial fn/\partial a\) at a.

Falls back to a central finite difference when no analytic derivative was supplied.