mr2.operators.functionals.L21Norm

class mr2.operators.functionals.L21Norm[source]

Bases: ElementaryProximableFunctional

Sum or mean of Euclidean group norms of weight * (x - target).

This implements \(f(x) = \frac{1}{n}\sum_g |w_g|\|x_g-b_g\|_2\), where \(b\) is target, \(w_g\) is the scalar weight for group g, and n is the number of outer groups for a mean, or one for a sum.

The inner L2 norm groups components along group_dim. The outer sum (or mean) reduces the group norms along dim; remaining axes are batch axes. Only abs(weight) enters the functional. Forward evaluation supports broadcasting that expands the input. Proximal mappings require target and weight to broadcast without expanding the input shape.

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

Initialize the group norm.

Parameters:
  • target (Tensor | complex | None, default: None) – Target tensor, broadcast with the input and weight.

  • weight (Tensor | complex, default: 1.0) – Scalar per group, possibly negative or complex. Must have singleton sizes along group axes after right alignment to the broadcast shape.

  • dim (int | Sequence[int] | None, default: None) – Outer reduction axes in the broadcast input rank, disjoint from group_dim. None reduces all non-group axes; () performs no outer reduction. Negative axes are supported; duplicates and aliases fail.

  • divide_by_n (bool, default: False) – Average over outer groups instead of summing. Group components are never counted. Averaging over zero outer groups raises ValueError.

  • keepdim (bool, default: False) – Retain both group and outer reduction axes with size one. Otherwise remove both sets of axes. Proximal mappings always retain input axes.

  • group_dim (int | Sequence[int]) – Required nonempty axis or sequence of axes for each Euclidean group. All axes may be grouped, yielding a single Euclidean norm.

__call__(*args: Unpack[Tin]) → Tout[source]

Apply the operator by calling the forward method.

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

Compute the sum or mean of weighted group norms.

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

Shrink each group toward target by sigma * abs(weight) / n.

Here n counts outer groups for a mean, and is one for a sum. Sigma must be real, nonnegative and broadcastable with singleton group axes.

Parameters:
  • x (Tensor) – Input tensor. Target and weight must broadcast without expanding its shape.

  • sigma (Tensor | float, default: 1.0) – Nonnegative scaling factor, scalar per group.

Returns:

Proximal mapping applied to the input tensor, with the same shape.

Raises:

ValueError – If target or weight expands the input shape.

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

Project x - sigma * target onto balls of radius abs(weight) / n.

Sigma obeys the same restrictions as in prox. Zero steps return the input, including outside the conjugate domain. Zero weights project to zero for positive steps.

Parameters:
  • x (Tensor) – Input tensor. Target and weight must broadcast without expanding its shape.

  • sigma (Tensor | float, default: 1.0) – Nonnegative scaling factor, scalar per group.

Returns:

Proximal mapping of the convex conjugate, with the input shape.

Raises:

ValueError – If target or weight expands the input shape.

__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 from two proximable functionals.

f | g is a separable sum with (f|g)(x,y) == f(x) + g(y).

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.