Functions for manipulating transition probability matrices.


Indices of nodes in the TPM.


Return True if tpm is in state-by-state form, otherwise False.

pyphi.tpm.condition_tpm(tpm, fixed_nodes, state)

Return a TPM conditioned on the given fixed node indices, whose states are fixed according to the given state-tuple.

The dimensions of the new TPM that correspond to the fixed nodes are collapsed onto their state, making those dimensions singletons suitable for broadcasting. The number of dimensions of the conditioned TPM will be the same as the unconditioned TPM.


Broadcast a state-by-node TPM so that singleton dimensions are expanded over the full network.

pyphi.tpm.marginalize_out(indices, tpm)

Marginalize out a node from a TPM.

  • indices (list[int]) – The indices of nodes to be marginalized out.
  • tpm (np.ndarray) – The TPM to marginalize the node out of.

A TPM with the same number of dimensions, with the nodes marginalized out.

Return type:


pyphi.tpm.infer_edge(tpm, a, b, contexts)

Infer the presence or absence of an edge from node A to node B.

Let S be the set of all nodes in a network. Let A’ = S - {A}. We call the state of A’ the context C of A. There is an edge from A to B if there exists any context C(A) such that p(B | C(A), A=0) =/= p(B | C(A), A=1).

  • tpm (np.ndarray) – The TPM in state-by-node, n-dimensional form.
  • a (int) – The index of the putative source node.
  • b (int) – The index of the putative sink node.

True if the edge A->B exists, False otherwise.

Return type:



Infer the connectivity matrix associated with a state-by-node TPM in n-dimensional form.