Skip to content

Commit

Permalink
Merge branch 'hotfix/0.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
wmayner committed Jul 22, 2015
2 parents 9b55b65 + 08650a7 commit 40c5303
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/examples/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ our subsystem:

>>> phi = pyphi.compute.big_phi(subsystem)
>>> phi
2.312496
2.312497

If we want to take a deeper look at the integrated-information-theoretic
properties of our network, we can access all the intermediate quantities and
Expand Down
2 changes: 1 addition & 1 deletion install_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.8.1, <2.0.0
scipy>=0.13.3, <1.0.0
pyemd>=0.0.9, <1.0.0
pyemd>=0.1.1, <1.0.0
joblib>=0.8.0a3, <1.0.0
psutil>=2.1.1, <3.0.0
marbl-python>=2.0.0, <3.0.0
Expand Down
2 changes: 1 addition & 1 deletion pyphi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"""

__title__ = 'pyphi'
__version__ = '0.7.0'
__version__ = '0.7.1'
__description__ = 'Python library for computing integrated information.',
__author__ = 'Will Mayner'
__author_email__ = '[email protected]'
Expand Down
75 changes: 53 additions & 22 deletions pyphi/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,33 +201,64 @@ def _constellation_distance_simple(C1, C2, subsystem):
def _constellation_distance_emd(unique_C1, unique_C2, subsystem):
"""Return the distance between two constellations in concept-space,
using the generalized EMD."""
# We need the null concept to be the partitioned constellation, in case a
# concept is destroyed by a cut (and needs to be moved to the null
# concept).
unique_C2 = unique_C2 + [subsystem.null_concept]
# Get the concept distances from the concepts in the unpartitioned
# constellation to the partitioned constellation.
# Get the pairwise distances between the concepts in the unpartitioned and
# partitioned constellations.
distances = np.array([
[concept_distance(i, j) for j in unique_C2]
for i in unique_C1
[concept_distance(i, j) for j in unique_C2] for i in unique_C1
])
# We need distances from all concepts---in both the unpartitioned and
# partitioned constellations---to the null concept, because:
# - often a concept in the unpartitioned constellation is destroyed by a
# cut (and needs to be moved to the null concept); and
# - in certain cases, the partitioned system will have *greater* sum of
# small-phi, even though it has less big-phi, which means that some
# partitioned-constellation concepts will be moved to the null concept.
distances_to_null = np.array([
concept_distance(c, subsystem.null_concept)
for constellation in (unique_C1, unique_C2) for c in constellation
])
# Now we make the distance matrix.
# It has blocks of zeros in the upper left and bottom right to make the
# distance matrix square, and to ensure that we're only moving mass from
# the unpartitioned constellation to the partitioned constellation.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Now we make the distance matrix, which will look like this:
#
# C1 C2 0
# +~~~~~~~~+~~~~~~~~+~~~+
# | | | |
# C1 | X | D | |
# | | | |
# +~~~~~~~~+~~~~~~~~+ D |
# | | | n |
# C2 | D' | X | |
# | | | |
# +~~~~~~~~+~~~~~~~~+~~~|
# 0 | Dn' | X |
# +~~~~~~~~~~~~~~~~~~~~~+
#
# The diagonal blocks marked with an X are set to a value larger than any
# pairwise distance between concepts. This ensures that concepts are never
# moved to another concept within their own constellation; they must always
# go either from one constellation to another, or to the null concept N.
# The D block is filled with the pairwise distances between the two
# constellations, and Dn is filled with the distances from each concept to
# the null concept.
N, M = len(unique_C1), len(unique_C2)
distance_matrix = np.zeros([N + M] * 2)
# Top-right block.
distance_matrix[:N, N:] = distances
# Bottom-left block.
distance_matrix[N:, :N] = distances.T
# Add one to the side length for the null concept distances.
distance_matrix = np.empty([N + M + 1] * 2)
# Ensure that concepts are never moved within their own constellation.
distance_matrix[:] = np.max(distances) + 1
# Set the top-right block to the pairwise constellation distances.
distance_matrix[:N, N:-1] = distances
# Set the bottom-left block to the same, but transposed.
distance_matrix[N:-1, :N] = distances.T
# Do the same for the distances to the null concept.
distance_matrix[-1, :-1] = distances_to_null
distance_matrix[:-1, -1] = distances_to_null.T
distance_matrix[-1, -1] = 0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Construct the two phi distributions.
d1 = [c.phi for c in unique_C1] + [0] * M
d2 = [0] * N + [c.phi for c in unique_C2]
# Calculate how much phi disappeared and assign it to the null concept (the
# null concept is the last element in the second distribution).
# Construct the two phi distributions, with an entry at the end for the
# null concept.
d1 = [c.phi for c in unique_C1] + [0] * M + [0]
d2 = [0] * N + [c.phi for c in unique_C2] + [0]
# Calculate how much phi disappeared and assign it to the null concept.
d2[-1] = sum(d1) - sum(d2)
# The sum of the two signatures should be the same.
assert utils.phi_eq(sum(d1), sum(d2))
Expand Down
2 changes: 1 addition & 1 deletion pyphi/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def emergence(network):
"""
micro_phi = compute.main_complex(network).phi
partitions = list_all_partitions(network)
max_phi = 0
max_phi = float('-inf')
for partition in partitions:
groupings = list_all_groupings(partition)
for grouping in groupings:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

setup(
name='pyphi',
version='0.7.0',
version='0.7.1',
description='A Python library for computing integrated information.',
author='Will Mayner',
author_email='[email protected]',
Expand Down
4 changes: 2 additions & 2 deletions test/test_big_phi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

standard_answer = {
'phi': 2.312496,
'phi': 2.312497,
'unpartitioned_small_phis': {
(1,): 0.25,
(2,): 0.5,
Expand Down Expand Up @@ -106,7 +106,7 @@


rule152_answer = {
'phi': 6.974947,
'phi': 6.974952,
'unpartitioned_small_phis': {
(0,): 0.125002,
(1,): 0.125002,
Expand Down

0 comments on commit 40c5303

Please sign in to comment.