pyrtid.regularization.SparseInvCovarianceMatrix#

class pyrtid.regularization.SparseInvCovarianceMatrix(*args, **kwargs)[source]#

Bases: CovarianceMatrix

Represents a sparse inverse covariance matrix.

Works for arbitrary kernels on irregular grids.

__init__(inv_mat: csc_array, inv_mat_cho_factor: Optional[Factor] = None) None[source]#

Initialize the instance.

Parameters
  • inv_mat (csc_array) – Sparse precision matrix (inverse of the covariance matrix).

  • inv_mat_cho_factor (Optional[Factor]) – inv_mat CHOLMOD Factor. If not provided, the factorization is performed at the instance initialization. The default is None.

Methods definition

__call__(x)#

Call self as a function.

_adjoint()#

Default implementation of _adjoint; defers to rmatvec.

_init_dtype()#

Determine the dtype by executing matvec on an int8 test vector.

In np.promote_types hierarchy, the type int8 is the smallest, so we call matvec on int8 and use the promoted dtype of the output to set the default dtype of the LinearOperator. We assume that matmat, rmatvec, and rmatmat would result in the same dtype of the output given an int8 input as matvec.

Called from subclasses at the end of the __init__ routine.

_matmat(X)#

Default matrix-matrix multiplication handler.

Falls back on the user-defined _matvec method, so defining that will define matrix multiplication (though in a very suboptimal way).

_matvec(x: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[float64]][source]#

Return the covariance matrix times the vector x.

_rdot(x)#

Matrix-matrix or matrix-vector multiplication from the right.

Parameters

x (array_like) – 1-d or 2-d array, representing a vector or matrix.

Returns

xA – 1-d or 2-d array (depending on the shape of x) that represents the result of applying this linear operator on x from the right.

Return type

array

Notes

This is copied from dot to implement right multiplication.

_rmatmat(X)#

Default implementation of _rmatmat defers to rmatvec or adjoint.

_rmatvec(x)#

Default implementation of _rmatvec; defers to adjoint.

_transpose()#

Default implementation of _transpose; defers to rmatvec + conj

adjoint()#

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns

A_H – Hermitian adjoint of self.

Return type

LinearOperator

dot(x)#

Matrix-matrix or matrix-vector multiplication.

Parameters

x (array_like) – 1-d or 2-d array, representing a vector or matrix.

Returns

Ax – 1-d or 2-d array (depending on the shape of x) that represents the result of applying this linear operator on x.

Return type

array

get_diagonal() ndarray[Any, dtype[float64]][source]#

Return the diagonal entries of the matrix (variances).

The matrix is never built explicitly. Instead the matvec interface is used to multiply all column of the identity matrix.

get_trace() float#

Return the trace of the covariance matrix.

itercount() int#

Return the number of counts.

matmat(X)#

Matrix-matrix multiplication.

Performs the operation y=A@X where A is an MxN linear operator and X dense N*K matrix or ndarray.

Parameters

X ({matrix, ndarray}) – An array with shape (N,K).

Returns

Y – A matrix or ndarray with shape (M,K) depending on the type of the X argument.

Return type

{matrix, ndarray}

Notes

This matmat wraps any user-specified matmat routine or overridden _matmat method to ensure that y has the correct type.

matvec(x)#

Matrix-vector multiplication.

Performs the operation y=A@x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters

x ({matrix, ndarray}) – An array with shape (N,) or (N,1).

Returns

y – A matrix or ndarray with shape (M,) or (M,1) depending on the type and shape of the x argument.

Return type

{matrix, ndarray}

Notes

This matvec wraps the user-specified matvec routine or overridden _matvec method to ensure that y has the correct shape and type.

reset_comptors() None#

Set the comptors to zero.

rmatmat(X)#

Adjoint matrix-matrix multiplication.

Performs the operation y = A^H @ x where A is an MxN linear operator and x is a column vector or 1-d array, or 2-d array. The default implementation defers to the adjoint.

Parameters

X ({matrix, ndarray}) – A matrix or 2D array.

Returns

Y – A matrix or 2D array depending on the type of the input.

Return type

{matrix, ndarray}

Notes

This rmatmat wraps the user-specified rmatmat routine.

rmatvec(x)#

Adjoint matrix-vector multiplication.

Performs the operation y = A^H @ x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters

x ({matrix, ndarray}) – An array with shape (M,) or (M,1).

Returns

y – A matrix or ndarray with shape (N,) or (N,1) depending on the type and shape of the x argument.

Return type

{matrix, ndarray}

Notes

This rmatvec wraps the user-specified rmatvec routine or overridden _rmatvec method to ensure that y has the correct shape and type.

solve(x: ndarray[Any, dtype[float64]]) ndarray[Any, dtype[float64]][source]#

Return $Q^{-1} x.

transpose()#

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().

property H#

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns

A_H – Hermitian adjoint of self.

Return type

LinearOperator

property T#

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().

property number_pts: int#

Number of points in the domain (n).