dubfi.linalg.mpipad.main ======================== .. py:module:: dubfi.linalg.mpipad.main .. autoapi-nested-parse:: MPI linear algebra parent module. This module instructs multiple MPI processes (workers) to do linear algebra computations. .. codeauthor:: Valentin Bruch, DWD .. versionadded:: 0.1.0 (initial release) Classes ------- .. autoapisummary:: dubfi.linalg.mpipad.main.MpiVector dubfi.linalg.mpipad.main.MpiDenseBdMatrix dubfi.linalg.mpipad.main.MpiLinParamVector dubfi.linalg.mpipad.main.MpiDensePostR Functions --------- .. autoapisummary:: dubfi.linalg.mpipad.main.simple_segments Module Contents --------------- .. py:function:: simple_segments(size: int, overlap: int, number: int = -1) -> dubfi.linalg.mpipad.segments.Segments Construct MPI segments along one linear, equally spaced coordinate. .. py:class:: MpiVector(seg: dubfi.linalg.mpipad.segments.Segments, shape: tuple[int, ...]) Bases: :py:obj:`dubfi.linalg.types.AbstractVector`, :py:obj:`dubfi.mpi.parent_context.MpiObj` MPI distributed vector. .. py:property:: shape Shape of array representation of self, last dimension is the vector dimension. .. py:property:: data Numpy array representation of self, collects data from worker processes. .. py:method:: fromdata(data: numpy.ndarray, other=None) :classmethod: Construct distributed vector from dense array, borrowing segment information from other. .. py:method:: fromarray(segments: dubfi.linalg.mpipad.segments.Segments, data: numpy.ndarray) :classmethod: Construct distributed vector from dense array and given segments. .. py:method:: apply(other) Compute scalar product with other vector. .. py:method:: dot(other: numpy.ndarray) -> MpiVector Compute scalar product along some non-vector dimension. .. py:method:: __add__(other) Add two vectors, applying broadcasting rules. .. py:method:: __iadd__(other) Add vector in-place. .. py:method:: __sub__(other) Subtract vector from self, applying broadcasting rules. .. py:method:: __isub__(other) Subtract vector in-place. .. py:method:: __mul__(other) Multiply by scalar or numpy array treated as scalar along vector space dimension. .. py:method:: iszero() Check if all elements are zero. .. py:method:: tonumpy() Numpy array representation of self, collects data from worker processes. .. py:class:: MpiDenseBdMatrix(seg: dubfi.linalg.mpipad.segments.Segments, shape: tuple[int, ...]) Bases: :py:obj:`dubfi.linalg.types.AbstractOperator`, :py:obj:`dubfi.mpi.parent_context.MpiObj` MPI parent of approximately diagonal or block-diagonal matrix. .. py:property:: shape Shape of array (matrix) representation of self. .. py:method:: fromarray(data: numpy.ndarray, seg: dubfi.linalg.mpipad.segments.Segments) :classmethod: Construct distributed operator from dense array and given segments. .. 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:: diagonal() Return diagonal of self as MPI vector. .. py:method:: __mul__(other) Multiply element-wise. .. py:method:: __add__(other) Add to other linear operator. .. py:method:: __iadd__(other) Add other linear operator in-place. .. py:method:: __sub__(other) Subtract other linear operator. .. py:method:: __isub__(other) Subtract other linear operator in-place. .. py:method:: dot(other) Inner product along non-vector dimensions. .. py:method:: trace() Compute trace of self. .. py:method:: trace_product(other) Compute trace of (self @ other). .. py:method:: logdet() Compute log(det(self)) assuming that self is a positive definite, real-symmetric matrix. .. py:method:: tonumpy() Numpy array representation of self, collects data from worker processes. .. py:method:: sandwich(vec) Compute vec @ self @ vec. .. py:method:: validate_uncertainty_statistics(vec) -> tuple[numpy.ndarray, numpy.ndarray] Indicate whether vec is a likely realization of a Gaussian random variable with variance self. Assume that self is the error covariance matrix of a Gaussian random variable X with mean 0. Provide indications whether X is a likely realization of X in the following form: Diagonalize self: self = V @ diag(D) @ V.T where D is the vector of eigenvalues of self and V is an orthogonal matrix. Return (V.T @ vec, D). One can expect that (V.T @ vec) / D is a Gaussian random variable with mean 0 and standard deviation 1. .. versionadded:: 0.1.3 .. py:class:: MpiLinParamVector(seg: dubfi.linalg.mpipad.segments.Segments, shape: tuple[int, ...]) Bases: :py:obj:`dubfi.linalg.generic.ParametrizedVector`, :py:obj:`dubfi.mpi.parent_context.MpiObj` MPI distributed linear parametrized vector. .. py:method:: fromarray(seg: dubfi.linalg.mpipad.segments.Segments, array: numpy.ndarray) :classmethod: Construct distributed parametrized vector from dense array and given segments. .. py:method:: __call__(s) Compute vector at given parameters. .. py:method:: grad(s) Compute gradient of vector at given parameters. .. py:method:: hess(s) Compute Hesse matrix of vector at given parameters. .. py:class:: MpiDensePostR(seg) Bases: :py:obj:`dubfi.linalg.generic.ParametrizedOperator`, :py:obj:`dubfi.mpi.parent_context.MpiObj` MPI distributed R matrix for flux inversion. .. py:method:: fromarray(seg: dubfi.linalg.mpipad.segments.Segments, h_ens: numpy.ndarray, localization_length: float, regularization: float) :classmethod: Construct distributed object from dense vectors and given segments. .. py:method:: __call__(s) Compute R at given parameters. .. py:method:: grad(s) Compute gradient of R at given parameters. .. py:method:: hess(s) Compute Hesse matrix of R at given parameters. .. py:method:: diagonal_components() -> dict[str, numpy.ndarray] Parameter-independent, additive contributions to the diagonal (for debugging).