# 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

name (string) – The name of the measure.

Keyword Arguments

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.

Returns

The EMD between d1 and d2.

Return type

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.

Returns

The sum of absolute differences of d1 and d2.

Return type

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.

Returns

The KLD of d1 from d2.

Return type

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.klm(p, q)

Compute the KLM 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
Returns

The EMD between d1 and d2, rounded to PRECISION.

Return type

float

Raises

ValueError – If direction is invalid.

pyphi.distance.repertoire_distance(direction, r1, r2)

Compute the distance between two repertoires for the given direction.

Parameters
Returns

The distance between d1 and d2, rounded to PRECISION.

Return type

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.

Returns

The distance between r1 and r2.

Return type

float