mr2.operators.functionals.RicianNegLogLikelihood
- class mr2.operators.functionals.RicianNegLogLikelihood[source]
Bases:
Operator[Tensor,tuple[Tensor]]Reduced Rician negative log likelihood for nonnegative amplitudes.
For predicted amplitude \(a\), observed magnitude \(y\) and noise standard deviation \(s\), with \(z=ay/s^2\), the per-observation objective is
\[\ell(a,y,s) = \frac{a^2+y^2}{2s^2} - \log I_0(ay/s^2) + 2\log s.\]This omits the data-only term \(-\log y\) from the full negative log density, allowing zero observations. Observation derivatives refer to this reduced objective: \(\partial_y\ell=(y-a I_1(z)/I_0(z))/s^2\), including its zero limit at \(y=0\). Amplitude derivatives likewise vanish at \(a=0\). The noise normalization is retained for fitting learnable noise. This likelihood is generally nonconvex.
Inputs must be finite, real, nonnegative amplitudes;
noise_stdmust be strictly positive. Float32 and float64 are supported. The caller must keep amplitudes in their physical domain; negative values evaluate the even mathematical extension of the loss. Values and derivatives are limited by the representable range of the chosen dtype. Ordinary PyTorch operations support double backward, Hessian-vector products andtorch.func.vmapsupports mapping amplitudes of an initialized operator; mapping constructor parameters is unsupported because validation checks tensor values.- __init__(target: Tensor | float, noise_std: Tensor | float, weight: Tensor | float = 1.0, dim: int | Sequence[int] | None = None, divide_by_n: bool = False, keepdim: bool = False) None[source]
Initialize the likelihood.
- Parameters:
target (
Tensor|float) – Finite, nonnegative observed magnitude, broadcastable with the input.noise_std (
Tensor|float) – Finite standard deviation of EACH real/imaginary Gaussian noise component (complex noise variance is twice its square). Strictly positive, broadcastable with the input; may require gradients. Pass a float64 tensor for float64 noise precision; Python floats use the default dtype. For repeated fitting, use a leaf tensor or atorch.nn.Parameter. To move learnable tensors with this operator, use Parameters and create the optimizer after moving it. Recompute derived noise tensors when rebuilding the likelihood for each fitting iteration.weight (
Tensor|float, default:1.0) – Finite, nonnegative likelihood weights, broadcastable with the observations. Multiplies the per-observation loss, rather than the residual.dim (
int|Sequence[int] |None, default:None) – Dimensions to reduce;Nonereduces all dimensions.divide_by_n (
bool, default:False) – Use the mean instead of the sum over the broadcast loss dimensions. The divisor counts elements, including zero weights.keepdim (
bool, default:False) – Retain reduced dimensions with size one.
- forward(x: Tensor) tuple[Tensor][source]
Return the weighted reduced likelihood for physical amplitude
x.Note
Prefer calling the instance as
operator(x)over directly calling this method. See this PyTorch discussion.
- __add__(other: Operator[Unpack[Tin], Tout]) Operator[Unpack[Tin], Tout][source]
- __add__(other: Tensor | complex) Operator[Unpack[Tin], tuple[Unpack[Tin]]]
Operator addition.
Returns
lambda x: self(x) + other(x)if other is a operator,lambda x: self(x) + other*xif other is a tensor
- __matmul__(other: Operator[Unpack[Tin2], tuple[Unpack[Tin]]] | Operator[Unpack[Tin2], tuple[Tensor, ...]]) Operator[Unpack[Tin2], Tout][source]
Operator composition.
Returns
lambda x: self(other(x))
- __mul__(other: Tensor | complex) Operator[Unpack[Tin], Tout][source]
Operator multiplication with tensor.
Returns
lambda x: self(x*other)