mrpro.operators.SynthesisDictionaryOp

class mrpro.operators.SynthesisDictionaryOp

Bases: LinearOperator

Synthesis dictionary operator (coefficients -> patches).

Mathematically, this operator implements the multiplication of a synthesis dictionary (i.e. a collection of \(K\) sparsifying functions, so-called atoms, stored as matrix-columns) with a \(K\)-dimensional coefficient vector, i.e.:math:D s, where \(D \in V^{d \times K}\) with \(V \in \{\mathbb{R}, \mathbb{C}\}\) is the synthesis dictionary (typically with \(K \geq d\)) and \(s \in V^K\) is the coefficient vector.

This operator is intended for use with image patches. Therefore, the dictionary \(D\) is defined by its \(K\) sparsifying functions of shape \(d_1 \times d_2 \times \ldots\), with \(d := d_1 \cdot d_2 \cdot \ldots\). The operator performs the matrix-vector multiplication described above with respect to the dimensions specified by the parameter dim. To achieve this, both the dictionary and the input are reshaped accordingly.

For example, for a dictionary of shape (48, 8, 8), a set of coefficient vectors of shape (1000, 2, 160, 48) and dim=(-2, -1), the operator yields an output of shape (1000, 2, 160, 8, 8), where the last two dimensions correspond to the dimensions of the patches.

The adjoint (Hermitian) operator maps the patches to the coefficient vectors, i.e. it implements \(D^H x\).

__init__(dictionary: Tensor, dim: Sequence[int] | int) → None

Initialize Synthesis Dictionary Operator.

Parameters:
  • dictionary (Tensor) – Dictionary tensor to be applied to the coefficients. Shape e.g. (n_entries, d1, d0) for 2D patches or for 3D patches (n_entries, d3, d1, d0)

  • dim (Sequence[int] | int) – Dimensions of the patches. Their order has to match the order of the patch dimensions of dictionary.

property H: LinearOperator

Adjoint operator.

Obtains the adjoint of an instance of this operator as an AdjointLinearOperator, which itself is a an LinearOperator that can be applied to tensors.

Note: linear_operator.H.H == linear_operator

property gram: LinearOperator

Gram operator.

For a LinearOperator \(A\), the self-adjoint Gram operator is defined as \(A^H A\).

Note

This is the inherited default implementation.

__call__(x: Tensor) → tuple[Tensor]

Apply dictionary synthesis operation to input coefficients.

The selected dimensions of the input patches are rearranged and flattened before applying the dictionary.

Parameters:

x (Tensor) – Input tensor containing the coefficients.

Returns:

Patches

adjoint(x: Tensor) → tuple[Tensor]

Apply dictionary analysis operation to input patches.

The selected dimensions of the input patches are rearranged and flattened before applying the dictionary.

Parameters:

x (Tensor) – Input tensor containing the patches.

Returns:

Coefficients.

forward(c: Tensor) → tuple[Tensor]

Apply forward of SynthesisDictionaryOp.

Note

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

operator_norm(initial_value: Tensor, dim: Sequence[int] | None, max_iterations: int = 20, relative_tolerance: float = 1e-4, absolute_tolerance: float = 1e-5, callback: Callable[[Tensor], None] | None = None) → Tensor

Power iteration for computing the operator norm of the operator.

Parameters:
  • initial_value (Tensor) – initial value to start the iteration; must be element of the domain. if the initial value contains a zero-vector for one of the considered problems, the function throws an ValueError.

  • dim (Sequence[int] | None) –

    The dimensions of the tensors on which the operator operates. The choice of dim determines how the operator norm is inperpreted. For example, for a matrix-vector multiplication with a batched matrix tensor of shape (batch1, batch2, row, column) and a batched input tensor of shape (batch1, batch2, row):

    • If dim=None, the operator is considered as a block diagonal matrix with batch1*batch2 blocks and the result is a tensor containing a single norm value (shape (1, 1, 1)).

    • If dim=(-1), batch1*batch2 matrices are considered, and for each a separate operator norm is computed.

    • If dim=(-2,-1), batch1 matrices with batch2 blocks are considered, and for each matrix a separate operator norm is computed.

    Thus, the choice of dim determines implicitly determines the domain of the operator.

  • max_iterations (int, default: 20) – maximum number of iterations

  • relative_tolerance (float, default: 1e-4) – absolute tolerance for the change of the operator-norm at each iteration; if set to zero, the maximal number of iterations is the only stopping criterion used to stop the power iteration.

  • absolute_tolerance (float, default: 1e-5) – absolute tolerance for the change of the operator-norm at each iteration; if set to zero, the maximal number of iterations is the only stopping criterion used to stop the power iteration.

  • callback (Callable[[Tensor], None] | None, default: None) – user-provided function to be called at each iteration

Returns:

An estimaton of the operator norm. Shape corresponds to the shape of the input tensor initial_value with the dimensions specified in dim reduced to a single value. The pointwise multiplication of initial_value with the result of the operator norm will always be well-defined.

__add__(other: LinearOperator | Tensor | complex) → LinearOperator
__add__(other: Operator[Tensor, tuple[Tensor]]) → Operator[Tensor, tuple[Tensor]]

Operator addition.

Returns lambda x: self(x) + other(x) if other is a operator, lambda x: self(x) + other if other is a tensor

__matmul__(other: LinearOperator) → LinearOperator
__matmul__(other: Operator[Unpack[Tin2], tuple[Tensor]] | Operator[Unpack[Tin2], tuple[Tensor, ...]]) → Operator[Unpack[Tin2], tuple[Tensor]]

Operator composition.

Returns lambda x: self(other(x))

__mul__(other: Tensor | complex) → LinearOperator

Operator elementwise left multiplication with tensor/scalar.

Returns lambda x: self(x*other)

__or__(other: LinearOperator) → LinearOperatorMatrix

Horizontal stacking of two LinearOperators.

A|B is a LinearOperatorMatrix with two columns, with (A|B)(x1,x2) == A(x1) + B(x2). See mrpro.operators.LinearOperatorMatrix for more information.

__radd__(other: Tensor | complex) → LinearOperator

Operator addition.

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

__rmul__(other: Tensor | complex) → LinearOperator

Operator elementwise right multiplication with tensor/scalar.

Returns lambda x: other*self(x)