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'
.For actual causation calculations, use
config.ACTUAL_CAUSATION_MEASURE
.
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 dividebyzero 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
andd2
. 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
andd2
. Return type
float

pyphi.distance.
kld
(d1, d2)¶ Return the KullbackLeibler Divergence (KLD) between two distributions.
 Parameters
d1 (np.ndarray) – The first distribution.
d2 (np.ndarray) – The second distribution.
 Returns
The KLD of
d1
fromd2
. 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.
intrinsic_difference
(p, q)¶ Compute the intrinsic difference (ID) between two distributions.
This is defined as
\[\max_i \left\{ p_i \log_2 \left( \frac{p_i}{q_i} \right) \right\}\]where we define \(p_i \log_2 \left( \frac{p_i}{q_i} \right)\) to be \(0\) when \(p_i = 0\) or \(q_i = 0\).
See the following paper:
Barbosa LS, Marshall W, Streipert S, Albantakis L, Tononi G (2020). A measure for intrinsic information. Sci Rep, 10, 18803. https://doi.org/10.1038/s41598020759434
 Parameters
p (float) – The first probability distribution.
q (float) – The second probability distribution.
 Returns
The intrinsic difference.
 Return type
float

pyphi.distance.
absolute_intrinsic_difference
(p, q)¶ Compute the absolute intrinsic difference (AID) between two distributions.
This is the same as the ID, but with the absolute value taken before the maximum is taken.
See documentation for
intrinsic_difference()
for further details and references. Parameters
p (float) – The first probability distribution.
q (float) – The second probability distribution.
 Returns
The absolute intrinsic difference.
 Return type
float

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.

pyphi.distance.
repertoire_distance
(direction, r1, r2, nb=False)¶ Compute the distance between two repertoires for the given direction.

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
andr2
. Return type
float

pyphi.distance.
pointwise_mutual_information
(p, q)¶ Compute the pointwise mutual information (PMI).
This is defined as
\[\log_2\left(\frac{p}{q}\right)\]when \(p \neq 0\) and \(q \neq 0\), and \(0\) otherwise.
 Parameters
p (float) – The first probability.
q (float) – The second probability.
 Returns
the pointwise mutual information.
 Return type
float

pyphi.distance.
weighted_pointwise_mutual_information
(p, q)¶ Compute the weighted pointwise mutual information (WPMI).
This is defined as
\[p \log_2\left(\frac{p}{q}\right)\]when \(p \neq 0\) and \(q \neq 0\), and \(0\) otherwise.
 Parameters
p (float) – The first probability.
q (float) – The second probability.
 Returns
The weighted pointwise mutual information.
 Return type
float

pyphi.distance.
probability_distance
(p, q, measure=None)¶ Compute the distance between two probabilities in actual causation.
The metric that defines this can be configured with
config.ACTUAL_CAUSATION_MEASURE
. Parameters
p (float) – The first probability.
q (float) – The second probability.
 Keyword Arguments
measure (str) – Optionally override
config.ACTUAL_CAUSATION_MEASURE
with another measure name from the registry. Returns
The probability distance between
p
andq
. Return type
float