KernelMatrix¶
- class itergp.linops.KernelMatrix(kernel, x0, x1=None, size_keops=1000)¶
Bases:
LinearOperatorKernel matrix.
Linear operator defining (matrix-)multiplication with a kernel matrix \(K=k(X_0,X_1) \in \mathbb{R}^{n_0 \times n_1}\), constructed from two sets of inputs \(X_i \in \mathbb{R}^{n_i \times d}\).
- Parameters
kernel (randprocs.kernels.Kernel) – Kernel.
x0 (backend.Array) – Inputs for the first argument of
kernel.x1 (Optional[backend.Array]) – Inputs for the second argument of
kernel.size_keops – At what size of the training data to use KeOps
LazyTensorinstead of full matrices in memory.
Attributes Summary
Data type of the linear operator.
Whether the
LinearOperatorrepresents a lower triangular matrix.Whether the
LinearOperator\(L \in \mathbb{R}^{n \times n}\) is (strictly) positive-definite, i.e. \(x^T L x > 0\) for \(x \in \mathbb{R}^n\).Whether input dimension matches output dimension.
Whether the
LinearOperator\(L\) is symmetric, i.e. \(L = L^T\).Whether the
LinearOperatorrepresents an upper triangular matrix.Covariance function of the kernel matrix.
Number of linear operator dimensions.
Shape of the linear operator.
First input(s).
Second input(s).
Methods Summary
__call__(x[, axis])Call self as a function.
astype(dtype[, order, casting, subok, copy])Cast a linear operator to a different
dtype.broadcast_matmat(matmat)Broadcasting for a (implicitly defined) matrix-matrix product.
broadcast_matvec(matvec)Broadcasting for a (implicitly defined) matrix-vector product.
broadcast_rmatmat(rmatmat)broadcast_rmatvec(rmatvec)cholesky([lower])Computes a Cholesky decomposition of the
LinearOperator.cond([p])Compute the condition number of the linear operator.
det()Determinant of the linear operator.
eigvals()Eigenvalue spectrum of the linear operator.
inv()Inverse of the linear operator.
Log absolute determinant of the linear operator.
rank()Rank of the linear operator.
Compute or approximate the closest symmetric
LinearOperatorin the Frobenius norm.todense([cache])Dense matrix representation of the linear operator.
trace()Trace of the linear operator.
transpose(*axes)Transpose this linear operator.
Attributes Documentation
- T¶
- dtype¶
Data type of the linear operator.
- is_lower_triangular¶
Whether the
LinearOperatorrepresents a lower triangular matrix.If this is
None, it is unknown whether the matrix is lower triangular or not.
- is_positive_definite¶
Whether the
LinearOperator\(L \in \mathbb{R}^{n \times n}\) is (strictly) positive-definite, i.e. \(x^T L x > 0\) for \(x \in \mathbb{R}^n\).If this is
None, it is unknown whether the matrix is positive-definite or not. Only symmetric operators can be positive-definite.
- is_square¶
Whether input dimension matches output dimension.
- is_symmetric¶
Whether the
LinearOperator\(L\) is symmetric, i.e. \(L = L^T\).If this is
None, it is unknown whether the operator is symmetric or not. Only square operators can be symmetric.
- is_upper_triangular¶
Whether the
LinearOperatorrepresents an upper triangular matrix.If this is
None, it is unknown whether the matrix is upper triangular or not.
- kernel¶
Covariance function of the kernel matrix.
- ndim¶
Number of linear operator dimensions.
Defined analogously to
numpy.ndarray.ndim.
- shape¶
Shape of the linear operator.
Defined as a tuple of the output and input dimension of operator.
- size¶
- x0¶
First input(s).
- x1¶
Second input(s).
Methods Documentation
- __call__(x, axis=None)¶
Call self as a function.
- astype(dtype, order='K', casting='unsafe', subok=True, copy=True)¶
Cast a linear operator to a different
dtype.- Parameters
dtype (Union[probnum.backend.Dtype, dtype[Any], None, Type[Any], _SupportsDType[dtype[Any]], str, Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]) – Data type to which the linear operator is cast.
order (str) – Memory layout order of the result.
casting (str) – Controls what kind of data casting may occur.
subok (bool) – If True, then sub-classes will be passed-through (default). False is currently not supported for linear operators.
copy (bool) – Whether to return a new linear operator, even if
dtypeis the same.
- Return type
LinearOperator
- classmethod broadcast_matmat(matmat)¶
Broadcasting for a (implicitly defined) matrix-matrix product.
Convenience function / decorator to broadcast the definition of a matrix-matrix product to vectors. This can be used to easily construct a new linear operator only from a matrix-matrix product.
- classmethod broadcast_matvec(matvec)¶
Broadcasting for a (implicitly defined) matrix-vector product.
Convenience function / decorator to broadcast the definition of a matrix-vector product. This can be used to easily construct a new linear operator only from a matrix-vector product.
- classmethod broadcast_rmatmat(rmatmat)¶
- classmethod broadcast_rmatvec(rmatvec)¶
- cholesky(lower=True)¶
Computes a Cholesky decomposition of the
LinearOperator.The Cholesky decomposition of a symmetric positive-definite matrix \(A \in \mathbb{R}^{n \times n}\) is given by \(A = L L^T\), where the unique Cholesky factor \(L \in \mathbb{R}^{n \times n}\) of \(A\) is a lower triangular matrix with a positive diagonal.
As a side-effect, this method will set the value of
is_positive_definitetoTrue, if the computation of the Cholesky factorization succeeds. Otherwise,is_positive_definitewill be set toFalse.The result of this computation will be cached. If
cholesky()is first called withlower=Truefirst and afterwards withlower=Falseor vice-versa, the method simply returns the transpose of the cached value.- Parameters
lower (bool) – If this is set to
False, this method computes and returns the upper triangular Cholesky factor \(U = L^T\), for which \(A = U^T U\). By default (True), the method computes the lower triangular Cholesky factor \(L\).- Returns
The lower or upper Cholesky factor of the
LinearOperator, depending on the value of the parameterlower. The result will have its propertiesis_upper_triangular/is_lower_triangularset accordingly.- Return type
cholesky_factor
- Raises
numpy.linalg.LinAlgError – If the
LinearOperatoris not symmetric, i.e. ifis_symmetricis not set toTrue.numpy.linalg.LinAlgError – If the
LinearOperatoris not positive definite.
- cond(p=None)¶
Compute the condition number of the linear operator.
The condition number of the linear operator with respect to the
pnorm. It measures how much the solution \(x\) of the linear system \(Ax=b\) changes with respect to small changes in \(b\).- Parameters
p ({None, 1, , 2, , inf, 'fro'}, optional) –
Order of the norm:
p
norm for matrices
None
2-norm, computed directly via singular value decomposition
’fro’
Frobenius norm
np.inf
max(sum(abs(x), axis=1))
1
max(sum(abs(x), axis=0))
2
2-norm (largest sing. value)
- Returns
The condition number of the linear operator. May be infinite.
- Return type
cond
- inv()¶
Inverse of the linear operator.
- Return type
LinearOperator
- rank()¶
Rank of the linear operator.
- Return type
int64
- symmetrize()¶
Compute or approximate the closest symmetric
LinearOperatorin the Frobenius norm.The closest symmetric matrix to a given square matrix \(A\) in the Frobenius norm is given by
\[\operatorname{sym}(A) := \frac{1}{2} (A + A^T).\]However, for efficiency reasons, it is preferrable to approximate this operator in some cases. For example, a Kronecker product \(K = A \otimes B\) is more efficiently symmetrized by means of
\begin{equation} \operatorname{sym}(A) \otimes \operatorname{sym}(B) = \operatorname{sym}(K) + \frac{1}{2} \left( \frac{1}{2} \left( A \otimes B^T + A^T \otimes B \right) - \operatorname{sym}(K) \right). \end{equation}- Returns
The closest symmetric
LinearOperatorin the Frobenius norm, or an approximation, which makes a reasonable trade-off between accuracy and efficiency (see above). The resultingLinearOperatorwill have itsis_symmetricproperty set toTrue.- Return type
symmetrized_linop
- Raises
numpy.linalg.LinAlgError – If this method is called on a non-square
LinearOperator.
- todense(cache=True)¶
Dense matrix representation of the linear operator.
This method can be computationally very costly depending on the shape of the linear operator. Use with caution.
- Returns
matrix – Matrix representation of the linear operator.
- Return type
np.ndarray
- Parameters
cache (bool) –
- trace()¶
Trace of the linear operator.
Computes the trace of a square linear operator \(\text{tr}(A) = \sum_{i-1}^n A_{ii}\).