Beispiel #1
0
def test_causal_flow_pop(bowtie_database, bowtie_env_categories):
    # This what it was evolved to do (see the generate.py file)
    pop = bowtie_database.population
    f_flow = CausalFlowAnalyzer(bowtie_database.world)
    j_flow = f_flow.analyse_collection(pop)
    flow = Information(j_flow)
    c_flow = numpy.asarray(flow)

    f_mut = MutualInfoAnalyzer(bowtie_database.world, bowtie_env_categories)
    j_mut = f_mut.analyse_collection(pop)
    mut = Information(j_mut)
    c_mut = numpy.asarray(mut)

    # Let's just try the first few
    for i, n in enumerate(pop):
        p_joint = get_causal_flow(n)
        p_flow = calc_info_from_probs(p_joint)
        numpy.testing.assert_allclose(c_flow[i], p_flow)

        _, p_mut = calc_mutual_info(n, bowtie_env_categories)
        numpy.testing.assert_allclose(c_mut[i, :, 0], p_mut)

        # It takes too long....
        if i == 50:
            break
Beispiel #2
0
def test_mutual_info_cython(bowtie_network, bowtie_env_categories):
    f = MutualInfoAnalyzer(bowtie_network.factory.world,
                           bowtie_env_categories)
    j = f.analyse_network(bowtie_network)
    p_joint, p_info = calc_mutual_info(bowtie_network,
                                       bowtie_env_categories)
    info = Information(j)
    c_info = numpy.asarray(info)[0]

    # Need to account for different shape
    numpy.testing.assert_allclose(c_info[:, 0], p_info)