示例#1
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
示例#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
示例#3
0
def test_mip_ordering():
    phi1 = models.Mip(direction=None,
                      mechanism=(),
                      purview=(),
                      partition=None,
                      unpartitioned_repertoire=None,
                      partitioned_repertoire=None,
                      phi=1.0)
    different_phi1 = models.Mip(direction='different',
                                mechanism=(),
                                purview=(),
                                partition=0,
                                unpartitioned_repertoire=None,
                                partitioned_repertoire=None,
                                phi=1.0)
    phi2 = models.Mip(direction=0,
                      mechanism=(),
                      purview=(),
                      partition='stilldifferent',
                      unpartitioned_repertoire=None,
                      partitioned_repertoire=None,
                      phi=1.0 + constants.EPSILON * 2)
    assert phi1 < phi2
    assert phi2 > phi1
    assert phi1 <= phi2
    assert phi2 >= phi1
    assert phi1 <= different_phi1
    assert phi1 >= different_phi1
示例#4
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))
示例#5
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
示例#6
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))
示例#7
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
示例#8
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)
示例#9
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))
示例#10
0
def test_mip_repr_str():
    mip = models.Mip(direction=None,
                     mechanism=(),
                     purview=(),
                     unpartitioned_repertoire=None,
                     partitioned_repertoire=None,
                     phi=0.0,
                     partition=())
    print(repr(mip))
    print(str(mip))
示例#11
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
示例#12
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)
示例#13
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
示例#14
0
def mip(phi=1.0, dir=None, mech=(), purv=(), partition=None,
        unpartitioned_repertoire=None, partitioned_repertoire=None):
    return models.Mip(phi=phi, direction=dir, mechanism=mech,
                      purview=purv, partition=partition,
                      unpartitioned_repertoire=unpartitioned_repertoire,
                      partitioned_repertoire=partitioned_repertoire)