mbi.MarginalLossFn
- class mbi.MarginalLossFn(cliques: Sequence[tuple[str | int, ...]], loss_fn: Callable[[CliqueVector, Any], Array | ndarray | bool | number | bool | int | float | complex], data: Any = (), lipschitz: float = 1.0)[source]
Bases:
objectA loss function over the concatenated vector of marginals.
Separates the computation (
loss_fn, static) from the captured data (data, dynamic JAX pytree leaves). This allowsMarginalLossFnto be passed throughjax.jitas a regular traced argument rather than a static one, so that different measurement values with the same structure reuse the same compiled program.- cliques
Cliques defining the scope of the marginals.
- Type:
collections.abc.Sequence[tuple[str | int, …]]
- loss_fn
A pure function
(marginals, data) -> loss. This is treated as static metadata for JIT compilation.- Type:
collections.abc.Callable[[mbi.clique_vector.CliqueVector, Any], jax.Array | numpy.ndarray | numpy.bool | numpy.number | bool | int | float | complex]
- data
Arbitrary pytree of arrays captured by
loss_fn. This is traced through JIT and can change without recompilation.- Type:
Any
- lipschitz
Lipschitz constant of the gradient. Defaults to
1.0.- Type:
float
Methods
__init__Attributes
- cliques: Sequence[tuple[str | int, ...]]
- loss_fn: Callable[[CliqueVector, Any], Array | ndarray | bool | number | bool | int | float | complex]
- data: Any = ()
- lipschitz: float = 1.0
- __call__(marginals: CliqueVector) Array | ndarray | bool | number | bool | int | float | complex[source]
Call self as a function.