math_utils module
- dynamapp.math_utils.logger = <Logger dynamapp.math_utils (WARNING)>
Eigenvalue decomposition of a matrix
matrix
such thatleft_orthogonal @ eigenvalues @ right_orthogonal
equalsmatrix
.
- class dynamapp.math_utils.Decomposition(left_orthogonal, eigenvalues, right_orthogonal)
Bases:
tuple
- eigenvalues
Alias for field number 1
- left_orthogonal
Alias for field number 0
- right_orthogonal
Alias for field number 2
- dynamapp.math_utils.condition_number(M, threshold=1e-05)[source]
Computes the condition number of a matrix with a check for SVD convergence. The condition number of a matrix is given by the equation:
\[\kappa = \sigma_{max} / \sigma_{min}\]\(\sigma_{max}\) is the maximum singular value.
\(\sigma_{min}\) is the minimum singular value.
- Args:
M (np.ndarray): Input matrix. threshold (float): Threshold for the condition number.
- dynamapp.math_utils.validate_matrix_shape(matrix: jax.numpy.ndarray, shape: Tuple[float, float], name: str)[source]
Raises if
matrix
does not have shapeshape
. The error message will containname
.
- dynamapp.math_utils.eigenvalue_decomposition(matrix: jax.numpy.ndarray) Decomposition [source]
Calculate eigenvalue decomposition of
matrix
as aDecomposition
.
- dynamapp.math_utils.reduce_decomposition(decomposition: Decomposition, rank: int) Decomposition [source]
Reduce an eigenvalue decomposition
decomposition
such that onlyrank
number of biggest eigenvalues remain. Returns anotherDecomposition
.
- dynamapp.math_utils.block_hankel_matrix(matrix: jax.numpy.ndarray, num_block_rows: int) jax.numpy.ndarray [source]
Calculate a block Hankel matrix based on input matrix
matrix
withnum_block_rows
block rows. The shape ofmatrix
is interpreted in row-order, like the structure of apd.DataFrame
: the rows are measurements and the columns are data sources.The returned block Hankel matrix has a columnar structure. Every column of the returned matrix consists of
num_block_rows
block rows (measurements). See the examples for details.Examples
Suppose that the input matrix contains 4 measurements of 2-dimensional data:
>>> matrix = np.array([ >>> [0, 1], >>> [2, 3], >>> [4, 5], >>> [6, 7] >>> ])
If the number of block rows is set to
num_block_rows=2
, then the block Hankel matrix will be>>> np.array([ >>> [0, 2, 4], >>> [1, 3, 5], >>> [2, 4, 6], >>> [3, 5, 7] >>> ])
- dynamapp.math_utils.vectorize(matrix: jax.numpy.ndarray) jax.numpy.ndarray [source]
Given a matrix
matrix
of shape(a, b)
, return a vector of shape(a*b, 1)
with all columns ofmatrix
stacked on top of eachother.