コード例 #1
0
def test_eq():
    phi = 0.5
    close_enough = phi - constants.EPSILON / 2
    not_quite = phi - constants.EPSILON * 2
    assert utils.eq(phi, close_enough)
    assert not utils.eq(phi, not_quite)
    assert not utils.eq(phi, (phi - phi))
コード例 #2
0
ファイル: test_utils.py プロジェクト: wmayner/pyphi
def test_eq():
    phi = 0.5
    close_enough = phi - constants.EPSILON / 2
    not_quite = phi - constants.EPSILON * 2
    assert utils.eq(phi, close_enough)
    assert not utils.eq(phi, not_quite)
    assert not utils.eq(phi, (phi - phi))
コード例 #3
0
def test_rule152_complexes_no_caching(rule152):
    net = rule152
    # Mapping from index of a PyPhi subsystem in network.subsystems to the
    # index of the corresponding subsystem in the Matlab list of subsets
    perm = {0: 0, 1: 1, 2: 3, 3: 7, 4: 15, 5: 2, 6: 4, 7: 8, 8: 16, 9: 5, 10:
            9, 11: 17, 12: 11, 13: 19, 14: 23, 15: 6, 16: 10, 17: 18, 18: 12,
            19: 20, 20: 24, 21: 13, 22: 21, 23: 25, 24: 27, 25: 14, 26: 22, 27:
            26, 28: 28, 29: 29, 30: 30}
    with open('test/data/rule152_results.pkl', 'rb') as f:
        results = pickle.load(f)

    # Don't use concept caching for this test.
    constants.CACHE_CONCEPTS = False

    for state, result in results.items():
        # Empty the DB.
        _flushdb()
        # Unpack the state from the results key.
        # Generate the network with the state we're testing.
        net = Network(rule152.tpm, state, cm=rule152.cm)
        # Comptue all the complexes, leaving out the first (empty) subsystem
        # since Matlab doesn't include it in results.
        complexes = list(compute.complexes(net))[1:]
        # Check the phi values of all complexes.
        zz = [(sia.phi, result['subsystem_phis'][perm[i]]) for i, sia in
            list(enumerate(complexes))]
        diff = [utils.eq(sia.phi, result['subsystem_phis'][perm[i]]) for
                i, sia in list(enumerate(complexes))]
        assert all(utils.eq(sia.phi, result['subsystem_phis'][perm[i]])
                   for i, sia in list(enumerate(complexes))[:])
        # Check the major complex in particular.
        major = compute.major_complex(net)
        # Check the phi value of the major complex.
        assert utils.eq(major.phi, result['phi'])
        # Check that the nodes are the same.
        assert (major.subsystem.node_indices ==
                complexes[result['major_complex'] - 1].subsystem.node_indices)
        # Check that the concept's phi values are the same.
        result_concepts = [c for c in result['concepts']
                           if c['is_irreducible']]
        z = list(zip([c.phi for c in major.ces],
                     [c['phi'] for c in result_concepts]))
        diff = [i for i in range(len(z)) if not utils.eq(z[i][0], z[i][1])]
        assert all(list(utils.eq(c.phi, result_concepts[i]['phi']) for i, c
                        in enumerate(major.ces)))
        # Check that the minimal cut is the same.
        assert major.cut == result['cut']
コード例 #4
0
ファイル: test_relations.py プロジェクト: wesmith/pyphi
def test_PQR_relations():
    with config.override(
            PARTITION_TYPE="TRI",
            MEASURE="BLD",
    ):
        PQR = examples.PQR()
        ces = compute.ces(PQR)
        separated_ces = list(relations.separate_ces(ces))
        results = list(relations.relations(PQR, ces))

        # NOTE: these phi values are in nats, not bits!
        answers = [
            [(0, 4), 0.6931471805599452, [(2, )]],
            [(0, 6), 0.6931471805599452, [(2, )]],
            [(1, 2), 0.3465735902799726, [(0, )]],
            [(1, 3), 0.3465735902799726, [(0, )]],
            [(1, 7), 0.3465735902799726, [(0, )]],
            [(2, 3), 0.3465735902799726, [(0, ), (1, ), (0, 1)]],
            [(2, 4), 0.3465735902799726, [(1, )]],
            [(2, 6), 0.3465735902799726, [(0, ), (1, ), (0, 1)]],
            [(2, 7), 0.3465735902799726, [(0, ), (1, ), (0, 1)]],
            [(3, 7), 0.693147180559945, [(0, 1)]],
            [(4, 6), 1.3862943611198901, [(1, 2)]],
            [(5, 7), 0.6931471805599452, [(2, )]],
            [(0, 4, 6), 0.6931471805599452, [(2, )]],
            [(1, 2, 3), 0.3465735902799726, [(0, )]],
            [(1, 2, 7), 0.3465735902799726, [(0, )]],
            [(1, 3, 7), 0.3465735902799726, [(0, )]],
            [(2, 3, 7), 0.3465735902799726, [(0, ), (1, ), (0, 1)]],
            [(2, 4, 6), 0.3465735902799726, [(1, )]],
            [(1, 2, 3, 7), 0.3465735902799726, [(0, )]],
        ]

        def base2(x):
            return x / np.log(2.0)

        for result, answer in zip(results, answers):
            subset, phi, purviews = answer
            subset = tuple(separated_ces[i] for i in subset)
            relata = relations.Relata(PQR, subset)
            assert set(purviews) == set(result.ties)
            assert utils.eq(base2(phi), result.phi)
            assert relata == result.relata
コード例 #5
0
def test_phi_max(cut, expected_phi_max, mechanism):
    assert eq(subsystem[cut].phi_max(mechanism), expected_phi_max)
コード例 #6
0
def test_phi_max(cut, expected_phi_max, mechanism):
    assert eq(subsystem[cut].phi_max(mechanism), expected_phi_max)