pyphi.convert.state_by_node2state_by_state#

pyphi.convert.state_by_node2state_by_state(sbn)[source]#

Convert a state-by-node TPM to a state-by-state TPM.

Important

A nondeterministic state-by-node TPM can have more than one representation as a state-by-state TPM. The mapping is made one-to-one by assuming the TPMs to be conditionally independent, so this function returns the corresponding conditionally independent state-by-state TPM.

Note

The rows of the state-by-node TPM are assumed to follow the little-endian convention. The rows and columns of the resulting state-by-state TPM both follow the little-endian convention. See the PyPhi documentation on Transition probability matrix conventions for more information.

Parameters:

sbn (list[list] or np.ndarray) – A state-by-node TPM with row indices following the little-endian convention.

Returns:

np.ndarray – A state-by-state TPM, with both row and column indices following the little-endian convention.

Examples

>>> tpm = np.array([[1, 1, 0],
...                 [0, 0, 1],
...                 [0, 1, 1],
...                 [1, 0, 0],
...                 [0, 0, 1],
...                 [1, 0, 0],
...                 [1, 1, 1],
...                 [1, 0, 1]])
>>> state_by_node2state_by_state(tpm)
array([[0., 0., 0., 1., 0., 0., 0., 0.],
       [0., 0., 0., 0., 1., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 1., 0.],
       [0., 1., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 1., 0., 0., 0.],
       [0., 1., 0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0., 0., 1.],
       [0., 0., 0., 0., 0., 1., 0., 0.]])
>>> tpm = np.array([[0.1, 0.3, 0.7],
...                 [0.3, 0.9, 0.2],
...                 [0.3, 0.9, 0.1],
...                 [0.2, 0.8, 0.5],
...                 [0.1, 0.7, 0.4],
...                 [0.4, 0.3, 0.6],
...                 [0.4, 0.3, 0.1],
...                 [0.5, 0.2, 0.1]])
>>> state_by_node2state_by_state(tpm)
array([[0.189, 0.021, 0.081, 0.009, 0.441, 0.049, 0.189, 0.021],
       [0.056, 0.024, 0.504, 0.216, 0.014, 0.006, 0.126, 0.054],
       [0.063, 0.027, 0.567, 0.243, 0.007, 0.003, 0.063, 0.027],
       [0.08 , 0.02 , 0.32 , 0.08 , 0.08 , 0.02 , 0.32 , 0.08 ],
       [0.162, 0.018, 0.378, 0.042, 0.108, 0.012, 0.252, 0.028],
       [0.168, 0.112, 0.072, 0.048, 0.252, 0.168, 0.108, 0.072],
       [0.378, 0.252, 0.162, 0.108, 0.042, 0.028, 0.018, 0.012],
       [0.36 , 0.36 , 0.09 , 0.09 , 0.04 , 0.04 , 0.01 , 0.01 ]])
>>> tpm = np.array([[1],
...                 [0]])
>>> state_by_node2state_by_state(tpm)
array([[0., 1.],
       [1., 0.]])
>>> tpm = np.array([[[[0.5, 0.5]]]])
>>> state_by_node2state_by_state(tpm)
array([[0.25, 0.25, 0.25, 0.25]])