MatrixWeighting¶
-
class
odl.space.weighting.
MatrixWeighting
(matrix, impl, exponent=2.0, **kwargs)[source]¶ Bases:
odl.space.weighting.Weighting
Weighting of a space by a matrix.
The exact definition of the weighted inner product, norm and distance functions depend on the concrete space.
The matrix must be Hermitian and posivive definite, otherwise it does not define an inner product or norm, respectively. This is not checked during initialization.
- Attributes
Methods
dist
(self, x1, x2)Calculate the distance between two elements.
equiv
(self, other)Test if other is an equivalent weighting.
inner
(self, x1, x2)Return the inner product of two elements.
is_valid
(self)Test if the matrix is positive definite Hermitian.
matrix_decomp
(self[, cache])Compute a Hermitian eigenbasis decomposition of the matrix.
norm
(self, x)Calculate the norm of an element.
-
__init__
(self, matrix, impl, exponent=2.0, \*\*kwargs)[source]¶ Initialize a new instance.
- Parameters
- matrix
scipy.sparse.spmatrix
or 2-dim.array-like
Square weighting matrix of the inner product
- implstring
Specifier for the implementation backend
- exponentpositive float, optional
Exponent of the norm. For values other than 2.0, the inner product is not defined. If
matrix
is a sparse matrix, only 1.0, 2.0 andinf
are allowed.- precomp_mat_powbool, optional
If
True
, precompute the matrix powerW ** (1/p)
during initialization. This has no effect ifexponent
is 1.0, 2.0 orinf
.Default:
False
- cache_mat_powbool, optional
If
True
, cache the matrix powerW ** (1/p)
. This can happen either during initialization or in the first call tonorm
ordist
, resp. This has no effect ifexponent
is 1.0, 2.0 orinf
.Default:
True
- cache_mat_decompbool, optional
If
True
, cache the eigenbasis decomposition of the matrix. This can happen either during initialization or in the first call tonorm
ordist
, resp. This has no effect ifexponent
is 1.0, 2.0 orinf
.Default:
False
- matrix
Notes
The matrix power
W ** (1/p)
is computed by eigenbasis decomposition:eigval, eigvec = scipy.linalg.eigh(matrix) mat_pow = (eigval ** p * eigvec).dot(eigvec.conj().T)
Depending on the matrix size, this can be rather expensive.