# distance¶

Functions for measuring distances.

class pyphi.distance.MeasureRegistry

Storage for measures registered with PyPhi.

Users can define custom measures:

Examples

>>> @measures.register('ALWAYS_ZERO')
... def always_zero(a, b):
...    return 0


And use them by setting config.MEASURE = 'ALWAYS_ZERO'.

desc = 'measures'
register(name, asymmetric=False)

Decorator for registering a measure with PyPhi.

Parameters: Keyword Arguments: name (string) – The name of the measure. asymmetric (boolean) – True if the measure is asymmetric.
asymmetric()

Return a list of asymmetric measures.

class pyphi.distance.np_suppress

Decorator to suppress NumPy warnings about divide-by-zero and multiplication of NaN.

Note

This should only be used in cases where you are sure that these warnings are not indicative of deeper issues in your code.

pyphi.distance.hamming_emd(d1, d2)

Return the Earth Mover’s Distance between two distributions (indexed by state, one dimension per node) using the Hamming distance between states as the transportation cost function.

Singleton dimensions are sqeezed out.

pyphi.distance.effect_emd(d1, d2)

Compute the EMD between two effect repertoires.

Because the nodes are independent, the EMD between effect repertoires is equal to the sum of the EMDs between the marginal distributions of each node, and the EMD between marginal distribution for a node is the absolute difference in the probabilities that the node is OFF.

Parameters: d1 (np.ndarray) – The first repertoire. d2 (np.ndarray) – The second repertoire. The EMD between d1 and d2. float
pyphi.distance.l1(d1, d2)

Return the L1 distance between two distributions.

Parameters: d1 (np.ndarray) – The first distribution. d2 (np.ndarray) – The second distribution. The sum of absolute differences of d1 and d2. float
pyphi.distance.kld(d1, d2)

Return the Kullback-Leibler Divergence (KLD) between two distributions.

Parameters: d1 (np.ndarray) – The first distribution. d2 (np.ndarray) – The second distribution. The KLD of d1 from d2. float
pyphi.distance.entropy_difference(d1, d2)

Return the difference in entropy between two distributions.

pyphi.distance.psq2(d1, d2)

Compute the PSQ2 measure.

Parameters: d1 (np.ndarray) – The first distribution. d2 (np.ndarray) – The second distribution.
pyphi.distance.mp2q(p, q)

Compute the MP2Q measure.

Parameters: p (np.ndarray) – The unpartitioned repertoire q (np.ndarray) – The partitioned repertoire
pyphi.distance.bld(p, q)

Compute the Buzz Lightyear (Billy-Leo) Divergence.

pyphi.distance.directional_emd(direction, d1, d2)

Compute the EMD between two repertoires for a given direction.

The full EMD computation is used for cause repertoires. A fast analytic solution is used for effect repertoires.

Parameters: direction (Direction) – CAUSE or EFFECT. d1 (np.ndarray) – The first repertoire. d2 (np.ndarray) – The second repertoire. The EMD between d1 and d2, rounded to PRECISION. float ValueError – If direction is invalid.
pyphi.distance.repertoire_distance(direction, r1, r2)

Compute the distance between two repertoires for the given direction.

Parameters: direction (Direction) – CAUSE or EFFECT. r1 (np.ndarray) – The first repertoire. r2 (np.ndarray) – The second repertoire. The distance between d1 and d2, rounded to PRECISION. float
pyphi.distance.system_repertoire_distance(r1, r2)

Compute the distance between two repertoires of a system.

Parameters: r1 (np.ndarray) – The first repertoire. r2 (np.ndarray) – The second repertoire. The distance between r1 and r2. float