mrpro.operators.ConstraintsOp

class mrpro.operators.ConstraintsOp[source]

Bases: EndomorphOperator

Transformation to map real-valued tensors to certain ranges.

__init__(bounds: Sequence[tuple[float | None, float | None]], beta_sigmoid: float = 1.0, beta_softplus: float = 1.0) None[source]

Initialize a constraint operator.

The operator maps real-valued tensors to certain ranges. The transformation is applied element-wise. The transformation is defined by the bounds. The bounds are applied in the order of the input tensors. If there are more input tensors than bounds, the remaining tensors are passed through without transformation.

If an input tensor is bounded from below AND above, a sigmoid transformation is applied. If an input tensor is bounded from below OR above, a softplus transformation is applied.

Parameters:
  • bounds (Sequence[tuple[float | None, float | None]]) – Sequence of (lower_bound, upper_bound) values. If a bound is None, the value is not constrained. If a lower bound is -inf, the value is not constrained from below. If an upper bound is inf, the value is not constrained from above. If the bounds are set to (None, None) or (-inf, inf), the value is not constrained at all.

  • beta_sigmoid (float, default: 1.0) – beta parameter for the sigmoid transformation (used if an input has two bounds). A higher value leads to a steeper sigmoid.

  • beta_softplus (float, default: 1.0) – parameter for the softplus transformation (used if an input is either bounded from below or above). A higher value leads to a steeper softplus.

__call__(*x: Tensor) tuple[Tensor, ...][source]

Apply the EndomorphOperator.

forward(*x: Tensor) tuple[Tensor, ...][source]

Transform tensors to chosen range.

Parameters:

x (Tensor) – tensors to be transformed

Returns:

tensors transformed to the range defined by the chosen bounds

inverse(*x_constrained: Tensor) tuple[Tensor, ...][source]

Reverses the variable transformation.

Parameters:

x_constrained (Tensor) – transformed tensors with values in the range defined by the bounds

Returns:

tensors in the domain with no bounds

static sigmoid(x: Tensor, beta: float = 1.0) Tensor[source]

Constraint x to be in the range given by ‘bounds’.

static sigmoid_inverse(x: Tensor, beta: float = 1.0) Tensor[source]

Constraint x to be in the range given by ‘bounds’.

static softplus(x: Tensor, beta: float = 1.0) Tensor[source]

Constrain x to be in (bound,infty).

static softplus_inverse(x: Tensor, beta: float = 1.0) Tensor[source]

Inverse of softplus_transformation.

__add__(other: Operator[Unpack, Tout]) Operator[Unpack, Tout][source]
__add__(other: Tensor) Operator[Unpack, tuple[Unpack]]

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: EndomorphOperator) EndomorphOperator[source]
__matmul__(other: Operator[Unpack, Tout]) Operator[Unpack, Tout]

Operator composition.

__mul__(other: Tensor | complex) Operator[Unpack, Tout][source]

Operator multiplication with tensor.

Returns lambda x: self(x*other)

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

Operator right addition.

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

__rmatmul__(other: Operator[Unpack, Tout]) Operator[Unpack, Tout][source]

Operator composition.

__rmul__(other: Tensor | complex) Operator[Unpack, Tout][source]

Operator multiplication with tensor.

Returns lambda x: other*self(x)