mrpro.operators.ConstraintsOp

class mrpro.operators.ConstraintsOp(bounds: Sequence[tuple[float | None, float | None]], beta_sigmoid: float = 1.0, beta_softplus: float = 1.0)[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 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 – beta parameter for the sigmoid transformation (used an input has two bounds). A higher value leads to a steeper sigmoid.

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

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

Transform tensors to chosen range.

Parameters:

x – tensors to be transformed

Return type:

tensors transformed to the range defined by the chosen bounds

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

Reverses the variable transformation.

Parameters:

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

Return type:

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.