CodeEntropy.levels.linalg module

Matrix utilities used across covariance and entropy calculations.

This module contains small, focused helpers for matrix construction and cleanup. All functions are pure (no side effects beyond logging) and operate on NumPy arrays.

Key behaviors: - create_submatrix computes a 3x3 outer-product block for two 3-vectors. - filter_zero_rows_columns removes rows/columns that are all (near) zero.

class CodeEntropy.levels.linalg.MatrixUtils[source]

Bases: object

Utility operations for small matrix manipulations.

create_submatrix(data_i: ndarray, data_j: ndarray) ndarray[source]

Create a 3x3 covariance-style submatrix from two 3-vectors.

This computes the outer product of data_i and data_j:

submatrix = outer(data_i, data_j)

Parameters:
  • data_i – Vector of shape (3,) representing bead i values.

  • data_j – Vector of shape (3,) representing bead j values.

Returns:

A (3, 3) NumPy array corresponding to the outer product.

Raises:

ValueError – If either input cannot be reshaped to (3,).

filter_zero_rows_columns(matrix: ndarray, atol: float = 0.0) ndarray[source]

Remove rows and columns that are entirely (near) zero.

A row (or column) is removed if all entries are close to zero according to np.isclose(…, atol=atol).

Parameters:
  • matrix – Input 2D array.

  • atol – Absolute tolerance used to determine “zero”. Defaults to 0.0.

Returns:

A new matrix with all-zero rows and columns removed. If no such rows or columns exist, returns a view/copy of the original with consistent NumPy typing.

Raises:

ValueError – If matrix is not 2D.