# partition¶

Functions for generating partitions.

pyphi.partition.partitions(collection)

Generate all set partitions of a collection.

Example

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

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)

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], ], [, [1, 2]], [[0, 2], ]]

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 = '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.mechanism   bipart.mechanism
─────────────────── ✕ ───────────────────
bipart.purview     bipart.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.