# partition¶

Functions for generating partitions.

pyphi.partition.bipartition_indices(N)

Return indices for undirected bipartitions of a sequence.

Parameters:

N (int) – The length of the sequence.

Returns:

A list of tuples containing the indices for each of the two parts.

Return type:

list

Example

>>> N = 3
>>> bipartition_indices(N)
[((), (0, 1, 2)), ((0,), (1, 2)), ((1,), (0, 2)), ((0, 1), (2,))]

pyphi.partition.bipartition(seq, nontrivial=False)

Return a list of bipartitions for a sequence.

Parameters:

a (Iterable) – The sequence to partition.

Returns:

A list of tuples containing each of the two partitions.

Return type:

list[tuple[tuple]]

Example

>>> bipartition((1,2,3))
[((), (1, 2, 3)), ((1,), (2, 3)), ((2,), (1, 3)), ((1, 2), (3,))]

pyphi.partition.directed_bipartition_indices(N)

Return indices for directed bipartitions of a sequence.

Parameters:

N (int) – The length of the sequence.

Returns:

A list of tuples containing the indices for each of the two parts.

Return type:

list

Example

>>> N = 3
>>> directed_bipartition_indices(N)
[((), (0, 1, 2)),
((0,), (1, 2)),
((1,), (0, 2)),
((0, 1), (2,)),
((2,), (0, 1)),
((0, 2), (1,)),
((1, 2), (0,)),
((0, 1, 2), ())]

pyphi.partition.directed_bipartition(seq, nontrivial=False)

Return a list of directed bipartitions for a sequence.

Parameters:

seq (Iterable) – The sequence to partition.

Returns:

A list of tuples containing each of the two parts.

Return type:

list[tuple[tuple]]

Example

>>> directed_bipartition((1, 2, 3))
[((), (1, 2, 3)),
((1,), (2, 3)),
((2,), (1, 3)),
((1, 2), (3,)),
((3,), (1, 2)),
((1, 3), (2,)),
((2, 3), (1,)),
((1, 2, 3), ())]

pyphi.partition.bipartition_of_one(seq)

Generate bipartitions where one part is of length 1.

pyphi.partition.reverse_elements(seq)

Reverse the elements of a sequence.

pyphi.partition.directed_bipartition_of_one(seq)

Generate directed bipartitions where one part is of length 1.

Parameters:

seq (Iterable) – The sequence to partition.

Returns:

A list of tuples containing each of the two partitions.

Return type:

list[tuple[tuple]]

Example

>>> partitions = directed_bipartition_of_one((1, 2, 3))
>>> list(partitions)
[((1,), (2, 3)),
((2,), (1, 3)),
((3,), (1, 2)),
((2, 3), (1,)),
((1, 3), (2,)),
((1, 2), (3,))]

pyphi.partition.directed_tripartition_indices(N)

Return indices for directed tripartitions of a sequence.

Parameters:

N (int) – The length of the sequence.

Returns:

A list of tuples containing the indices for each partition.

Return type:

list[tuple]

Example

>>> N = 1
>>> directed_tripartition_indices(N)
[((0,), (), ()), ((), (0,), ()), ((), (), (0,))]

pyphi.partition.directed_tripartition(seq)

Generator over all directed tripartitions of a sequence.

Parameters:

seq (Iterable) – a sequence.

Yields:

tuple[tuple] – A tripartition of seq.

Example

>>> seq = (2, 5)
>>> list(directed_tripartition(seq))
[((2, 5), (), ()),
((2,), (5,), ()),
((2,), (), (5,)),
((5,), (2,), ()),
((), (2, 5), ()),
((), (2,), (5,)),
((5,), (), (2,)),
((), (5,), (2,)),
((), (), (2, 5))]

pyphi.partition.k_partitions(collection, k)

Generate all k-partitions of a collection.

Example

>>> list(k_partitions(range(3), 2))
[[[0, 1], [2]], [[0], [1, 2]], [[0, 2], [1]]]

class pyphi.partition.PartitionRegistry

Storage for partition schemes registered with PyPhi.

Users can define custom partitions:

Examples

>>> @partition_types.register('NONE')
... def no_partitions(mechanism, purview):
...    return []


And use them by setting config.PARTITION_TYPE = 'NONE'

desc = 'distinction partitions'
pyphi.partition.mip_partitions(mechanism, purview, node_labels=None)

Return a generator over all mechanism-purview partitions, based on the current configuration.

pyphi.partition.mip_bipartitions(mechanism, purview, node_labels=None)

Return an generator of all $$\varphi$$ bipartitions of a mechanism over a purview.

Excludes all bipartitions where one half is entirely empty, e.g:

 A     ∅
─── ✕ ───
B     ∅


is not valid, but

 A     ∅
─── ✕ ───
∅     B


is.

Parameters:
• mechanism (tuple[int]) – The mechanism to partition

• purview (tuple[int]) – The purview to partition

Yields:

Bipartition

Where each bipartition is:

bipart[0].mechanism   bipart[1].mechanism
─────────────────── ✕ ───────────────────
bipart[0].purview     bipart[1].purview


Example

>>> mechanism = (0,)
>>> purview = (2, 3)
>>> for partition in mip_bipartitions(mechanism, purview):
...     print(partition, '\n')
∅     0
─── ✕ ───
2     3

∅     0
─── ✕ ───
3     2

∅     0
─── ✕ ───
2,3    ∅

pyphi.partition.wedge_partitions(mechanism, purview, node_labels=None)

Return an iterator over all wedge partitions.

These are partitions which strictly split the mechanism and allow a subset of the purview to be split into a third partition, e.g.:

 A     B     ∅
─── ✕ ─── ✕ ───
B     C     D


See PARTITION_TYPE in config for more information.

Parameters:
• mechanism (tuple[int]) – A mechanism.

• purview (tuple[int]) – A purview.

Yields:

Tripartition – all unique tripartitions of this mechanism and purview.

pyphi.partition.all_partitions(mechanism, purview, node_labels=None)

Return all possible partitions of a mechanism and purview.

Partitions can consist of any number of parts.

Parameters:
• mechanism (tuple[int]) – A mechanism.

• purview (tuple[int]) – A purview.

Yields:

KPartition – A partition of this mechanism and purview into k parts.

class pyphi.partition.CompletePartition(*parts, node_labels=None)

Represents the partition that completely separates mechanism and purview.

parts
node_labels
pyphi.partition.complete_partition(mechanism, purview)
class pyphi.partition.AtomicPartition(*parts, node_labels=None)

Represents the partition that separates all inter-element connections.

parts
node_labels
pyphi.partition.atomic_partition(elements)
class pyphi.partition.SystemPartitionRegistry

Storage for system partition schemes registered with PyPhi.

Users can define custom partitions:

Examples

>>> @system_partition_types.register('NONE')
... def no_partitions(mechanism, purview):
...    return []


And use them by setting config.SYSTEM_PARTITION_TYPE = 'NONE'

desc = 'system partitions'
pyphi.partition.system_directed_bipartitions(nodes)
pyphi.partition.system_directed_bipartitions_cut_one(nodes)
pyphi.partition.system_bipartitions_simple(nodes, node_labels=None)
pyphi.partition.system_temporal_directed_bipartitions(nodes)
pyphi.partition.system_temporal_directed_bipartitions_cut_one(nodes)
pyphi.partition.general(node_indices, node_labels=None)
pyphi.partition.num_general_partitions(n)
pyphi.partition.general_bidirectional(node_indices, node_labels=None)
pyphi.partition.unidirectional_set_partitions(node_indices, node_labels=None)

Generate all unidirectional set partitions of a set of nodes.

pyphi.partition.system_partitions(nodes, node_labels=None, partition_scheme=None, filter_func=None)

Return the currently configured system partitions for the given nodes.