LinearModel#
- class cuqi.model.LinearModel(forward, adjoint=None, range_geometry=None, domain_geometry=None)#
Model based on a Linear forward operator.
- Parameters:
forward (2D ndarray or callable function.) – Forward operator.
adjoint (2D ndarray or callable function. (optional if matrix is passed as forward))
range_geometry (integer or cuqi.geometry.Geometry (optional)) – If integer is given, a cuqi.geometry._DefaultGeometry is created with dimension of the integer.
domain_geometry (integer or cuqi.geometry.Geometry (optional)) – If integer is given, a cuqi.geometry._DefaultGeometry is created with dimension of the integer.
- Variables:
range_geometry – The geometry representing the range.
domain_geometry – The geometry representing the domain.
Example
Consider a linear model represented by a matrix, i.e., \(y=Ax\) where \(A\) is a matrix.
We can define such a linear model by passing the matrix \(A\):
import numpy as np from cuqi.model import LinearModel A = np.random.randn(2,3) model = LinearModel(A)
The dimension of the range and domain geometries will be automatically inferred from the matrix \(A\).
Meanwhile, such a linear model can also be defined by a forward function and an adjoint function:
import numpy as np from cuqi.model import LinearModel A = np.random.randn(2,3) def forward(x): return A@x def adjoint(y): return A.T@y model = LinearModel(forward, adjoint=adjoint, range_geometry=2, domain_geometry=3)
Note that you would need to specify the range and domain geometries in this case as they cannot be inferred from the forward and adjoint functions.
- __init__(forward, adjoint=None, range_geometry=None, domain_geometry=None)#
Methods
__init__
(forward[, adjoint, range_geometry, ...])adjoint
(*args[, is_par])Adjoint of the model.
forward
(*args[, is_par])Forward function of the model.
Returns an ndarray with the matrix representing the forward operator.
gradient
(direction, *args[, ...])Gradient of the forward operator (Direction-Jacobian product)
Attributes
Transpose of linear model.
The dimension of the domain
The geometry representing the domain of the model.
The number of inputs of the model.
The dimension of the range
The geometry representing the range of the model.
The shift of the affine model.