rxmc.covariance.Term#
- class rxmc.covariance.Term(fn, params=(), *, kind='matrix', support=None, coords=None, constant=False)[source]#
Bases:
objectOne additive contribution to the stacked covariance.
- Parameters:
fn (callable or array_like) –
fn(c, *values) -> np.ndarraywithcaTermContextandvaluesthe sampled values ofparams(in order). A plain array is a fixed contribution (constant=Trueimplied): a standard-deviation vector forkind="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 aConstraintCovariance.coords (Transform or callable, optional) – Coordinate transform applied to
x[support]beforefnsees it (e.g. angle to momentum transfer). Its parameters, if any, are appended toparams.constant (bool, optional) – Declare that a callable
fndoes not readc.ym(the model prediction) and has no parameters, so the contribution can be evaluated once and cached.c.xandc.yare invariant per constraint and may be read freely (e.g. a fixed-hyperparameter kernel overx). A constant term is first evaluated withc.ym is None, so a mis-declared term fails loudly. Ignored (True) for arrayfn.
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’sxnever changes. Build a fresh Term per constraint; only masked views of one constraint (which stack the same observations) may share Terms.Methods
__init__(fn[, params, kind, support, ...])add_to(Sigma, ctx, theta)Add this term's contribution to the stacked
Sigmain place.bind(N)Resolve
support=Noneto the whole stack of lengthN.local_context(ctx[, theta])The
TermContextthis term sees attheta.value(ctx[, theta])The raw array
fnreturns (std vector, mode vector, or block).Attributes
Whether the term can write off-diagonal entries (
kind != "diag").- property couples_offdiagonal: bool#
Whether the term can write off-diagonal entries (
kind != "diag").
- bind(N: int) None[source]#
Resolve
support=Noneto the whole stack of lengthN.Idempotent for the same
N; a term constructed with an explicit support is untouched. Re-binding to a differentNraises: one Term belongs to one constraint (masked views of that constraint share its stack, seerxmc.constraint.Constraint.masked()).
- local_context(ctx: StackContext, theta=()) TermContext[source]#
The
TermContextthis term sees attheta.
- value(ctx: StackContext, theta=()) ndarray[source]#
The raw array
fnreturns (std vector, mode vector, or block).
- add_to(Sigma: ndarray, ctx: StackContext, theta) None[source]#
Add this term’s contribution to the stacked
Sigmain place.