Skip to content

Simulators API

Exact signatures for acquisition schemes, compartments, mixtures, priors, and noise models. Read the simulator guide first, or open the component example.

Acquisition schemes

acquisition_scheme dataclass

acquisition_scheme(bvals: Array, bvecs: Array, delta: ArrayLike = (lambda: 0.0106)(), Delta: ArrayLike = (lambda: 0.0431)())

Bases: AcquisitionScheme

A class representing a diffusion MRI acquisition scheme.

This class encapsulates the parameters needed to define a diffusion MRI acquisition, including b-values, gradient directions, and timing parameters.

Attributes:

Name Type Description
bvals ArrayLike

Array of b-values in s/mm^2, representing the diffusion weighting.

bvecs ArrayLike

Array of 3D unit vectors representing gradient directions.

delta ArrayLike

Time between the start of the diffusion encoding and the first gradient pulse in seconds.

Delta ArrayLike

Time between the start of the diffusion encoding and the second gradient pulse in seconds.

bvals instance-attribute

bvals: Array

bvecs instance-attribute

bvecs: Array

delta class-attribute instance-attribute

delta: ArrayLike = field(default_factory=lambda: 0.0106)

Delta class-attribute instance-attribute

Delta: ArrayLike = field(default_factory=lambda: 0.0431)

qvals property

qvals: ArrayLike

Calculate the q-values for the acquisition scheme.

Returns:

Name Type Description
ArrayLike ArrayLike

Array of q-values in 1/mm, calculated from b-values and Delta.

tau property

tau: ArrayLike

Calculate the effective diffusion time tau.

Returns:

Name Type Description
ArrayLike ArrayLike

Array of effective diffusion times in seconds.

gradient_strengths property

gradient_strengths: ArrayLike

Calculate the gradient strengths required for the acquisition scheme.

Returns:

Name Type Description
ArrayLike ArrayLike

Array of gradient strengths in T/m.

from_gradient_strengths classmethod

from_gradient_strengths(gradient_strengths: ArrayLike, gradient_directions: ArrayLike, delta: ArrayLike, Delta: ArrayLike) -> acquisition_scheme

Create an acquisition scheme from gradient parameters.

Parameters:

Name Type Description Default
gradient_strengths ArrayLike

Gradient strengths in T/m (typically 0.003-0.008 T/m, can reach 0.03-0.1 T/m in animal scanners).

required
gradient_directions ArrayLike

Gradient directions as 3D unit vectors.

required
delta ArrayLike

Time between the start of the diffusion encoding and the first gradient pulse.

required
Delta ArrayLike

Time between the start of the diffusion encoding and the second gradient pulse.

required

Returns:

Name Type Description
acquisition_scheme acquisition_scheme

A new acquisition scheme instance.

Raises:

Type Description
AssertionError

If Delta is not greater than delta, or if gradient strengths and directions have mismatched shapes, or if gradient directions are not 3D unit vectors.

ssfp_acquisition_scheme dataclass

ssfp_acquisition_scheme(bvecs: Array, T1_raw: ArrayLike, T2_raw: ArrayLike, B1: ArrayLike, diffGradAmps_raw: ArrayLike, flipAngles_raw: ArrayLike = (lambda: 14.0)(), TRs: ArrayLike = (lambda: 0.021)(), diffGradDur: ArrayLike = (lambda: 0.01016)(), delta: ArrayLike = (lambda: 0.0106)(), Delta: ArrayLike = (lambda: 0.008)(), gyromag_ratio: ArrayLike = (lambda: 4258 * 2 * pi)())

Bases: AcquisitionScheme

Steady-State Free Precession (SSFP) acquisition description.

Parameters are stored in common MR units and converted as properties:

  • bvecs: diffusion gradient unit vectors.
  • TRs: repetition times [s].
  • flipAngles_raw: flip angles [deg] (property flipAngles yields radians).
  • diffGradAmps_raw: diffusion gradient amplitudes [T/m] (property diffGradAmps yields G/mm).
  • diffGradDur: diffusion gradient durations [s].
  • B1: transmit field scaling, unitless.
  • T1_raw / T2_raw: relaxation times [ms] (properties T1/T2 yield seconds).
  • delta / Delta: diffusion pulse duration and separation [s].

Derived quantities:

  • sa, ca: \(\sin(\alpha B_1)\), \(\cos(\alpha B_1)\) with \(\alpha\) in radians.
  • E1, E2: relaxation terms \(\exp(-\mathrm{TR}/T_1)\), \(\exp(-\mathrm{TR}/T_2)\).
  • qvals: \(q = \gamma \, G \, \delta\) [1/mm] using gyromag_ratio in rad/ms/mT.
  • bvals: \(b = q^2 \, 4\pi^2 \, \Delta\).

bvecs instance-attribute

bvecs: Array

T1_raw instance-attribute

T1_raw: ArrayLike

T2_raw instance-attribute

T2_raw: ArrayLike

B1 instance-attribute

B1: ArrayLike

diffGradAmps_raw instance-attribute

diffGradAmps_raw: ArrayLike

flipAngles_raw class-attribute instance-attribute

flipAngles_raw: ArrayLike = field(default_factory=lambda: 14.0)

TRs class-attribute instance-attribute

TRs: ArrayLike = field(default_factory=lambda: 0.021)

diffGradDur class-attribute instance-attribute

diffGradDur: ArrayLike = field(default_factory=lambda: 0.01016)

delta class-attribute instance-attribute

delta: ArrayLike = field(default_factory=lambda: 0.0106)

Delta class-attribute instance-attribute

Delta: ArrayLike = field(default_factory=lambda: 0.008)

gyromag_ratio class-attribute instance-attribute

gyromag_ratio: ArrayLike = field(default_factory=lambda: 4258 * 2 * jnp.pi)

T1 property

T1: ArrayLike

T1 converted to seconds.

T2 property

T2: ArrayLike

T2 converted to seconds.

diffGradAmps property

diffGradAmps: ArrayLike

Diffusion gradient amplitudes converted to G/mm.

flipAngles property

flipAngles: ArrayLike

Flip angles converted to radians.

sa property

sa: ArrayLike

sin(flip angle * B1) [unitless].

ca property

ca: ArrayLike

cos(flip angle * B1) [unitless].

E1 property

E1: ArrayLike

Longitudinal relaxation term E1 = exp(-TR/T1) [unitless].

E2 property

E2: ArrayLike

Transverse relaxation term E2 = exp(-TR/T2) [unitless].

logE1 property

logE1: ArrayLike

Logarithm of longitudinal relaxation: logE1 = -TR/T1 [unitless].

logE2 property

logE2: ArrayLike

Logarithm of transverse relaxation: logE2 = -TR/T2 [unitless].

qvals property

qvals: ArrayLike

Diffusion encoding q-values, q = γ·G·δ [1/mm].

γ in rad/(ms·mT), G in T/m (≡ mT/mm), δ in ms.

bvals property

bvals: ArrayLike

Effective b-values, b = - 1/D log(S_ssfp/S_ssfp)

Abstract simulator classes

Compartment

Bases: ABC

to_theta abstractmethod classmethod

to_theta(*kwargs) -> Array

Transforms the natural parameters to the optimization parameters which are assumed to be normally distributed.

to_params abstractmethod classmethod

to_params(theta: ArrayLike) -> Any

Transforms the optimization parameters to the natural parameters.

from_theta classmethod

from_theta(theta: ArrayLike, **kwargs) -> Compartment

Creates a compartment from the optimization parameters.

tree_flatten

tree_flatten() -> tuple

Flattens the compartment into a list of children and auxiliary data.

tree_unflatten classmethod

tree_unflatten(aux_data: Any, children: list) -> Compartment

Reconstructs the compartment from the list of children and auxiliary data.

SignalCompartment

Bases: Compartment

signal_fn classmethod

signal_fn(acq: acquisition_scheme, *args, **kwargs) -> ArrayLike

Computes the signal for the compartment.

log_signal_fn abstractmethod classmethod

log_signal_fn(acq: acquisition_scheme, *args, **kwargs) -> ArrayLike

Computes the log-signal for the compartment.

signal

signal(acq: acquisition_scheme, rng=None) -> ArrayLike

Simulates the signal for the compartment.

log_signal

log_signal(acq: acquisition_scheme, rng=None) -> ArrayLike

Simulates the log-signal for the compartment.

fit

fit(logS: ArrayLike, bvals: ArrayLike, bvecs: ArrayLike) -> Any

Fits the compartment to the signal deterministically.

to_fod

to_fod()

Converts the signal compartment to a fiber orientation distribution compartment.

NoiseCompartment

Bases: Compartment

noise abstractmethod

noise(signal, rng: key) -> ArrayLike

Simulates the noise for the compartment.

log_likelihood abstractmethod

log_likelihood(signal_pred, signal_obs) -> Array

signal_response_kernels

StickKernel

StickKernel(lam_par: float)

Bases: SignalKernel

theta_dim class-attribute instance-attribute

theta_dim: int = 1

lam_min class-attribute instance-attribute

lam_min: float = Stick.min_lam

lam_max class-attribute instance-attribute

lam_max: float = Stick.max_lam

lam_par instance-attribute

lam_par = lam_par

kernel_fn classmethod

kernel_fn(acq: acquisition_scheme, mu: ArrayLike, lam_par: float, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value.

to_theta classmethod

to_theta(lam_par: ArrayLike) -> ArrayLike

Convert the lambda value to the parameter space theta.

ZeppelinKernel

ZeppelinKernel(lam_perp: float, lam_par: float)

Bases: SignalKernel

theta_dim class-attribute instance-attribute

theta_dim: int = 2

lam_min class-attribute instance-attribute

lam_min: float = Zeppelin.min_lam

lam_max class-attribute instance-attribute

lam_max: float = Zeppelin.max_lam

lam_perp instance-attribute

lam_perp = lam_perp

lam_par instance-attribute

lam_par = lam_par

kernel_fn classmethod

kernel_fn(acq: acquisition_scheme, mu: ArrayLike, lam_perp: float, lam_par: float, rng=None) -> ArrayLike

Signal for the given b-values and b-vectors.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value.

to_theta classmethod

to_theta(lam_perp: float, lam_par: float) -> ArrayLike

Convert the lambda value to the parameter space theta.

NODDIKernel

NODDIKernel(fraction, lam_perp, lam_par)

Bases: SignalKernel

theta_dim class-attribute instance-attribute

theta_dim: int = 3

fraction instance-attribute

fraction = fraction

lam_perp instance-attribute

lam_perp = lam_perp

lam_par instance-attribute

lam_par = lam_par

kernel_fn classmethod

kernel_fn(acq: acquisition_scheme, mu: ArrayLike, fraction, lam_perp, lam_par, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value.

to_theta classmethod

to_theta(fraction, lam_perp, lam_par) -> ArrayLike

Convert the lambda value to the parameter space theta.

SimpleSANDIKernel

SimpleSANDIKernel(fraction_in, fraction_ec, lam_par_in, lam_perp_ex, lam_par_ex)

Bases: SignalKernel

theta_dim class-attribute instance-attribute

theta_dim: int = 5

fraction_in instance-attribute

fraction_in = fraction_in

fraction_ec instance-attribute

fraction_ec = fraction_ec

lam_par_in instance-attribute

lam_par_in = lam_par_in

lam_perp_ex instance-attribute

lam_perp_ex = lam_perp_ex

lam_par_ex instance-attribute

lam_par_ex = lam_par_ex

kernel_fn classmethod

kernel_fn(acq: acquisition_scheme, mu: ArrayLike, fraction_in, fraction_ec, lam_par_in, lam_perp_ex, lam_par_ex, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

to_theta classmethod

to_theta(fraction_in, fraction_ec, lam_par_in, lam_perp_ex, lam_par_ex) -> ArrayLike

MultiCompartment

MultiCompartment(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: SignalCompartment

Composable mixture of signal compartments with optional shared parameters.

A MultiCompartment turns a set of signal compartments :math:S_k(b, \mathbf{g}) and fractions :math:f_k into a single signal

.. math::

S(b, \mathbf{g}) = \sum_k f_k \; S_k(b, \mathbf{g})

Noise compartments can be added on top through noise_types. The class exposes to_theta / from_theta so priors over fractions, shared diffusivities and per-compartment parameters stay Gaussian in optimization space.

References

  • Stejskal & Tanner, 1965. Spin diffusion measurements: spin echoes in the presence of a time‐dependent field gradient.
  • Behrens et al., 2003. Characterization and propagation of uncertainty in diffusion-weighted MR imaging.

num_compartments classmethod

num_compartments()

get_all_params

get_all_params()

signal_fn classmethod

signal_fn(acq: acquisition_scheme, model_compartments, noise_compartments, model_fractions, model_mask, shared_parameter, rng=None)

to_theta classmethod

to_theta(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Local signal models

A selection of voxel-wise dMRI signal compartments is implemented below.

Isotropic compartments

Ball

Ball(lam: float)

Bases: SignalCompartment

Isotropic Gaussian diffusion (free water).

Signal follows the Stejskal–Tanner form

.. math:: S(b) = \exp(-b\,\lambda),

with scalar diffusivity :math:\lambda \in [0, 10^{-2}]\,\mathrm{mm}^2/\mathrm{s} (Stejskal & Tanner, 1965).

Initialize the Ball model with a lambda value.

theta_dim class-attribute instance-attribute

theta_dim: int = 1

lam_min class-attribute instance-attribute

lam_min: float = 0.0

lam_max class-attribute instance-attribute

lam_max: float = 0.01

lam instance-attribute

lam = lam

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, lam: float, rng=None) -> ArrayLike

Computes the log-signal for the ball compartment.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value.

to_theta classmethod

to_theta(lam: ArrayLike) -> Array

Convert the lambda value to the parameter space theta.

fit

fit(logS: ArrayLike, bvals: ArrayLike, bvecs: Array) -> tuple

Fit the Ball model to the log signal and b-values.

to_fod

to_fod()

StaticBall

StaticBall()

Bases: Ball

The StaticBall model is a Ball with a fixed lambda value. The lam parameter is shared from a global parameter state as a class attribute.

Initialize the StaticBall model. The lam parameter is a class attribute and not passed to the constructor.

theta_dim class-attribute instance-attribute

theta_dim: int = 0

lam class-attribute instance-attribute

lam: float = None

to_theta classmethod

to_theta() -> ArrayLike

Convert to the parameter space theta. Since there are no learnable parameters, return an empty array.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to parameters. Since there are no learnable parameters, return an empty tuple.

from_global_params classmethod

from_global_params(params: ArrayLike, idx: list[int]) -> StaticBall

Create a StaticBall from a global theta value.

Parameters

theta : ArrayLike The global parameter array idx : list[int] Indices in the global parameter array that correspond to this model's parameters

Returns

StaticBall A StaticBall instance with parameters extracted from the global theta

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, rng=None) -> ArrayLike

Computes the log-signal for the ball compartment.

MultiShellBall

MultiShellBall(lam: float, lam_std: float)

Bases: Ball

The MultiShellBall model is a Ball with multiple lambda values. The lam parameter is shared from a global parameter state as a class attribute.

Initialize the MultiShellBall model. The lam parameter is a class attribute and not passed to the constructor.

theta_dim class-attribute instance-attribute

theta_dim: int = 2

lam_std_min class-attribute instance-attribute

lam_std_min: float = 1e-07

lam_std_max class-attribute instance-attribute

lam_std_max: float = 0.01

lam instance-attribute

lam: float = lam

lam_std instance-attribute

lam_std: float = lam_std

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, lam: float, lam_std: float, rng=None) -> ArrayLike

Computes the log-signal for the ball compartment with uncertainty.

to_theta classmethod

to_theta(lam: float, lam_std: float) -> ArrayLike

Convert to the parameter space theta. Since there are no learnable parameters, return an empty array.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to parameters. Since there are no learnable parameters, return an empty tuple.

MultiShellStaticBall

MultiShellStaticBall()

Bases: MultiShellBall

The MultiShellBall model is a Ball with multiple lambda values. The lam parameter is shared from a global parameter state as a class attribute.

theta_dim class-attribute instance-attribute

theta_dim: int = 0

lam class-attribute instance-attribute

lam: float = None

lam_std class-attribute instance-attribute

lam_std: float = None

from_global_params classmethod

from_global_params(params: ArrayLike, idx: list[int]) -> StaticBall

Create a StaticBall from a global theta value.

Parameters

theta : ArrayLike The global parameter array idx : list[int] Indices in the global parameter array that correspond to this model's parameters

Returns

StaticBall A StaticBall instance with parameters extracted from the global theta

to_theta classmethod

to_theta() -> ArrayLike

Convert to the parameter space theta. Since there are no learnable parameters, return an empty array.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to parameters. Since there are no learnable parameters, return an empty tuple.

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, rng=None) -> ArrayLike

Computes the log-signal for the ball compartment.

SSFPBall

SSFPBall(lam: float)

Bases: SignalCompartment

The SSFPBall model is a Ball with a fixed lambda value. The lam parameter is shared from a global parameter state as a class attribute.

theta_dim class-attribute instance-attribute

theta_dim: int = 1

lam_min class-attribute instance-attribute

lam_min: float = 0.0

lam_max class-attribute instance-attribute

lam_max: float = 0.01

lam instance-attribute

lam = lam

signal_fn classmethod

signal_fn(acq: ssfp_acquisition_scheme, lam: float, rng=None) -> ArrayLike

Computes the signal for the ball compartment.

log_signal_fn classmethod

log_signal_fn(acq: ssfp_acquisition_scheme, lam: float, rng=None) -> ArrayLike

Computes the log-signal for the ball compartment.

to_theta classmethod

to_theta(lam: float) -> ArrayLike

Convert to the parameter space theta. Since there are no learnable parameters, return an empty array.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to parameters. Since there are no learnable parameters, return an empty tuple.

SSFPStaticBall

SSFPStaticBall()

Bases: SSFPBall

The SSFPStaticBall model is a SSFPBall with a fixed lambda value. The lam parameter is shared from a global parameter state as a class attribute.

theta_dim class-attribute instance-attribute

theta_dim: int = 0

lam class-attribute instance-attribute

lam: float = None

from_global_params classmethod

from_global_params(params: ArrayLike, idx: list[int]) -> StaticBall

Create a StaticBall from a global theta value.

to_theta classmethod

to_theta() -> ArrayLike

Convert to the parameter space theta. Since there are no learnable parameters, return an empty array.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to parameters. Since there are no learnable parameters, return an empty tuple.

signal_fn classmethod

signal_fn(acq: ssfp_acquisition_scheme, rng=None) -> ArrayLike

Computes the signal for the ball compartment.

log_signal_fn classmethod

log_signal_fn(acq: ssfp_acquisition_scheme, rng=None) -> ArrayLike

Computes the log-signal for the ball compartment.

Sphere

Sphere(radius: float)

Bases: SignalCompartment

The Stejskal Tanner signal approximation of a sphere model. It assumes that pulse length is infinitessimally small and diffusion time large enough so that the diffusion is completely restricted. Only depends on q-value.

Parameters

diameter : float, sphere diameter in meters.

References

.. [1] Balinov, Balin, et al. "The NMR self-diffusion method applied to restricted diffusion. Simulation of echo attenuation from molecules in spheres and between planes." Journal of Magnetic Resonance, Series A 104.1 (1993): 17-25.

theta_dim class-attribute instance-attribute

theta_dim = 1

radius_mean class-attribute instance-attribute

radius_mean = math.log(0.01)

radius_scale class-attribute instance-attribute

radius_scale = 0.5

radius instance-attribute

radius = radius

log_signal_fn classmethod

log_signal_fn(acq, radius: float, rng=None)

to_theta classmethod

to_theta(radius: float) -> ArrayLike

Convert the sphere radius to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the sphere radius.

Anisotropic compartments

Zeppelin

Zeppelin(mu: ArrayLike, lambda_par: float, lambda_perp: float)

Bases: SignalCompartment

Axially symmetric Gaussian tensor (:math:\lambda_{\parallel}, \lambda_{\perp}).

Signal:

.. math:: S(b, \mathbf{g}) = \exp\Big(-b \big[\lambda_{\perp} + (\lambda_{\parallel}-\lambda_{\perp})(\mathbf{g}\cdot\boldsymbol{\mu})^2\big]\Big),

often used for extra-axonal water (Basser et al., 1994).

Initialize the Zeppelin model with orientation and diffusivity parameters.

theta_dim class-attribute instance-attribute

theta_dim = 4

min_lam class-attribute instance-attribute

min_lam = 0.0

max_lam class-attribute instance-attribute

max_lam = 0.01

mu instance-attribute

mu = mu

lambda_par instance-attribute

lambda_par = lambda_par

lambda_perp instance-attribute

lambda_perp = lambda_perp

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, lambda_par: float, lambda_perp: float, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

to_theta classmethod

to_theta(mu: ArrayLike, lambda_par: float, lambda_perp: float) -> ArrayLike

Convert the parameters to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the model parameters.

fit

fit(logS: ArrayLike, acq) -> tuple

Fit the Zeppelin model to the log signal, b-values, and b-vectors.

to_fod

to_fod()

StaticZeppelin

StaticZeppelin(mu: ArrayLike)

Bases: Zeppelin

The StaticZeppelin model is a Zeppelin with a fixed lambda value.

theta_dim class-attribute instance-attribute

theta_dim: int = 3

lambda_par class-attribute instance-attribute

lambda_par: float = None

lambda_perp class-attribute instance-attribute

lambda_perp: float = None

mu instance-attribute

mu = mu

to_theta classmethod

to_theta(mu: ArrayLike) -> ArrayLike

Convert the parameters to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Cylinder

Cylinder(mu: ArrayLike, lam_par: float, radius: float)

Bases: SignalCompartment

The Stejskal-Tanner approximation of a finite-radius cylinder (Callaghan, 1991). Assumes rectangular pulses and :math:\Delta \gg \delta.

NOTE: This model assumes that the gradient pulses are rectangular and that the diffusion time is much larger than the pulse duration and available in the acquisition scheme.

theta_dim class-attribute instance-attribute

theta_dim = 4

lam_par_max class-attribute instance-attribute

lam_par_max: float = 0.01

radius_mean class-attribute instance-attribute

radius_mean = math.log(0.01)

radius_scale class-attribute instance-attribute

radius_scale = 0.5

mu instance-attribute

mu = mu

lam_par instance-attribute

lam_par = lam_par

radius instance-attribute

radius = radius

log_signal_fn classmethod

log_signal_fn(acq, mu: ArrayLike, lam_par: float, radius: float, rng=None)

Compute the log signal attenuation.

to_theta classmethod

to_theta(mu: ArrayLike, lam_par: float, radius: float) -> ArrayLike

Convert parameters to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the model parameters.

WatsonZeppelin

WatsonZeppelin(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Watson distribution with zeppelin kernel.

fod_type class-attribute instance-attribute

fod_type = Watson

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = ZeppelinKernel

BinghamZeppelin

BinghamZeppelin(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Bingham distribution with zeppelin kernel.

fod_type class-attribute instance-attribute

fod_type = Bingham

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = ZeppelinKernel

Stick

Stick(mu: ArrayLike, lam_par: float)

Bases: SignalCompartment

Zero-radius cylinder aligned with unit vector :math:\boldsymbol{\mu}.

Signal:

.. math:: S(b, \mathbf{g}) = \exp\big(-b\,\lambda_{\parallel} (\mathbf{g}\cdot\boldsymbol{\mu})^2\big),

capturing fully anisotropic diffusion along the fiber (Behrens et al., 2003).

Initialize the Stick model with a lambda value and eigenvector.

theta_dim class-attribute instance-attribute

theta_dim = 3

min_lam class-attribute instance-attribute

min_lam = 0.0

max_lam class-attribute instance-attribute

max_lam = 0.01

mu instance-attribute

mu = mu

lam_par instance-attribute

lam_par = lam_par

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, lam_par: float, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

to_theta classmethod

to_theta(mu: ArrayLike, lam_par: float) -> ArrayLike

Convert the parameters to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value and eigenvector.

to_fod

to_fod()

fit

fit(logS: ArrayLike, acq: acquisition_scheme) -> tuple

Fit the Stick model to the log signal, b-values, and b-vectors.

StaticStick

StaticStick(mu: ArrayLike)

Bases: Stick

The StaticStick model is a Stick with a fixed lambda value. The lam_par parameter is shared from a global parameter state as a class attribute, while the mu parameter remains learnable.

Initialize the StaticStick model with a mu value. The lam_par parameter is a class attribute and not passed to the constructor.

theta_dim class-attribute instance-attribute

theta_dim: int = 2

lam_par class-attribute instance-attribute

lam_par: float = None

mu instance-attribute

mu = mu

to_theta classmethod

to_theta(mu: ArrayLike) -> ArrayLike

Convert only the mu parameter to the parameter space theta. The lam_par parameter is a class attribute and not included in theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the mu value. The lam_par parameter is a class attribute and not included in theta.

from_global_params classmethod

from_global_params(params: ArrayLike, idx: list[int]) -> type

Create a StaticStick from a global theta value.

Parameters

theta : ArrayLike The global parameter array idx : list[int] Indices in the global parameter array that correspond to this model's parameters

Returns

StaticStick A StaticStick instance with parameters extracted from the global theta

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

Parameters

acq : acquisition_scheme The acquisition scheme containing b-values and b-vectors mu : ArrayLike The orientation of the stick in spherical coordinates rng : jax.random.key, optional Random number generator key, by default None

Returns

ArrayLike The log signal

MultiShellStick

MultiShellStick(mu: ArrayLike, lam_par: float, lam_par_std: float)

Bases: Stick

The MultiShellStick model is a Stick with a fixed lambda value. The lam_par parameter is shared from a global parameter state as a class attribute, while the mu parameter remains learnable.

Initialize the MultiShellStick model with a mu value, lam_par, and lam_par_std.

theta_dim class-attribute instance-attribute

theta_dim: int = 4

lam_par_std_min class-attribute instance-attribute

lam_par_std_min: float = 0.0

lam_par_std_max class-attribute instance-attribute

lam_par_std_max: float = 0.005

mu instance-attribute

mu = mu

lam_par instance-attribute

lam_par: float = lam_par

lam_par_std instance-attribute

lam_par_std: float = lam_par_std

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, lam_par: float, lam_par_std: float, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

Parameters

acq : acquisition_scheme The acquisition scheme containing b-values and b-vectors

to_theta classmethod

to_theta(mu: ArrayLike, lam_par: float, lam_par_std: float) -> ArrayLike

Convert the parameters to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value and eigenvector.

MultiShellStaticStick

MultiShellStaticStick(mu: ArrayLike)

Bases: MultiShellStick

The MultiShellStaticStick model is a Stick with a fixed lambda value. The lam_par parameter is shared from a global parameter state as a class attribute, while the mu parameter remains learnable.

Initialize the MultiShellStaticStick model with a mu value.

theta_dim class-attribute instance-attribute

theta_dim: int = 2

lam_par class-attribute instance-attribute

lam_par: float = None

lam_par_std class-attribute instance-attribute

lam_par_std: float = None

mu instance-attribute

mu = mu

to_theta classmethod

to_theta(mu: ArrayLike) -> ArrayLike

Convert only the mu parameter to the parameter space theta. The lam_par parameter is a class attribute and not included in theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the mu value. The lam_par parameter is a class attribute and not included in theta.

from_global_params classmethod

from_global_params(params: ArrayLike, idx: list[int]) -> type

Create a MultiShellStaticStick from a global theta value.

Parameters

theta : ArrayLike The global parameter array idx : list[int] Indices in the global parameter array that correspond to this model's parameters

Returns

MultiShellStaticStick A MultiShellStaticStick instance with parameters extracted from the global theta

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

Parameters

acq : acquisition_scheme The acquisition scheme containing b-values and b-vectors mu : ArrayLike The orientation of the stick in spherical coordinates rng : jax.random.key, optional Random number generator key, by default None

Returns

ArrayLike The log signal

SSFPStick

SSFPStick(mu: ArrayLike, lam_par: float)

Bases: Stick

The SSFPStick model is a Stick with a fixed lambda value. The lam_par parameter is shared from a global parameter state as a class attribute, while the mu parameter remains learnable.

theta_dim class-attribute instance-attribute

theta_dim: int = 3

lam_min class-attribute instance-attribute

lam_min: float = 0.0

lam_max class-attribute instance-attribute

lam_max: float = 0.01

mu instance-attribute

mu = mu

lam_par instance-attribute

lam_par: float = lam_par

signal_fn classmethod

signal_fn(acq: acquisition_scheme, mu: ArrayLike, lam_par: float, rng=None) -> ArrayLike

Compute the signal for given b-values and b-vectors.

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, lam_par: float, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

SSFPStaticStick

SSFPStaticStick(mu: ArrayLike)

Bases: SSFPStick

The SSFPStaticStick model is a SSFPStick with a fixed lambda value. The lam_par parameter is shared from a global parameter state as a class attribute.

theta_dim class-attribute instance-attribute

theta_dim: int = 2

lam_par class-attribute instance-attribute

lam_par: float = None

mu instance-attribute

mu = mu

from_global_params classmethod

from_global_params(params: ArrayLike, idx: list[int]) -> type

Create a SSFPStaticStick from a global theta value.

to_theta classmethod

to_theta(mu: ArrayLike) -> ArrayLike

Convert only the mu parameter to the parameter space theta. The lam_par parameter is a class attribute and not included in theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the mu value. The lam_par parameter is a class attribute and not included in theta.

signal_fn classmethod

signal_fn(acq: acquisition_scheme, mu: ArrayLike, rng=None) -> ArrayLike

Compute the signal for given b-values and b-vectors.

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, mu: ArrayLike, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

WatsonStick

WatsonStick(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Watson distribution with stick kernel.

fod_type class-attribute instance-attribute

fod_type = Watson

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = StickKernel

BinghamStick

BinghamStick(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Bingham distribution with stick kernel.

fod_type class-attribute instance-attribute

fod_type = Bingham

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = StickKernel

Dot

Dot()

Bases: SignalCompartment

The Dot model is a simple model that represents a single point in space. It has no parameters and the signal is constant across all b-values and b-vectors. It represent trapped water molecules in the tissue.

theta_dim class-attribute instance-attribute

theta_dim: int = 0

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, rng=None) -> ArrayLike

Computes the log-signal for the dot compartment.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the lambda value.

to_theta classmethod

to_theta() -> ArrayLike

Convert the lambda value to the parameter space theta.

to_fod

to_fod()

Dti

Dti(D: ArrayLike)

Bases: SignalCompartment

The Diffusion Tensor Imaging (DTI) model represents the diffusion of water molecules in the brain. It is a simple model that assumes Gaussian diffusion.

Initialize the DTI model with a diffusion tensor D.

theta_dim class-attribute instance-attribute

theta_dim: int = 6

D_scale class-attribute instance-attribute

D_scale = 0.001

min_lam class-attribute instance-attribute

min_lam: float = 0.0001

D instance-attribute

D = D

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, D: ArrayLike, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

to_theta classmethod

to_theta(D: ArrayLike) -> ArrayLike

Convert the diffusion tensor D to the parameter space theta.

to_params classmethod

to_params(theta: ArrayLike) -> tuple

Convert the parameter space theta to the diffusion tensor D.

fit

fit(logS: ArrayLike, acq: acquisition_scheme) -> tuple

Fit the DTI model to the log signal, b-values, and b-vectors.

to_fod

to_fod()

Spherical convolution based simulators

These compartments convolve a kernel with a fiber orientation distribution (FOD) on the sphere. The shared base classes live in dmri.simulators.convolved_models.

convolved_models

HEMISPHERE_VERTICES module-attribute

HEMISPHERE_VERTICES = jnp.array(hemisphere_default.vertices)

SignalKernel

Bases: Compartment

vmap_on_sphere class-attribute instance-attribute

vmap_on_sphere: bool = False

kernel_fn abstractmethod classmethod

kernel_fn(mu: ArrayLike, acq: acquisition_scheme, **kwargs) -> Array

sh_coeff

sh_coeff(acq: acquisition_scheme, sh_order: int) -> ArrayLike

ConvolvedSignalCompartment

ConvolvedSignalCompartment(fod, signal_kernel)

Bases: SignalCompartment

fod_type instance-attribute

fod_type: type

signal_kernel_type instance-attribute

signal_kernel_type: type

default_eval_sh_order class-attribute instance-attribute

default_eval_sh_order: int = 14

fod instance-attribute

fod = fod

signal_kernel instance-attribute

signal_kernel = signal_kernel

__init_subclass__

__init_subclass__()

signal_fn classmethod

signal_fn(acq: acquisition_scheme, fod, signal_kernel, rng=None) -> ArrayLike

Compute the log signal for given b-values and b-vectors.

log_signal_fn classmethod

log_signal_fn(acq: acquisition_scheme, **kwargs)

to_theta classmethod

to_theta(fod, signal_kernel)

to_params classmethod

to_params(theta)

to_fod

to_fod()

NoddiW

NoddiW(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Watson distribution with NODDI kernel.

fod_type class-attribute instance-attribute

fod_type = Watson

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = NODDIKernel

NoddiB

NoddiB(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Bingham distribution with NODDI kernel.

fod_type class-attribute instance-attribute

fod_type = Bingham

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = NODDIKernel

SandiW

SandiW(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Watson distribution with SANDI kernel.

fod_type class-attribute instance-attribute

fod_type = Watson

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = SimpleSANDIKernel

SandiB

SandiB(fod, signal_kernel)

Bases: ConvolvedSignalCompartment

Bingham distribution with SANDI kernel.

fod_type class-attribute instance-attribute

fod_type = Bingham

signal_kernel_type class-attribute instance-attribute

signal_kernel_type = SimpleSANDIKernel

Spherical distributions

Orientation distributions (FODs, Watson, Bingham, ...) used by convolved compartments and as orientation priors.

sphereical_distributions

sphere_default module-attribute

sphere_default = get_sphere(name='symmetric724')

hemisphere_default module-attribute

hemisphere_default = HemiSphere(phi=sphere_default.phi, theta=sphere_default.theta)

big_sphere module-attribute

big_sphere = get_sphere(name='repulsion724')

bigger_hemisphere module-attribute

bigger_hemisphere = HemiSphere(phi=big_sphere.phi, theta=big_sphere.theta)

SphericalDistribution

Bases: Compartment

pdf abstractmethod

pdf(n)

sample abstractmethod

sample(key, shape)

sh_coeff

sh_coeff(sh_order=None, sphere=None, full_basis=False, **kwargs)

The Watson spherical distribution model in spherical harmonics. The minimum order is automatically derived from numerical experiments to ensure fast function executation and accurate results.

Parameters

sh_order : int, maximum spherical harmonics order to be used in the approximation.

Returns

watson_sh : array, spherical harmonics of Watson probability density.

viz

viz(plot_type='fod', sphere=None, n_samples=1000, ax=None, color=None, cmap=None, levels=3, alpha=None)

Visualize the spherical distribution model on the sphere.

Parameters

plot_type : str, optional Type of plot to generate. Options are: - "polar": Plot in polar coordinates (theta, phi) - "cartesian": Plot in Cartesian coordinates (x, y, z) - "fod": Plot as a fiber orientation distribution sphere : object, optional Sphere object for vertices (used in cartesian plot) n_samples : int, optional Number of samples to generate ax : matplotlib.axes.Axes, optional Matplotlib axis to plot on color : str, optional Colormap to use levels : int, optional Number of contour levels for polar plot alpha : float, optional Transparency of the surface for FOD plot

Returns

matplotlib.axes.Axes The matplotlib axis containing the plot

to_pmf

to_pmf(sphere=None, n_samples=1000)

Convert the continuous distribution to a discrete probability mass function.

Parameters

sphere : object, optional Sphere object for vertices n_samples : int, optional Number of samples to generate

Returns

tuple (vertices, probabilities) where vertices are the sphere points and probabilities are the corresponding PMF values

Uniform

Bases: SphericalDistribution

theta_dim class-attribute instance-attribute

theta_dim: int = 0

pdf

pdf(n)

sample

sample(key, shape)

to_theta classmethod

to_theta(mu, odi) -> ArrayLike

to_params classmethod

to_params(theta: ArrayLike) -> Any

SymmetricDirac

SymmetricDirac(mu)

Bases: SphericalDistribution

theta_dim class-attribute instance-attribute

theta_dim = 3

mu instance-attribute

mu = mu

pdf

pdf(n)

sample

sample(key, shape)

to_theta classmethod

to_theta(mu, odi) -> ArrayLike

to_params classmethod

to_params(theta: ArrayLike) -> Any

TensorFOD

TensorFOD(evecs, evals)

Bases: SphericalDistribution

evecs instance-attribute

evecs = evecs

evals instance-attribute

evals = evals

pdf

pdf(n)

sample

sample(key, shape)

to_theta classmethod

to_theta(evecs, evals) -> ArrayLike

to_params classmethod

to_params(theta: ArrayLike) -> Any

Tensor2dFOD

Tensor2dFOD(evecs, evals)

Bases: SphericalDistribution

evecs instance-attribute

evecs = evecs

evals instance-attribute

evals = evals

pdf

pdf(n)

sample

sample(key, shape)

to_theta classmethod

to_theta(evecs, evals) -> ArrayLike

to_params classmethod

to_params(theta: ArrayLike) -> Any

MixtureOfFODs

MixtureOfFODs(fractions, components)

Bases: SphericalDistribution

components instance-attribute

components = components

fractions instance-attribute

fractions = fractions

pdf

pdf(n)

sample

sample(key, shape)

to_theta classmethod

to_theta(fractions, components) -> ArrayLike

to_params classmethod

to_params(theta: ArrayLike) -> Any

Watson

Watson(mu, odi)

Bases: SphericalDistribution

The Watson spherical distribution model [1]_ [2]_.

Parameters

mu : array, shape(2), angles [theta, phi] representing main orientation on the sphere. theta is inclination of polar angle of main angle mu [0, pi]. phi is polar angle of main angle mu [-pi, pi]. kappa : float, concentration parameter of the Watson distribution.

References

.. [1] Kaden et al. "Parametric spherical deconvolution: inferring anatomical connectivity using diffusion MR imaging". NeuroImage (2007) .. [2] Zhang et al. "NODDI: practical in vivo neurite orientation dispersion and density imaging of the human brain". NeuroImage (2012)

theta_dim class-attribute instance-attribute

theta_dim = 3

odi_min class-attribute instance-attribute

odi_min = 0.02

odi_max class-attribute instance-attribute

odi_max = 0.99

mu instance-attribute

mu = mu

odi instance-attribute

odi = odi

pdf

pdf(n)

The Watson spherical distribution model [1, 2].

Parameters

n : array of shape(3) or array of shape(N x 3), sampled orientations of the Watson distribution.

Returns

Wn: float or array of shape(N), Probability density at orientations n, given mu and kappa.

sample

sample(key, shape)

Now defers to _sample_watson_distribution.

to_theta classmethod

to_theta(mu, odi) -> ArrayLike

Transforms the natural parameters to the optimization parameters which are assumed to be normally distributed.

to_params classmethod

to_params(theta: ArrayLike) -> Any

Transforms the optimization parameters to the natural parameters.

Bingham

Bingham(mu, odi, psi, beta_fraction)

Bases: SphericalDistribution

theta_dim class-attribute instance-attribute

theta_dim = 5

odi_min class-attribute instance-attribute

odi_min = 0.02

odi_max class-attribute instance-attribute

odi_max = 0.99

psi_min class-attribute instance-attribute

psi_min = 0.0

psi_max class-attribute instance-attribute

psi_max = np.pi

beta_fraction_min class-attribute instance-attribute

beta_fraction_min = 0.0

beta_fraction_max class-attribute instance-attribute

beta_fraction_max = 1.0

mu instance-attribute

mu = mu

odi instance-attribute

odi = odi

psi instance-attribute

psi = psi

beta_fraction instance-attribute

beta_fraction = beta_fraction

pdf

pdf(n)

sample

sample(key, shape)

to_params classmethod

to_params(theta)

to_theta classmethod

to_theta(mu, odi, psi, beta_fraction)

sample_watson_ar_1

sample_watson_ar_1(key, mu, kappa)

Draw a single sample from Watson(mu, kappa) on the unit sphere using acceptance-rejection from the uniform distribution on S^{d-1}.

Parameters:

Name Type Description Default
key

a jax.random.PRNGKey

required
mu

a jnp.ndarray of shape (d,) — will be normalized internally

required
kappa

a nonnegative float (concentration parameter)

required

Returns: A jnp.ndarray of shape (d,) lying on the unit sphere, distributed ~ Watson(mu,kappa).

diffusion_tensor2d_odf

diffusion_tensor2d_odf(dirs, evals, evecs)

Compute the ODF for a single diffusion tensor at directions dirs. Handles the degenerate case, where the last eigenvalue is 0, by restricting the evaluation to the plane spanned by the first two eigenvectors. For directions falling outside the plane, returns 0.

sample_single_from_odf_jax

sample_single_from_odf_jax(evals, evecs, rng)

Sample a single unit direction from the ODF defined by the diffusion tensor using naive rejection sampling in JAX, implemented with jax.lax.while_loop. Parameters


evals : array-like, shape (3,) Eigenvalues of the diffusion tensor (assumed positive). evecs : array-like, shape (3, 3) Eigenvectors of the diffusion tensor (columns = eigenvectors). rng : jax.random.PRNGKey Random key for JAX. max_iter : int, optional Maximum proposals for rejection sampling. Returns


direction : jnp.ndarray, shape (3,) A single sampled unit direction, or None (a Python object) if rejected in all attempts.

sample_single_from_odf_jax_degenerate

sample_single_from_odf_jax_degenerate(evals, evecs, rng, max_iter=10000)

Sample a direction from the ODF of a 'degenerate' diffusion tensor with eigenvalues [lambda1, lambda2, 0] using naive rejection sampling in the plane of nonzero diffusion. Parameters


evals : array-like of shape (3,) Eigenvalues of the diffusion tensor. We assume evals[2] == 0 and evals[0], evals[1] > 0 (ordered or not). evecs : array-like of shape (3,3) Eigenvectors (columns) of the diffusion tensor. evecs[:,2] is the direction corresponding to the zero eigenvalue. rng : jax.random.PRNGKey Random key for JAX. max_iter : int, optional Maximum proposals for rejection sampling in the plane. Returns


direction : jnp.ndarray of shape (3,) A sampled unit direction in the plane spanned by the two nonzero eigenvalues, or None (Python object) if rejected in all attempts.

diffusion_tensor_odf

diffusion_tensor_odf(dirs, evals, evecs)

Compute the ODF for a single diffusion tensor at directions dirs.

odi2kappa

odi2kappa(odi)

Calculates concentration (kappa) from orientation dispersion index (odi).

get_sh_order_from_odi

get_sh_order_from_odi(odi)

Returns minimum sh_order to estimate spherical harmonics for given odi.

inverse_sh_matrix cached

inverse_sh_matrix(sh_order, sphere=None, full_basis=False)

Returns the inverse of the spherical harmonics basis matrix.

deterministic_sphere_integration

deterministic_sphere_integration(kappa, beta, mu, mu_beta, n_theta=200, n_phi=200)

Use a 2D trapezoidal rule in spherical coords to approximate ∫ exp(kappa (n·mu)^2 + beta (n·mu_beta)^2 ) dΩ(n).

sample_sphere

sample_sphere(key, n_samples)

Generate n_samples random unit vectors on S^2 by sampling Normal(0,1) in 3D and normalizing. Returns shape (n_samples, 3).

sample_quad_exp_distribution

sample_quad_exp_distribution(key, kappa, beta, mu, mu_beta)

Predefined model collections

Ready-made MultiCompartment families mirroring common literature mixtures (Ball–Stick, Ball–3-Stick, multi-shell variants, ...).

models

Predefined multi-compartment model collections.

These convenience classes mirror common mixtures from the literature such as Ball–Stick (Behrens et al., 2003), Ball–Stick–Zeppelin, and multi-shell variants with shared diffusivity priors. Each class specifies the underlying MultiCompartment ingredients: signal compartments, noise compartments, and Dirichlet priors over fractions.

BallStickSharedDiffusivity

BallStickSharedDiffusivity(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [StaticBall, StaticStick]

noise_types class-attribute instance-attribute

noise_types = []

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(2)

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedDiffusivity

BallStickSharedDiffusivity2

BallStickSharedDiffusivity2(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [StaticBall, StaticStick]

noise_types class-attribute instance-attribute

noise_types = []

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(2)

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedDiffusivity

Ball3StickSharedDiffusivity

Ball3StickSharedDiffusivity(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.array([3.5, 1.0, 0.3, 0.1])

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedDiffusivity

Ball3StickSharedDiffusivityTotalParamPenalizedPrior

Ball3StickSharedDiffusivityTotalParamPenalizedPrior(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.array([3.5, 1.0, 0.3, 0.1])

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedDiffusivity

mask_prior_cls class-attribute instance-attribute

mask_prior_cls = TotalParamPenalizedPrior

SSFPBall3StickSharedDiffusivity

SSFPBall3StickSharedDiffusivity(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.array([3.5, 1.0, 0.3, 0.1])

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedSSFPDiffusivity

normalizing_fn staticmethod

normalizing_fn(acq, x: ArrayLike) -> ArrayLike

SSFPBall3StickSharedDiffusivityBetterNorm

SSFPBall3StickSharedDiffusivityBetterNorm(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.array([3.5, 1.0, 0.3, 0.1])

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedSSFPDiffusivity

pre_normalizing_fn staticmethod

pre_normalizing_fn(acq, x: ArrayLike) -> ArrayLike

Ball3StickSharedDiffusivityUniformFraction

Ball3StickSharedDiffusivityUniformFraction(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(4)

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedDiffusivity

MultiShellBall3StickSharedDiffusivity

MultiShellBall3StickSharedDiffusivity(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.array([3.5, 1.0, 0.3, 0.1])

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedMultiShellDiffusivity

MultiShellBall3StickSharedDiffusivityUniformFraction

MultiShellBall3StickSharedDiffusivityUniformFraction(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(4)

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedMultiShellDiffusivity

MultiShellBall3StickSharedDiffusivityGammaPrior

MultiShellBall3StickSharedDiffusivityGammaPrior(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

noise_types class-attribute instance-attribute

noise_types = [BoundedGaussianNoise]

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.array([3.5, 1.0, 0.3, 0.1])

shared_parameter_type class-attribute instance-attribute

shared_parameter_type = SharedMultiShellDiffusivityGammaPrior

BallStick

BallStick(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball, Stick]

noise_types class-attribute instance-attribute

noise_types = []

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(2)

Ball2Stick

Ball2Stick(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball, Stick, Stick]

noise_types class-attribute instance-attribute

noise_types = []

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(3)

Ball3Stick

Ball3Stick(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball, Stick, Stick, Stick]

noise_types class-attribute instance-attribute

noise_types = []

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(4)

Ball3StickNoise

Ball3StickNoise(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball, Stick, Stick, Stick]

noise_types class-attribute instance-attribute

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(4)

BallStickZeppelinNoise

BallStickZeppelinNoise(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball, Stick, Zeppelin]

noise_types class-attribute instance-attribute

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(3)

Ball2Stick2Zeppelin2Dti

Ball2Stick2Zeppelin2Dti(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball, Stick, Stick, Zeppelin, Zeppelin, Dti, Dti]

noise_types class-attribute instance-attribute

noise_types = []

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(7)

Ball3Stick3ZeppelinNoise

Ball3Stick3ZeppelinNoise(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball] + 3 * [Stick] + 3 * [Zeppelin]

noise_types class-attribute instance-attribute

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(1 + 3 + 3)

AllGaussianModels

AllGaussianModels(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball] + 3 * [Stick] + 3 * [Zeppelin] + 3 * [Dti]

noise_types class-attribute instance-attribute

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(1 + 3 + 3 + 3)

AllGaussianModelsParamCountPrior

AllGaussianModelsParamCountPrior(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball] + 3 * [Stick] + 3 * [Zeppelin] + 3 * [Dti]

noise_types class-attribute instance-attribute

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(1 + 3 + 3 + 3)

mask_prior_cls class-attribute instance-attribute

mask_prior_cls = TotalParamPenalizedPrior

AllGaussianAndConvolvedModels

AllGaussianAndConvolvedModels(model_fractions: ArrayLike, model_compartments: list, noise_compartments: list, model_mask: ArrayLike | None = None, shared_parameter: SharedParameterState | None = None)

Bases: MultiCompartment

model_types class-attribute instance-attribute

model_types = [Ball] + 3 * [Stick] + 3 * [Zeppelin] + 3 * [Dti] + [Dot] + [WatsonStick] + [WatsonZeppelin] + [BinghamStick] + [BinghamZeppelin] + [NoddiB] + [NoddiW] + [SandiB] + [SandiW]

noise_types class-attribute instance-attribute

fraction_prior class-attribute instance-attribute

fraction_prior = jnp.ones(1 + 3 + 3 + 3 + 9)

mask_prior_cls class-attribute instance-attribute

mask_prior_cls = TotalParamPenalizedPrior

Noise models

noise_compartments

Noise models for diffusion MRI signals.

Implements bounded Rician and Gaussian noise commonly observed in magnitude MR images. The likelihoods follow:

.. math:: p(z \mid \nu, \sigma) = \frac{z}{\sigma^2} \exp\Big(-\tfrac{z^2+\nu^2}{2\sigma^2}\Big) I_0\Big(\tfrac{z\nu}{\sigma^2}\Big)

with :math:I_0 the modified Bessel function (Gudbjartsson & Patz, 1995). SNR priors are kept in bounded ranges for numerical stability.

RicianNoise

RicianNoise(snr)

Bases: NoiseCompartment

theta_dim class-attribute instance-attribute

theta_dim = 1

snr instance-attribute

snr = snr

noise

noise(signal, rng)

log_likelihood

log_likelihood(signal_pred, signal_true)

to_theta classmethod

to_theta(snr: ArrayLike) -> ArrayLike

Transforms the natural parameters to the optimization parameters which are assumed to be normally distributed.

to_params classmethod

to_params(theta: ArrayLike) -> Any

Transforms the optimization parameters to the natural parameters.

GaussianNoise

GaussianNoise(snr)

Bases: NoiseCompartment

theta_dim class-attribute instance-attribute

theta_dim = 1

snr instance-attribute

snr = snr

noise

noise(signal, rng)

log_likelihood

log_likelihood(signal_pred, signal_true)

to_theta classmethod

to_theta(snr: ArrayLike) -> ArrayLike

Transforms the natural parameters to the optimization parameters which are assumed to be normally distributed.

to_params classmethod

to_params(theta: ArrayLike) -> Any

Transforms the optimization parameters to the natural parameters.

BoundedRicianNoise

BoundedRicianNoise(snr)

Bases: RicianNoise

theta_dim class-attribute instance-attribute

theta_dim = 1

min_snr class-attribute instance-attribute

min_snr = 3

max_snr class-attribute instance-attribute

max_snr = 80

snr instance-attribute

snr = snr

to_theta classmethod

to_theta(snr: ArrayLike) -> ArrayLike

Transforms the natural parameters to the optimization parameters which are assumed to be normally distributed.

to_params classmethod

to_params(theta: ArrayLike) -> Any

Transforms the optimization parameters to the natural parameters.

BoundedGaussianNoise

BoundedGaussianNoise(snr)

Bases: GaussianNoise

theta_dim class-attribute instance-attribute

theta_dim = 1

min_snr class-attribute instance-attribute

min_snr = 3

max_snr class-attribute instance-attribute

max_snr = 80

snr instance-attribute

snr = snr

to_theta classmethod

to_theta(snr: ArrayLike) -> ArrayLike

Transforms the natural parameters to the optimization parameters which are assumed to be normally distributed.

to_params classmethod

to_params(theta: ArrayLike) -> Any

Transforms the optimization parameters to the natural parameters.

RicianNoiseSNR7080

RicianNoiseSNR7080(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 70

max_snr class-attribute instance-attribute

max_snr = 80

RicianNoiseSNR6070

RicianNoiseSNR6070(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 60

max_snr class-attribute instance-attribute

max_snr = 70

RicianNoiseSNR5060

RicianNoiseSNR5060(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 50

max_snr class-attribute instance-attribute

max_snr = 60

RicianNoiseSNR4050

RicianNoiseSNR4050(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 40

max_snr class-attribute instance-attribute

max_snr = 50

RicianNoiseSNR3040

RicianNoiseSNR3040(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 30

max_snr class-attribute instance-attribute

max_snr = 40

RicianNoiseSNR2030

RicianNoiseSNR2030(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 20

max_snr class-attribute instance-attribute

max_snr = 30

RicianNoiseSNR1020

RicianNoiseSNR1020(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 10

max_snr class-attribute instance-attribute

max_snr = 20

RicianNoiseSNR310

RicianNoiseSNR310(snr)

Bases: BoundedRicianNoise

min_snr class-attribute instance-attribute

min_snr = 3

max_snr class-attribute instance-attribute

max_snr = 10

GaussianNoiseSNR7080

GaussianNoiseSNR7080(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 70

max_snr class-attribute instance-attribute

max_snr = 80

GaussianNoiseSNR6070

GaussianNoiseSNR6070(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 60

max_snr class-attribute instance-attribute

max_snr = 70

GaussianNoiseSNR5060

GaussianNoiseSNR5060(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 50

max_snr class-attribute instance-attribute

max_snr = 60

GaussianNoiseSNR4050

GaussianNoiseSNR4050(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 40

max_snr class-attribute instance-attribute

max_snr = 50

GaussianNoiseSNR3040

GaussianNoiseSNR3040(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 30

max_snr class-attribute instance-attribute

max_snr = 40

GaussianNoiseSNR2030

GaussianNoiseSNR2030(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 20

max_snr class-attribute instance-attribute

max_snr = 30

GaussianNoiseSNR1020

GaussianNoiseSNR1020(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 10

max_snr class-attribute instance-attribute

max_snr = 20

GaussianNoiseSNR310

GaussianNoiseSNR310(snr)

Bases: BoundedGaussianNoise

min_snr class-attribute instance-attribute

min_snr = 3

max_snr class-attribute instance-attribute

max_snr = 10

add_rician_noise

add_rician_noise(rng, signal, sigma_g)

Adds Rician noise to an MRI signal.

NOTE: The noise follows a Rician distribution when the signal-to-noise ratio (SNR) is moderate to high

Parameters: - signal: ndarray of the true signal magnitude (η) - sigma_g: standard deviation of the Gaussian noise (σ_g)

Returns: - noisy_signal: ndarray of the signal with added Rician noise

add_gaussian_noise

add_gaussian_noise(rng, signal, sigma_g)

Adds Gaussian noise to an MRI signal.

NOTE: Often used for simplicity, especially when modeling raw complex data or when SNR is high.

Parameters: - signal: ndarray of the true signal magnitude (η) - sigma_g: standard deviation of the Gaussian noise (σ_g)

Returns: - noisy_signal: ndarray of the signal with added Gaussian noise

add_noncentral_chi_noise

add_noncentral_chi_noise(rng, signal, sigma_g, num_coils)

Adds Non-Central Chi noise to an MRI signal.

Nature: Arises in multi-coil acquisition systems due to the combination of multiple complex signals.Characteristics: The noise distribution in the magnitude image follows a non-central Chi distribution. Degree of freedom depends on the number of coils used in parallel imaging. Implications: More complex than the Rician model and can complicate bias correction.

Parameters: - signal: ndarray of the true signal magnitude (η) - sigma_g: standard deviation of the Gaussian noise (σ_g) - num_coils: number of coils used in parallel imaging

Returns: - noisy_signal: ndarray of the signal with added Non-Central Chi noise

Mask priors

mask_prior

Priors over which compartments are active in a multi-compartment model.

Implements Beta–Bernoulli style mask priors with utilities to sample masks and convert them into boolean vectors that gate compartments during simulation.

MaskPriorSample dataclass

MaskPriorSample(hyperparameters: Array, model_mask: Array)

Container holding sampled hyperparameters and the resulting mask.

hyperparameters instance-attribute

hyperparameters: Array

model_mask instance-attribute

model_mask: Array

MaskPrior

MaskPrior(num_model_components: int, num_noise_components: int)

Base class for hierarchical priors over simulator model masks.

mask_prior_dim class-attribute instance-attribute

mask_prior_dim: int = 1

num_model_components instance-attribute

num_model_components = int(num_model_components)

num_noise_components instance-attribute

num_noise_components = int(num_noise_components)

sample

sample(rng: KeyArray) -> MaskPriorSample

Sample hyperparameters and a mask conditioned on them.

log_prob

log_prob(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

Return log probability of a binary mask conditioned on hyperparameters.

prob

prob(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

Return probability of a binary mask conditioned on hyperparameters.

sample_model_mask

sample_model_mask(rng: KeyArray, hyperparameters: ArrayLike) -> Array

Sample masks for model and noise components and concatenate them.

sample_noise_components

sample_noise_components(rng: KeyArray, hyperparameters: ArrayLike) -> Array

Default noise prior: exactly one active component (if any exist).

log_prob_noise_components

log_prob_noise_components(noise_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

sample_model_components

sample_model_components(rng: KeyArray, hyperparameters: ArrayLike) -> Array

Override to draw model-component masks.

sample_hyperparameters

sample_hyperparameters(rng: KeyArray) -> Array

Override to sample hyperparameters for the prior.

log_prob_model_components

log_prob_model_components(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

Override to evaluate log probability under the prior.

BetaBernoulliMaskPrior

BetaBernoulliMaskPrior(num_model_components: int, num_noise_components: int, alpha: float = 1.0, beta: float = 1.0, min_active_models: int = 1)

Bases: MaskPrior

Independent Bernoulli masks driven by a shared Beta hyper-prior.

mask_prior_dim class-attribute instance-attribute

mask_prior_dim: int = 1

alpha instance-attribute

alpha = float(alpha)

beta instance-attribute

beta = float(beta)

min_active_models instance-attribute

min_active_models = int(min_active_models)

sample_hyperparameters

sample_hyperparameters(rng: KeyArray) -> Array

sample_model_components

sample_model_components(rng: KeyArray, hyperparameters: ArrayLike) -> Array

log_prob_model_components

log_prob_model_components(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

BetaBernoulliParamCountScaledPrior

BetaBernoulliParamCountScaledPrior(num_model_components: int, num_noise_components: int, num_model_parameters: list[int], *, gamma: float = 1.0, kappa: float = 2.0, p_alpha: float = 1.0, p_beta: float = 1.0, eps: float = 0.001)

Bases: MaskPrior

Independent Bernoulli masks with per-component Dirichlet(2) (i.e., Beta) priors.

mask_prior_dim class-attribute instance-attribute

mask_prior_dim: int = 1

gamma instance-attribute

gamma = float(gamma)

kappa instance-attribute

kappa = float(kappa)

p_alpha instance-attribute

p_alpha = float(p_alpha)

p_beta instance-attribute

p_beta = float(p_beta)

sample_hyperparameters

sample_hyperparameters(rng: PRNGKey) -> Array

sample_model_components

sample_model_components(rng: KeyArray, hyperparameters: ArrayLike) -> Array

log_prob_model_components

log_prob_model_components(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

TotalParamPenalizedPrior

TotalParamPenalizedPrior(num_model_components: int, num_noise_components: int, num_model_parameters: list[int], *, p0: float = 0.5, u_alpha: float = 1.0, u_beta: float = 1.0, penalty_min: float = 0.0, penalty_max: float = 5.0, penalty_mode: str = 'linear', eps: float = 0.001)

Bases: MaskPrior

Global-complexity prior (scan) with fixed p0 and u∈[0,1] controlling penalty.

Conditionals
  • quadratic mode (default): logit P(z_i=1 | T) = logit(p0) - λ * (2*T*s_i + s_i**2) (global coupling via T; stricter as the model grows)

  • linear mode (AIC/BIC-like): logit P(z_i=1) = logit(p0) - λ * s_i (independent across components; fixed linear size penalty)

Hyperparameter
  • u ~ Beta(u_alpha, u_beta), or pass a fixed u in [0,1] when calling.
  • u=1 → no penalty (reverts to p0). u=0 → strongest penalty.
  • We map u to a desired worst-case logit drop delta* and set λ = delta* / scale_max, where scale_max depends on the mode:
    • quadratic: scale_max = max_i (2*S*s_i - s_i**2), S = sum_j s_j
    • linear: scale_max = max_i s_i

mask_prior_dim class-attribute instance-attribute

mask_prior_dim: int = 1

p0 instance-attribute

p0 = float(p0)

u_alpha instance-attribute

u_alpha = float(u_alpha)

u_beta instance-attribute

u_beta = float(u_beta)

penalty_min instance-attribute

penalty_min = float(penalty_min)

penalty_max instance-attribute

penalty_max = float(penalty_max)

penalty_mode instance-attribute

penalty_mode = penalty_mode

sample_hyperparameters

sample_hyperparameters(rng: KeyArray) -> Array

Sample u ~ Beta(u_alpha, u_beta). Caller may also pass a fixed u instead.

sample_model_components

sample_model_components(rng: PRNGKey, hyperparameters: ArrayLike) -> Array

log_prob_model_components

log_prob_model_components(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

MarkovMaskPrior

MarkovMaskPrior(num_model_components: int, num_noise_components: int, transition_matrix: ArrayLike, start_prob: ArrayLike | None = None, walk_length: int | None = None)

Bases: MaskPrior

Binary masks generated by a fixed-length Markov walk.

mask_prior_dim class-attribute instance-attribute

mask_prior_dim: int = 1

transition_logits instance-attribute

transition_logits = jnp.log(jnp.asarray(normalized_tm) + 1e-12)

start_logits instance-attribute

start_logits = jnp.log(jnp.asarray(start_prob) + 1e-12)

walk_length instance-attribute

walk_length = int(walk_length)

sample_hyperparameters

sample_hyperparameters(rng: KeyArray) -> Array

sample_model_components

sample_model_components(rng: KeyArray, hyperparameters: ArrayLike) -> Array

log_prob_model_components

log_prob_model_components(model_mask: ArrayLike, hyperparameters: ArrayLike) -> Array

Exact log-PMF of the visited set under a simple (no-revisit) Markov walk with length k = popcount(mask). Costs O(k^2 2^k).

sample_mask_and_prior

sample_mask_and_prior(mask_prior: MaskPrior, rng: PRNGKey) -> tuple[Array, Array]

Utility helper to sample (mask_prior, mask) pairs.