mrpro.operators.EinsumOp
- class mrpro.operators.EinsumOp(matrix: Tensor, einsum_rule: str = '... i j, ... j -> ... i')[source]
Bases:
LinearOperator
A Linear Operator that implements sum products in Einstein notation.
Implements \(A_{indices_A}*x^{indices_x} = y_{indices_y}\) with Einstein summation rules over the indices, see torch.einsum or einops.einsum for more information. Note, that the indices must be space separated (einops convention).
It can be used to implement tensor contractions, such as for example, different versions of matrix-vector or matrix-matrix products of the form \(A @ x\), depending on the chosen einsum rules and shapes of \(A\) and \(x\).
Examples are:
matrix-vector multiplication of \(A\) and the batched vector \(x = [x1,...,xN]\) consisting of \(N\) vectors \(x1, x2, ..., xN\). Then, the operation defined by \(A @ x := diag(A, A, ..., A) * [x1, x2, ..., xN]^T = [A*x1, A*x2, ..., A*xN]^T\) can be implemented by the einsum rule
"i j, ... j -> ... i"
.matrix-vector multiplication of a matrix \(A\) consisting of \(N\) different matrices \(A1, A2, ... AN\) with one vector \(x\). Then, the operation defined by \(A @ x: = diag(A1, A2,..., AN) * [x, x, ..., x]^T\) can be implemented by the einsum rule
"... i j, j -> ... i"
.matrix-vector multiplication of a matrix \(A\) consisting of \(N\) different matrices \(A1, A2, ... AN\) with a vector \(x = [x1,...,xN]\) consisting of \(N\) vectors \(x1, x2, ..., xN\). Then, the operation defined by \(A @ x: = diag(A1, A2,..., AN) * [x1, x2, ..., xN]^T\) can be implemented by the einsum rule
"... i j, ... j -> ... i"
. This is the default behavior of the operator.
- __init__(matrix: Tensor, einsum_rule: str = '... i j, ... j -> ... i') None [source]
Initialize Einsum Operator.
- Parameters:
matrix – ‘Matrix’ \(A\) to be used as first factor in the sum product \(A*x\)
einsum_rule – Einstein summation rule describing the forward of the operator. Also see torch.einsum for more information.
- adjoint(y: Tensor) tuple[Tensor] [source]
Multiplication of input with the adjoint of A.
- Parameters:
y – tensor to be multiplied with hermitian/adjoint ‘matrix’ A
- Return type:
result of adjoint sum product
- forward(x: Tensor) tuple[Tensor] [source]
Sum-Multiplication of input x with A.
A and the rule used to perform the sum-product is set at initialization.
- Parameters:
x – input tensor to be multiplied with the ‘matrix’ A
- Return type:
result of matrix-vector multiplication
- operator_norm(initial_value: Tensor, dim: Sequence[int] | None, max_iterations: int = 20, relative_tolerance: float = 0.0001, absolute_tolerance: float = 1e-05, callback: Callable[[Tensor], None] | None = None) Tensor
Power iteration for computing the operator norm of the linear operator.
- Parameters:
initial_value – initial value to start the iteration; if the initial value contains a zero-vector for one of the considered problems, the function throws an value error.
dim – the dimensions of the tensors on which the operator operates. For example, for a matrix-vector multiplication example, a batched matrix tensor with shape (4,30,80,160), input tensors of shape (4,30,160) to be multiplied, and dim = None, it is understood that the matrix representation of the operator corresponds to a block diagonal operator (with 4*30 matrices) and thus the algorithm returns a tensor of shape (1,1,1) containing one single value. In contrast, if for example, dim=(-1,), the algorithm computes a batched operator norm and returns a tensor of shape (4,30,1) corresponding to the operator norms of the respective matrices in the diagonal of the block-diagonal operator (if considered in matrix representation). In any case, the output of the algorithm has the same number of dimensions as the elements of the domain of the considered operator (whose dimensionality is implicitly defined by choosing dim), such that the pointwise multiplication of the operator norm and elements of the domain (to be for example used in a Landweber iteration) is well-defined.
max_iterations – maximum number of iterations
relative_tolerance – 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 – 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 – user-provided function to be called at each iteration
- Return type:
an estimaton of the operator norm
- property H: LinearOperator
Adjoint operator.
- property gram: LinearOperator
Gram operator.
For a LinearOperator \(A\), the self-adjoint Gram operator is defined as \(A^H A\).
Note: This is a default implementation that can be overwritten by subclasses for more efficient implementations.