mrpro.operators.functionals.L1NormViewAsReal

class mrpro.operators.functionals.L1NormViewAsReal[source]

Bases: ElementaryProximableFunctional

Functional class for the L1 Norm, where C is identified with \(R^2\).

This implements the functional given by \(f: C^N \rightarrow [0, \infty), x \rightarrow \|W_r * \mathrm{Re}(x-b))\|_1 +\|( W_i *\mathrm{Im}(x-b))\|_1\), where \(W_r\) and \(W_i\) are a either scalars or tensors and * denotes element-wise multiplication.

If the parameter weight is real-valued, \(W_r\) and \(W_i\) are both set to weight. If it is complex-valued, \(W_r\) and \(W_I\) are set to the real and imaginary part, respectively.

In most cases, consider setting divide_by_n to true to be independent of input size.

The norm of the vector is computed along the dimensions set at initialization.

__init__(target: Tensor | None | complex = None, weight: Tensor | complex = 1.0, dim: int | Sequence[int] | None = None, divide_by_n: bool = False, keepdim: bool = False) None[source]

Initialize a Functional.

We assume that functionals are given in the form \(f(x) = \phi ( \mathrm{weight} ( x - \mathrm{target}))\) for some functional \(\phi\).

Parameters:
  • target (Tensor | None | complex, default: None) – target element - often data tensor (see above)

  • weight (Tensor | complex, default: 1.0) – weight parameter (see above)

  • dim (int | Sequence[int] | None, default: None) – dimension(s) over which functional is reduced. All other dimensions of weight ( x - target) will be treated as batch dimensions.

  • divide_by_n (bool, default: False) – if true, the result is scaled by the number of elements of the dimensions index by dim in the tensor weight ( x - target). If true, the functional is thus calculated as the mean, else the sum.

  • keepdim (bool, default: False) – if true, the dimension(s) of the input indexed by dim are maintained and collapsed to singeltons, else they are removed from the result.

__call__(x: Tensor) tuple[Tensor][source]

Compute the L1 norm, viewing complex numbers as R^2.

Calculates \(\|W_r * \mathrm{Re}(x-b)\|_1 + \|W_i * \mathrm{Im}(x-b)\|_1\). If weight is real, \(W_r = W_i = \mathrm{weight}\). If weight is complex, \(W_r = \mathrm{Re}(\mathrm{weight})\) and \(W_i=\mathrm{Im}(\mathrm{weight})\). b is target. The norm is computed along dim. If divide_by_n is True, the result is averaged; otherwise, summed.

Parameters:

x (Tensor) – Input tensor.

Returns:

The L1 norm. If keepdim is True, the dimensions dim are retained with size 1; otherwise, they are reduced.

forward(x: Tensor) tuple[Tensor][source]

Apply forward of L1NormViewAsReal.

Note

Prefer calling the instance of the L1NormViewAsReal operator as operator(x) over directly calling this method. See this PyTorch discussion.

prox(x: Tensor, sigma: Tensor | float = 1.0) tuple[Tensor][source]

Proximal Mapping of the L1 Norm.

Apply the proximal mapping of the L1 norm with \(C\) identified as \(R^2\).

Parameters:
  • x (Tensor) – input tensor

  • sigma (Tensor | float, default: 1.0) – real valued positive scaling factor

Returns:

Proximal mapping applied to the input tensor

prox_convex_conj(x: Tensor, sigma: Tensor | float = 1.0) tuple[Tensor][source]

Apply proximal operator of convex conjugate of functional.

Yields \(\mathrm{prox}_{\sigma f^*}(x) = \mathrm{argmin}_{p} \sigma f^*(p) + 1/2 \|x-p\|_2^2\), where \(f^*\) denotes the convex conjugate of \(f\), given \(x\) and \(\sigma\).

Parameters:
  • x (Tensor) – input tensor

  • sigma (Tensor | float, default: 1.0) – scaling factor, must be positive

Returns:

Proximal operator of the convex conjugate applied to the input tensor

__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*x if 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)

__or__(other: ProximableFunctional) ProximableFunctionalSeparableSum[Tensor, Tensor][source]

Create a ProximableFunctionalSeparableSum object from two proximable functionals.

Parameters:

other (ProximableFunctional) – second functional to be summed

Returns:

ProximableFunctionalSeparableSum object

__radd__(other: Tensor | complex) Operator[Unpack[Tin], tuple[Unpack[Tin]]][source]

Operator right addition.

Returns lambda x: other*x + self(x)

__rmul__(scalar: Tensor | complex) ProximableFunctional[source]

Multiply functional with scalar.