dubfi.linalg.csc_sparse ======================= .. py:module:: dubfi.linalg.csc_sparse .. autoapi-nested-parse:: CSC sparse matrix implementation of generic operators. .. codeauthor:: Valentin Bruch, DWD .. versionadded:: 0.1.0 (initial release) Classes ------- .. autoapisummary:: dubfi.linalg.csc_sparse.CscMatrix dubfi.linalg.csc_sparse.CscTraceProdOperator dubfi.linalg.csc_sparse.CscEnsLinPostR Functions --------- .. autoapisummary:: dubfi.linalg.csc_sparse._csc_trace dubfi.linalg.csc_sparse.tr_asolver_bcsr dubfi.linalg.csc_sparse.tr_asolver_bcsc dubfi.linalg.csc_sparse._csc_csr_trace_prod dubfi.linalg.csc_sparse._r_csc_from_ens dubfi.linalg.csc_sparse._rgrad_csc_from_ens dubfi.linalg.csc_sparse._rhess_csc_from_ens Module Contents --------------- .. py:class:: CscMatrix(array, symmetric=False, use_inv=True) Bases: :py:obj:`dubfi.linalg.types.Operator` Compressed sparse column representation of a linear operator. .. py:property:: symmetric Indicate whether matrix is (or must be) real-symmetric. .. py:property:: splu Sparse LU decomposition of self. .. py:method:: tonumpy() Convert to dense array. .. py:property:: csc_array :type: scipy.sparse.csc_array Return CSC sparse array representation. .. py:method:: diagonal() Return diagonal of self. .. py:method:: __mul__(other) Multiply by scalar or numpy array treated as scalar along vector space dimensions. .. py:method:: __add__(other) Add other operator. .. py:method:: __iadd__(other) Add other operator in-place. .. py:method:: __sub__(other) Subtract other operator. .. py:method:: __isub__(other) Subtract other operator in-place. .. py:method:: apply(vec) Apply operator on vector: self @ vec. .. py:method:: rapply(vec) Apply transpose operator on vector: self.T @ vec. .. py:method:: inv() Compute (multiplicative) inverse operator. .. py:method:: solve(vec) Solve linear equation self @ x = vec for x. .. py:method:: chain(other) Combine operators: self @ other. .. py:method:: trace() Compute trace of self. .. py:method:: logdet() Compute log(det(self)) assuming that self is a positive definite, real-symmetric matrix. .. py:class:: CscTraceProdOperator(data, indices, indptr, symmetric=False) Bases: :py:obj:`dubfi.linalg.types.AbstractOperator` Auxiliary class used for computing trace products. .. py:property:: shape Shape of array (matrix) representation of self. .. py:property:: symmetric True if self equals its adjoint. .. py:method:: apply(vec) Apply operator on vector: self @ vec. .. py:method:: rapply(vec) Apply transpose operator on vector: self.T @ vec. .. py:method:: trace() Compute trace of self. .. py:method:: trace_product(other) Compute trace(self @ other). .. py:method:: tonumpy() Numpy array (matrix) representation of self. .. py:method:: chain(other) Combine operators: self @ other. .. py:method:: __mul__(other) Multiply element-wise. .. py:method:: __imul__(other) Multiply element-wise in-place. .. py:method:: solve(vec) :abstractmethod: Solve linear equation self @ x = vec for x. .. py:method:: dot(other) Inner product along non-vector dimensions. .. py:method:: __add__(other) Add two linear operators. .. py:method:: __iadd__(other) Add two linear operators in-place. .. py:method:: __sub__(other) Subtract two linear operators. .. py:method:: __isub__(other) Subtract two linear operators in-place. .. py:function:: _csc_trace(data, indices, indptr) Compute trace of a matrix in compressed sparse column representation. .. py:function:: tr_asolver_bcsr(apply_a, data, indices, indptr) Compute trace(A @ B) where Ax := apply_a(x) and B is represented as BSR (data, indices, indptr). .. py:function:: tr_asolver_bcsc(apply_a, data, indices, indptr) Compute trace(A @ B) where Ax := apply_a(x) and B is represented as BSC (data, indices, indptr). .. note:: This function assumes that apply_a is expensive. :func:`tr_asolver_bcsr` is generally more efficient. .. py:function:: _csc_csr_trace_prod(data1, indices1, indptr1, data2, indices2, indptr2) Compute trace(A @ B) represented as sparse CSC and CSR arrays. Consider two sparse square matrices A and B of equal shape. Let (data1, indices1, indptr1) be the CSC representation of A and (data2, indices2, indptr2) be the CSR representation of B. Then this function returns (a @ b).trace(). This function assumes sorted indices! .. py:class:: CscEnsLinPostR(h_ensemble, loc, regularization = 0.0, bg_ens = None, bc_ens = None) Bases: :py:obj:`dubfi.linalg.generic.ParametrizedOperator` CSC representation of R matrix in flux inversion problem. .. py:method:: set_bg_ens(bg_ens) Set the background (or total concentration) meteorological ensemble. .. py:method:: set_bc_ens(bc_ens) Set boundary condition ensemble. .. py:method:: __call__(s) Compute operator at given parameter vector s. .. py:method:: grad(s) Gradient at given parameter vector s. .. py:method:: hess(s) Hesse matrix at given parameter vector s. .. py:function:: _r_csc_from_ens(loc_data, indices, indptr, h) Construct ensemble contribution to R CSC data. Given a localization in CSC format and the ensemble observation operator H, construct the CSC data for R, assuming it share the same CSC indices and indptr as the localization. .. py:function:: _rgrad_csc_from_ens(loc_data, indices, indptr, h, h_ens) Construct gradient of R CSC data. Given a localization in CSC format and the ensemble observation operator H, construct the CSC data for grad(R), assuming it share the same CSC indices and indptr as the localization. .. py:function:: _rhess_csc_from_ens(loc_data, indices, indptr, h_ens) Construct Hesse matrix of R CSC data. Given a localization in CSC format and the ensemble observation operator H, construct the CSC data for hess(R), assuming it share the same CSC indices and indptr as the localization.