math_utils module

dynamapp.math_utils.logger = <Logger dynamapp.math_utils (WARNING)>

Eigenvalue decomposition of a matrix matrix such that left_orthogonal @ eigenvalues @ right_orthogonal equals matrix.

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 shape shape. The error message will contain name.

dynamapp.math_utils.eigenvalue_decomposition(matrix: jax.numpy.ndarray) Decomposition[source]

Calculate eigenvalue decomposition of matrix as a Decomposition.

dynamapp.math_utils.reduce_decomposition(decomposition: Decomposition, rank: int) Decomposition[source]

Reduce an eigenvalue decomposition decomposition such that only rank number of biggest eigenvalues remain. Returns another Decomposition.

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 with num_block_rows block rows. The shape of matrix is interpreted in row-order, like the structure of a pd.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 of matrix stacked on top of eachother.

dynamapp.math_utils.unvectorize(vector: jax.numpy.ndarray, num_rows: int) jax.numpy.ndarray[source]

Given a vector vector of shape (num_rows*b, 1), return a matrix of shape (num_rows, b) such that the stacked columns of the returned matrix equal vector.

dynamapp.math_utils.is_skew_symmetric(matrix)[source]

Check if the input matrix is skew-symmetric.