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
def test_causal_flow_net(bowtie_network): """Compare the clunky python version with our C++ version""" f = CausalFlowAnalyzer(bowtie_network.factory.world) j = f.analyse_network(bowtie_network) # We just access the 0th element, as we only sent one network for analysis c_joint = numpy.asarray(j)[0] # Test that each of the signals has a complete joint probability. It # should sum to 1.0 for per_reg in c_joint: for per_output in per_reg: assert per_output.sum() == 1.0 # Get the slow version from python. p_joint = get_causal_flow(bowtie_network) # TODO: They should be the same. # This actually fails, but not sure why right now. I think it is minor # stuff. Note that the INFORMATION calculated from these is the same # below. We're not using causal flow right now anyway... # numpy.testing.assert_allclose(p_joint, c_joint) # So should the information. info = Information(j) c_info = numpy.asarray(info)[0] p_info = calc_info_from_probs(p_joint) numpy.testing.assert_allclose(c_info, p_info)