Пример #1
0
def test_json_deserialization(s, transition):
    objects = [
        Direction.CAUSE,
        s.network,  # Network
        s,  # Subsystem
        models.Bipartition(models.Part((0, ), ()), models.Part((1, ), (2, 3))),
        models.KPartition(models.Part((0, ), ()), models.Part((1, ), (2, 3))),
        models.Tripartition(models.Part((0, ), ()), models.Part((1, ), (2, 3)),
                            models.Part((3, ), (4, ))),
        models.Cut((0, ), (2, )),
        models.NullCut((0, 1)),
        models.KCut(
            Direction.CAUSE,
            models.KPartition(models.Part((0, ), ()), models.Part((1, ),
                                                                  (2, 3)))),
        s.concept((1, 2)),
        s.concept((1, )),
        compute.ces(s),
        compute.sia(s),
        transition,
        transition.find_actual_cause((0, ), (0, )),
        actual.account(transition),
        actual.sia(transition)
    ]
    for o in objects:
        loaded = jsonify.loads(jsonify.dumps(o))
        assert loaded == o
Пример #2
0
def test_parallel_and_sequential_ces_are_equal(s, micro_s, macro_s):
    with config.override(PARALLEL_CONCEPT_EVALUATION=False):
        c = compute.ces(s)
        c_micro = compute.ces(micro_s)
        c_macro = compute.ces(macro_s)

    with config.override(PARALLEL_CONCEPT_EVALUATION=True):
        assert set(c) == set(compute.ces(s))
        assert set(c_micro) == set(compute.ces(micro_s))
        assert set(c_macro) == set(compute.ces(macro_s))
Пример #3
0
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
Пример #4
0
def test_maximal_states():
    with config.override(
            PARTITION_TYPE="TRI",
            MEASURE="BLD",
    ):
        subsystem = examples.PQR()
        ces = relations.separate_ces(compute.ces(subsystem))
        results = [relations.maximal_state(mice) for mice in ces]
        answers = [
            np.array([[0, 0, 0]]),
            np.array([[0, 0, 0]]),
            np.array([[0, 0, 0], [1, 1, 0]]),
            np.array([[0, 0, 0]]),
            np.array([[0, 1, 0]]),
            np.array([[0, 0, 1]]),
            np.array([[1, 1, 0]]),
            np.array([[0, 0, 1]]),
        ]
        for result, answer in zip(results, answers):
            print(result)
            print(answer)
            assert np.array_equal(result, answer)
Пример #5
0
def micro_s_ComputeSystemIrreducibility(micro_s):
    ces = compute.ces(micro_s)
    cuts = sia_bipartitions(micro_s.node_indices)
    return ComputeSystemIrreducibility(cuts, micro_s, ces)
Пример #6
0
def s_noised_ComputeSystemIrreducibility(s_noised):
    ces = compute.ces(s_noised)
    cuts = sia_bipartitions(s_noised.node_indices)
    return ComputeSystemIrreducibility(cuts, s_noised, ces)
Пример #7
0
def standard_ComputeSystemIrreducibility(s):
    ces = compute.ces(s)
    cuts = sia_bipartitions(s.node_indices)
    return ComputeSystemIrreducibility(cuts, s, ces)
Пример #8
0
def test_ces_concepts_share_the_same_subsystem(parallel, s):
    with config.override(PARALLEL_CONCEPT_EVALUATION=parallel):
        ces = compute.ces(s)
        for concept in ces:
            assert concept.subsystem is ces.subsystem