# convert¶

Conversion functions.

pyphi.convert.nodes2indices(nodes)
pyphi.convert.state2holi_index(state)

Convert a PyPhi state-tuple to a decimal index according to the HOLI convention.

Parameters: state (tuple(int) – A state-tuple where the $$i^{\textrm{th}}$$ element of the tuple gives the state of the $$i^{\textrm{th}}$$ node. holi_index – A decimal integer corresponding to a network state under the HOLI convention. int

Examples

>>> from pyphi.convert import state2loli_index
>>> state2holi_index((1, 0, 0, 0, 0))
16
>>> state2holi_index((1, 1, 1, 0, 0, 0, 0, 0))
224

pyphi.convert.state2loli_index(state)

Convert a PyPhi state-tuple to a decimal index according to the LOLI convention.

Parameters: state (tuple(int) – A state-tuple where the $$i^{\textrm{th}}$$ element of the tuple gives the state of the $$i^{\textrm{th}}$$ node. loli_index – A decimal integer corresponding to a network state under the LOLI convention. int

Examples

>>> from pyphi.convert import state2loli_index
>>> state2loli_index((1, 0, 0, 0, 0))
1
>>> state2loli_index((1, 1, 1, 0, 0, 0, 0, 0))
7

pyphi.convert.loli_index2state(i, number_of_nodes)

Convert a decimal integer to a PyPhi state tuple with the LOLI convention.

The output is the reverse of holi_index2state.

Parameters: i (int) – A decimal integer corresponding to a network state under the LOLI convention. state – A state-tuple where the $$i^{\textrm{th}}$$ element of the tuple gives the state of the $$i^{\textrm{th}}$$ node. tuple(int

Examples

>>> from pyphi.convert import loli_index2state
>>> number_of_nodes = 5
>>> loli_index2state(1, number_of_nodes)
(1, 0, 0, 0, 0)
>>> number_of_nodes = 8
>>> loli_index2state(7, number_of_nodes)
(1, 1, 1, 0, 0, 0, 0, 0)

pyphi.convert.holi_index2state(i, number_of_nodes)

Convert a decimal integer to a PyPhi state tuple using the HOLI convention that high-order bits correspond to low-index nodes.

The output is the reverse of loli_index2state.

Parameters: i (int) – A decimal integer corresponding to a network state under the HOLI convention. state – A state-tuple where the $$i^{\textrm{th}}$$ element of the tuple gives the state of the $$i^{\textrm{th}}$$ node. tuple(int

Examples

>>> from pyphi.convert import holi_index2state
>>> number_of_nodes = 5
>>> holi_index2state(1, number_of_nodes)
(0, 0, 0, 0, 1)
>>> number_of_nodes = 8
>>> holi_index2state(7, number_of_nodes)
(0, 0, 0, 0, 0, 1, 1, 1)

pyphi.convert.to_n_dimensional(tpm)

Reshape a state-by-node TPM to the N-D form.

See documentation for the Network object for more information on TPM formats.

pyphi.convert.state_by_state2state_by_node(tpm)

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

Note

The indices of the rows and columns of the state-by-state TPM are assumed to follow the LOLI convention. The indices of the rows of the resulting state-by-node TPM also follow the LOLI convention. See the documentation for the examples module for more info on these conventions.

Parameters: tpm (list(list) – A square state-by-state TPM with row and column indices following the LOLI convention. state_by_node_tpm – A state-by-node TPM, with row indices following the LOLI convention. np.ndarray

Examples

>>> from pyphi.convert import state_by_state2state_by_node
>>> tpm = np.array([[0.5, 0.5, 0.0, 0.0],
...                 [0.0, 1.0, 0.0, 0.0],
...                 [0.0, 0.2, 0.0, 0.8],
...                 [0.0, 0.3, 0.7, 0.0]])
>>> state_by_state2state_by_node(tpm)
array([[[ 0.5,  0. ],
[ 1. ,  0.8]],

[[ 1. ,  0. ],
[ 0.3,  0.7]]])

pyphi.convert.state_by_node2state_by_state(tpm)

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

Note

A nondeterministic state-by-node TPM can have more than one representation as a state-by-state TPM. However, the mapping can be made to be one-to-one if we assume the TPMs to be conditionally independent. Therefore, given a nondeterministic state-by-node TPM, this function returns the corresponding conditionally independent state-by-state.

Note

The indices of the rows of the state-by-node TPM are assumed to follow the LOLI convention, while the indices of the columns follow the HOLI convention. The indices of the rows and columns of the resulting state-by-state TPM both follow the HOLI convention.

Parameters: tpm (list(list) – A state-by-node TPM with row indices following the LOLI convention and column indices following the HOLI convention. state_by_state_tpm – A state-by-state TPM, with both row and column indices following the HOLI convention. np.ndarray
>>> from pyphi.convert import state_by_node2state_by_state
>>> 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.]])