dubfi.linalg.mpipad.main

MPI linear algebra parent module.

This module instructs multiple MPI processes (workers) to do linear algebra computations.

Added in version 0.1.0: (initial release)

Classes

MpiVector

MPI distributed vector.

MpiDenseBdMatrix

MPI parent of approximately diagonal or block-diagonal matrix.

MpiLinParamVector

MPI distributed linear parametrized vector.

MpiDensePostR

MPI distributed R matrix for flux inversion.

Functions

simple_segments(size, overlap[, number]) → dubfi.linalg.mpipad.segments.Segments

Construct MPI segments along one linear, equally spaced coordinate.

Module Contents

dubfi.linalg.mpipad.main.simple_segments(size: int, overlap: int, number: int = -1) → dubfi.linalg.mpipad.segments.Segments

Construct MPI segments along one linear, equally spaced coordinate.

class dubfi.linalg.mpipad.main.MpiVector(seg: dubfi.linalg.mpipad.segments.Segments, shape: tuple[int, ...])

Bases: dubfi.linalg.types.AbstractVector, dubfi.mpi.parent_context.MpiObj

MPI distributed vector.

property shape

Shape of array representation of self, last dimension is the vector dimension.

property data

Numpy array representation of self, collects data from worker processes.

classmethod fromdata(data: numpy.ndarray, other=None)

Construct distributed vector from dense array, borrowing segment information from other.

classmethod fromarray(segments: dubfi.linalg.mpipad.segments.Segments, data: numpy.ndarray)

Construct distributed vector from dense array and given segments.

apply(other)

Compute scalar product with other vector.

dot(other: numpy.ndarray) → MpiVector

Compute scalar product along some non-vector dimension.

__add__(other)

Add two vectors, applying broadcasting rules.

__iadd__(other)

Add vector in-place.

__sub__(other)

Subtract vector from self, applying broadcasting rules.

__isub__(other)

Subtract vector in-place.

__mul__(other)

Multiply by scalar or numpy array treated as scalar along vector space dimension.

iszero()

Check if all elements are zero.

tonumpy()

Numpy array representation of self, collects data from worker processes.

class dubfi.linalg.mpipad.main.MpiDenseBdMatrix(seg: dubfi.linalg.mpipad.segments.Segments, shape: tuple[int, ...])

Bases: dubfi.linalg.types.AbstractOperator, dubfi.mpi.parent_context.MpiObj

MPI parent of approximately diagonal or block-diagonal matrix.

property shape

Shape of array (matrix) representation of self.

classmethod fromarray(data: numpy.ndarray, seg: dubfi.linalg.mpipad.segments.Segments)

Construct distributed operator from dense array and given segments.

apply(vec)

Apply operator on vector: self @ vec.

rapply(vec)

Apply transpose operator on vector: self.T @ vec.

inv()

Compute (multiplicative) inverse operator.

solve(vec)

Solve linear equation self @ x = vec for x.

chain(other)

Combine operators: self @ other.

diagonal()

Return diagonal of self as MPI vector.

__mul__(other)

Multiply element-wise.

__add__(other)

Add to other linear operator.

__iadd__(other)

Add other linear operator in-place.

__sub__(other)

Subtract other linear operator.

__isub__(other)

Subtract other linear operator in-place.

dot(other)

Inner product along non-vector dimensions.

trace()

Compute trace of self.

trace_product(other)

Compute trace of (self @ other).

logdet()

Compute log(det(self)) assuming that self is a positive definite, real-symmetric matrix.

tonumpy()

Numpy array representation of self, collects data from worker processes.

sandwich(vec)

Compute vec @ self @ vec.

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.

Added in version 0.1.3.

class dubfi.linalg.mpipad.main.MpiLinParamVector(seg: dubfi.linalg.mpipad.segments.Segments, shape: tuple[int, ...])

Bases: dubfi.linalg.generic.ParametrizedVector, dubfi.mpi.parent_context.MpiObj

MPI distributed linear parametrized vector.

classmethod fromarray(seg: dubfi.linalg.mpipad.segments.Segments, array: numpy.ndarray)

Construct distributed parametrized vector from dense array and given segments.

__call__(s)

Compute vector at given parameters.

grad(s)

Compute gradient of vector at given parameters.

hess(s)

Compute Hesse matrix of vector at given parameters.

class dubfi.linalg.mpipad.main.MpiDensePostR(seg)

Bases: dubfi.linalg.generic.ParametrizedOperator, dubfi.mpi.parent_context.MpiObj

MPI distributed R matrix for flux inversion.

classmethod fromarray(seg: dubfi.linalg.mpipad.segments.Segments, h_ens: numpy.ndarray, localization_length: float, regularization: float)

Construct distributed object from dense vectors and given segments.

__call__(s)

Compute R at given parameters.

grad(s)

Compute gradient of R at given parameters.

hess(s)

Compute Hesse matrix of R at given parameters.

diagonal_components() → dict[str, numpy.ndarray]

Parameter-independent, additive contributions to the diagonal (for debugging).