rxmc.covariance.Term#

class rxmc.covariance.Term(fn, params=(), *, kind='matrix', support=None, coords=None, constant=False)[source]#

Bases: object

One additive contribution to the stacked covariance.

Parameters:
  • fn (callable or array_like) – fn(c, *values) -> np.ndarray with c a TermContext and values the sampled values of params (in order). A plain array is a fixed contribution (constant=True implied): a standard-deviation vector for kind="diag", a mode vector for "mode", or a symmetric block for "matrix".

  • params (sequence of Parameter, optional) – Parameters consumed by fn, matched by identity across terms (pass the same object to two terms to share one sampled value).

  • kind ({“diag”, “mode”, “matrix”}) – How the returned array enters the covariance (see module docstring).

  • support (array_like of int, optional) – Indices into the stacked vector. None (default) means the whole constraint; it is resolved when the term is added to a ConstraintCovariance.

  • coords (Transform or callable, optional) – Coordinate transform applied to x[support] before fn sees it (e.g. angle to momentum transfer). Its parameters, if any, are appended to params.

  • constant (bool, optional) – Declare that a callable fn does not read c.ym (the model prediction) and has no parameters, so the contribution can be evaluated once and cached. c.x and c.y are invariant per constraint and may be read freely (e.g. a fixed-hyperparameter kernel over x). A constant term is first evaluated with c.ym is None, so a mis-declared term fails loudly. Ignored (True) for array fn.

Notes

A Term is stateful: its support is bound once (see bind()) and constant or coordinate-transformed values are cached on the assumption that the constraint’s x never changes. Build a fresh Term per constraint; only masked views of one constraint (which stack the same observations) may share Terms.

__init__(fn, params=(), *, kind='matrix', support=None, coords=None, constant=False)[source]#

Methods

__init__(fn[, params, kind, support, ...])

add_to(Sigma, ctx, theta)

Add this term's contribution to the stacked Sigma in place.

bind(N)

Resolve support=None to the whole stack of length N.

local_context(ctx[, theta])

The TermContext this term sees at theta.

value(ctx[, theta])

The raw array fn returns (std vector, mode vector, or block).

Attributes

bound

couples_offdiagonal

Whether the term can write off-diagonal entries (kind != "diag").

property couples_offdiagonal: bool#

Whether the term can write off-diagonal entries (kind != "diag").

property bound: bool#
bind(N: int) → None[source]#

Resolve support=None to the whole stack of length N.

Idempotent for the same N; a term constructed with an explicit support is untouched. Re-binding to a different N raises: one Term belongs to one constraint (masked views of that constraint share its stack, see rxmc.constraint.Constraint.masked()).

local_context(ctx: StackContext, theta=()) → TermContext[source]#

The TermContext this term sees at theta.

value(ctx: StackContext, theta=()) → ndarray[source]#

The raw array fn returns (std vector, mode vector, or block).

add_to(Sigma: ndarray, ctx: StackContext, theta) → None[source]#

Add this term’s contribution to the stacked Sigma in place.