mushi.composition.closure
- closure(mat)[source]
Performs closure to ensure that all elements add up to 1.
- Parameters
mat (array_like) – a matrix of proportions where rows = compositions columns = components
- Returns
A matrix of proportions where all of the values are nonzero and each composition (row) adds up to 1
- Return type
array_like, np.float64
- Raises
ValueError – Raises an error if any values are negative.
ValueError – Raises an error if the matrix has more than 2 dimension.
ValueError – Raises an error if there is a row that has all zeros.
Examples
>>> import numpy as np >>> import mushi.composition as cmp >>> X = np.array([[2, 2, 6], [4, 4, 2]]) >>> cmp.closure(X) DeviceArray([[0.2, 0.2, 0.6], [0.4, 0.4, 0.2]], dtype=float64)