Skip to content

markov

exp_elements(m, base=10, sub_name=lambda x: 'u' + x[1:])

Exponentiate elements of matrix to a given base, and optionally substitute parameters with new parameters

Parameters:

Name Type Description Default
m Matrix

Input matrix which elements to exponentiate.

required
base

Base of the exponent.

10
sub_name Optional[Callable]

Function which takes parameter name and returns substitute parameter name.

lambda x: 'u' + x[1:]

Returns:

Type Description
Matrix

Exponentiated matrix

Source code in slimfit/markov.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def exp_elements(
    m: Matrix, base=10, sub_name: Optional[Callable] = lambda x: "u" + x[1:]
) -> Matrix:
    """
    Exponentiate elements of matrix to a given base, and optionally substitute parameters with new parameters

    Args:
        m: Input matrix which elements to exponentiate.
        base: Base of the exponent.
        sub_name: Function which takes parameter name and returns substitute parameter name.

    Returns:
        Exponentiated matrix

    """
    out = zeros(*m.shape)
    for i, j in np.ndindex(m.shape):
        elem = m[i, j]
        if elem == 0.0:
            continue
        else:
            out[i, j] = base**elem

    if sub_name is not None:
        subs = [(p, Parameter(name=sub_name(p.name))) for p in t.free_symbols]
        out = out.subs(subs)

    return out

extract_states(connectivity)

Parameters:

Name Type Description Default
connectivity list[str]

List of reaction equations.

required

Returns:

Type Description
list[str]

List of states found in all reaction equations.

Source code in slimfit/markov.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def extract_states(connectivity: list[str]) -> list[str]:
    """
    Args:
        connectivity: List of reaction equations.

    Returns:
        List of states found in all reaction equations.

    """

    # extract states from connectivity list
    all_states = [
        s for s in reduce(add, [eqn.split(" ") for eqn in connectivity]) if s not in OPERATORS
    ]

    # Remove duplicates, keep order
    all_states = list(dict.fromkeys(all_states))

    return all_states