Skip to content

Commit

Permalink
fix: remove Nick's lingering left nullspace
Browse files Browse the repository at this point in the history
  • Loading branch information
carrascomj committed Jun 20, 2024
1 parent 191b85b commit 09ba4cd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
6 changes: 0 additions & 6 deletions maud/data_model/kinetic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)

from maud.data_model.hardcoding import ID_SEPARATOR
from maud.utility_functions import get_left_nullspace


class ReactionMechanism(int, Enum):
Expand Down Expand Up @@ -269,11 +268,6 @@ def stoichiometric_matrix(self) -> pd.DataFrame:
"""Add the stoichiometric_matrix field."""
return get_stoichiometric_matrix(self.edges, self.mics, self.reactions)

@computed_field
def left_nullspace(self) -> pd.DataFrame:
"""Calculate the left nullspace."""
return get_left_nullspace(self.stoichiometric_matrix)

@computed_field
def phosphorylation_modifying_enzymes(
self,
Expand Down
47 changes: 0 additions & 47 deletions maud/utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,53 +101,6 @@ def get_null_space(a, rtol=1e-5):
return v[rank:].T.copy()


def get_left_nullspace(matrix: pd.DataFrame, atol=1e-13, rtol=0.0):
"""Compute an approximate basis for the null space (kernel) of a matrix.
The algorithm used by this function is based on the singular value
decomposition of the given matrix.
Parameters
----------
matrix : ndarray
The matrix should be at most 2-D. A 1-D array with length k
will be treated as a 2-D with shape (1, k)
atol : float
The absolute tolerance for a zero singular value. Singular values
smaller than ``atol`` are considered to be zero.
rtol : float
The relative tolerance for a zero singular value. Singular values less
than the relative tolerance times the largest singular value are
considered to be zero.
Notes
-----
If both `atol` and `rtol` are positive, the combined tolerance is the
maximum of the two; that is::
tol = max(atol, rtol * smax)
Singular values smaller than ``tol`` are considered to be zero.
Returns
-------
ndarray
If ``matrix`` is an array with shape (m, k), then the returned
nullspace will be an array with shape ``(k, n)``, where n is the
estimated dimension of the nullspace.
References
----------
Adapted from:
https://scipy.github.io/old-wiki/pages/Cookbook/RankNullspace.html
and then taken from from
https://github.com/opencobra/memote/blob/develop/src/memote/support/consistency_helpers.py#L163
""" # noqa: D402
matrix = np.atleast_2d(matrix)
_, sigma, vh = np.linalg.svd(matrix.T)
tol = max(atol, rtol * sigma[0])
num_nonzero = (sigma >= tol).sum()
return vh[num_nonzero:].conj().T


def get_rref(mat):
"""Return reduced row echelon form of a matrix."""
return sp.Matrix(mat).rref(iszerofunc=lambda x: abs(x) < 1e-10)[0]

0 comments on commit 09ba4cd

Please sign in to comment.