Example #1
0
def test_mice_ordering_by_purview():
    small = models.Mice(mip(purv=(1, 2)))
    big = models.Mice(mip(purv=(1, 2, 3)))
    assert small < big
    assert small <= big
    assert big > small
    assert big >= small
Example #2
0
def test_mice_equality():
    phi = 1.0
    mice = models.Mice(
        models.Mip(direction=None,
                   mechanism=(),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=phi,
                   partition=()))
    close_enough = models.Mice(
        models.Mip(direction=None,
                   mechanism=(),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=(phi - constants.EPSILON / 2),
                   partition=()))
    not_quite = models.Mice(
        models.Mip(direction=None,
                   mechanism=(),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=(phi - constants.EPSILON * 2),
                   partition=()))
    assert mice == close_enough
    assert mice != not_quite
Example #3
0
def test_mice_ordering_by_phi():
    phi1 = models.Mice(
        models.Mip(direction=None,
                   mechanism=(),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=1.0,
                   partition=()))
    different_phi1 = models.Mice(
        models.Mip(direction='different',
                   mechanism=(),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=1.0,
                   partition=()))
    phi2 = models.Mice(
        models.Mip(direction=None,
                   mechanism=(),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=(1.0 + constants.EPSILON * 2),
                   partition=()))
    assert phi1 < phi2
    assert phi2 > phi1
    assert phi1 <= phi2
    assert phi2 >= phi1
    assert phi1 <= different_phi1
    assert phi1 >= different_phi1
Example #4
0
def test_mice_odering_by_mechanism():
    small = models.Mice(mip(mech=(1,)))
    big = models.Mice(mip(mech=(1, 2, 3)))
    assert small < big
    assert small <= big
    assert big > small
    assert big >= small
    assert big != small
Example #5
0
def test_null_concept(s, flushcache, restore_fs_cache):
    flushcache()
    cause = models.Mice(models.Mip(
        unpartitioned_repertoire=s.unconstrained_cause_repertoire(()),
        phi=0, direction=DIRECTIONS[PAST], mechanism=(), purview=(),
        partition=None, partitioned_repertoire=None))
    effect = models.Mice(models.Mip(
        unpartitioned_repertoire=s.unconstrained_effect_repertoire(()),
        phi=0, direction=DIRECTIONS[FUTURE], mechanism=(), purview=(),
        partition=None, partitioned_repertoire=None))
    assert (s.null_concept ==
            models.Concept(mechanism=(), phi=0, cause=cause, effect=effect,
                           subsystem=s))
Example #6
0
def test_mice_ordering_by_phi():
    phi1 = models.Mice(mip())
    different_phi1 = models.Mice(mip(dir='different'))
    phi2 = models.Mice(mip(phi=(1.0 + constants.EPSILON * 2), partition=()))
    assert phi1 < phi2
    assert phi2 > phi1
    assert phi1 <= phi2
    assert phi2 >= phi1

    with pytest.raises(TypeError):
        phi1 <= different_phi1

    with pytest.raises(TypeError):
        phi1 >= different_phi1
Example #7
0
def test_concept_equality_repertoires(s):
    phi = 1.0
    mice1 = models.Mice(models.Mip(
        direction=None, mechanism=(), purview=(),
        unpartitioned_repertoire=np.array([1, 2]), partitioned_repertoire=(),
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    mice2 = models.Mice(models.Mip(
        direction=None, mechanism=(), purview=(),
        unpartitioned_repertoire=np.array([0, 0]), partitioned_repertoire=None,
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    concept = models.Concept(mechanism=(), cause=mice1, effect=mice2,
                             subsystem=s, phi=phi)
    another = models.Concept(mechanism=(), cause=mice2, effect=mice1,
                             subsystem=s, phi=phi)
    assert concept != another
Example #8
0
def test_damaged(s):
    # Build cut subsystem from s
    cut = models.Cut((0,), (1, 2))
    subsys = Subsystem(s.network, s.state, s.node_indices, cut=cut)

    # Cut splits mechanism:
    mip = mock.MagicMock(mechanism=(0, 1), purview=(1, 2), direction='future')
    mice = models.Mice(mip)
    assert mice.damaged_by_cut(subsys)
    assert not mice.damaged_by_cut(s)

    # Cut splits mechanism & purview (but not *only* mechanism)
    mip = mock.MagicMock(mechanism=(0,), purview=(1, 2), direction='future')
    mice = models.Mice(mip)
    assert mice.damaged_by_cut(subsys)
    assert not mice.damaged_by_cut(s)
Example #9
0
def test_mice_repr_str():
    mice = models.Mice(models.Mip(
        direction=None, mechanism=(), purview=(),
        unpartitioned_repertoire=None, partitioned_repertoire=None,
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    print(repr(mice))
    print(str(mice))
Example #10
0
def test_constellation_distance_uses_simple_vs_emd(mock_emd_distance,
                                                   mock_simple_distance, s):
    """Quick check that we use the correct constellation distance function.

    If the two constellations differ only in that some concepts have
    moved to the null concept and all other concepts are the same then
    we use the simple constellation distance. Otherwise, use the EMD.
    """
    make_mice = lambda: models.Mice(models.Mip(
        phi=None, direction=None, mechanism=None,
        purview=None, partition=None,
        unpartitioned_repertoire=None,
        partitioned_repertoire=None))

    lone_concept = models.Concept(cause=make_mice(), effect=make_mice(),
                                  mechanism=(0, 1))
    # lone concept -> null concept
    compute.constellation_distance((lone_concept,), ())
    assert mock_emd_distance.called is False
    assert mock_simple_distance.called is True
    mock_simple_distance.reset_mock()

    other_concept = models.Concept(cause=make_mice(), effect=make_mice(),
                                   mechanism=(0, 1, 2))
    # different concepts in constellation
    compute.constellation_distance((lone_concept,), (other_concept,))
    assert mock_emd_distance.called is True
    assert mock_simple_distance.called is False
Example #11
0
def test_relevant_connections(s, subsys_n1n2):
    mip = mock.Mock(mechanism=(0,), purview=(1,), direction='past')
    mice = models.Mice(mip)
    answer = np.array([
        [0, 0, 0],
        [1, 0, 0],
        [0, 0, 0],
    ])
    assert np.array_equal(mice._relevant_connections(s), answer)

    mip = mock.Mock(mechanism=(1,), purview=(1, 2), direction='future')
    mice = models.Mice(mip)
    answer = np.array([
        [1, 1],
        [0, 0],
    ])
    assert np.array_equal(mice._relevant_connections(subsys_n1n2), answer)
Example #12
0
def test_concept_hashing(s):
    mice = models.Mice(models.Mip(
        direction=None, mechanism=(0, 1, 2), purview=(0, 1, 2),
        unpartitioned_repertoire=None, partitioned_repertoire=None,
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    concept = models.Concept(
        mechanism=(0, 1, 2), cause=mice, effect=mice, subsystem=s, phi=0.0)
    hash(concept)
Example #13
0
def test_concept_repr_str():
    mice = models.Mice(models.Mip(
        direction=None, mechanism=(), purview=(),
        unpartitioned_repertoire=None, partitioned_repertoire=None,
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    concept = models.Concept(
        mechanism=(), cause=mice, effect=mice,
        subsystem=None, phi=0.0)
    print(repr(concept))
    print(str(concept))
Example #14
0
def test_concept_equality_one_subsystem_is_subset_of_another(s, subsys_n1n2):
    phi = 1.0
    mice = models.Mice(models.Mip(
        direction=None, mechanism=(), purview=(1, 2),
        unpartitioned_repertoire=(), partitioned_repertoire=(),
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    concept = models.Concept(mechanism=(2,), cause=mice, effect=mice,
                             subsystem=s, phi=phi)
    another = models.Concept(mechanism=(2,), cause=mice, effect=mice,
                             subsystem=subsys_n1n2, phi=phi)
    assert concept == another
Example #15
0
def test_concept_hashing_one_subsystem_is_subset_of_another(s, subsys_n1n2):
    phi = 1.0
    mice = models.Mice(models.Mip(
        direction=None, mechanism=(), purview=(1, 2),
        unpartitioned_repertoire=(), partitioned_repertoire=(),
        phi=0.0, partition=(models.Part((), ()), models.Part((), ()))))
    concept = models.Concept(mechanism=(2,), cause=mice, effect=mice,
                             subsystem=s, phi=phi)
    another = models.Concept(mechanism=(2,), cause=mice, effect=mice,
                             subsystem=subsys_n1n2, phi=phi)
    assert hash(concept) == hash(another)
    assert(len(set([concept, another])) == 1)
Example #16
0
def test_mice_odering_by_mechanism():
    small = models.Mice(
        models.Mip(direction=None,
                   mechanism=(1, 2),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=1.0,
                   partition=()))
    big = models.Mice(
        models.Mip(direction=None,
                   mechanism=(1, 2, 3),
                   purview=(),
                   unpartitioned_repertoire=None,
                   partitioned_repertoire=None,
                   phi=1.0,
                   partition=()))
    assert small < big
    assert small <= big
    assert big > small
    assert big >= small
    assert big != small
Example #17
0
def test_mice_equality():
    mice = models.Mice(mip(phi=1.0))
    close_enough = models.Mice(mip(phi=(1.0 - constants.EPSILON / 2)))
    not_quite = models.Mice(mip(phi=(1.0 - constants.EPSILON * 2)))
    assert mice == close_enough
    assert mice != not_quite