예제 #1
0
def test_get_children():
    hyp_space = utils.create_graph_hyp_space()

    dag_one = hyp_space["common_cause_1"]

    assert np.array_equal(dag_one.get_children(
        0, dag_one.graph), np.array([1, 2]))
    assert np.array_equal(dag_one.get_children(1, dag_one.graph), np.array([]))
    assert np.array_equal(dag_one.get_children(2, dag_one.graph), np.array([]))

    dag_two = hyp_space["common_effect_1"]

    assert np.array_equal(dag_two.get_children(
        0, dag_two.graph), np.array([2]))
    assert np.array_equal(dag_two.get_children(
        1, dag_two.graph), np.array([2]))
    assert np.array_equal(dag_two.get_children(2, dag_two.graph), np.array([]))

    dag_three = hyp_space["causal_chain_1"]

    assert np.array_equal(dag_three.get_children(
        0, dag_three.graph), np.array([1]))
    assert np.array_equal(dag_three.get_children(
        1, dag_three.graph), np.array([2]))
    assert np.array_equal(dag_three.get_children(
        2, dag_three.graph), np.array([]))
예제 #2
0
def test_graph_active_learner_two():
    t = 0.8  # transmission rate
    b = 0.0  # background rate

    hyp_space = utils.create_graph_hyp_space(t=t, b=b)
    example_two_graph_names = ['causal_chain_1', 'causal_chain_2']
    example_two_graphs = [hyp_space[graph_name]
                          for graph_name in example_two_graph_names]

    gal_two = GraphActiveLearner(example_two_graphs)
    gal_two.update_posterior()

    true_eig = np.array([0.11594429, 0.44202786, 0.44202786])

    assert np.allclose(true_eig, gal_two.expected_information_gain())
예제 #3
0
def test_graph_active_learner_three():
    t = 0.8  # transmission rate
    b = 0.0  # background rate

    hyp_space = utils.create_graph_hyp_space(t=t, b=b)
    example_three_graph_names = ['common_effect_2', 'single_link_1']
    example_three_graphs = [hyp_space[graph_name]
                            for graph_name in example_three_graph_names]

    gal_three = GraphActiveLearner(example_three_graphs)
    gal_three.update_posterior()

    true_eig = np.array([0.0, 0.0, 1.0])

    assert np.allclose(true_eig, gal_three.expected_information_gain())
예제 #4
0
def test_graph_active_learner_one():
    t = 0.8  # transmission rate
    b = 0.0  # background rate

    # example one
    hyp_space = utils.create_graph_hyp_space(t=t, b=b)
    example_one_graph_names = ['common_cause_1', 'common_cause_2']
    example_one_graphs = [hyp_space[graph_name]
                          for graph_name in example_one_graph_names]

    gal_one = GraphActiveLearner(example_one_graphs)
    gal_one.update_posterior()

    true_eig = np.array([0.5, 0.5, 0])

    assert np.array_equal(true_eig, gal_one.expected_information_gain())
예제 #5
0
def test_intervene():
    t = 0.8
    b = 0.01
    hyp_space = utils.create_graph_hyp_space(t, b)

    common_effect_1 = hyp_space["common_effect_1"]

    common_effect_intervene_0 = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 0]])
    common_effect_intervene_1 = np.array([[0, 0, 1], [0, 0, 1], [0, 0, 0]])
    common_effect_intervene_2 = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])

    common_effect_1.intervene(0)
    assert np.array_equal(
        common_effect_1.intervened_graph, common_effect_intervene_0)

    common_effect_1.intervene(1)
    assert np.array_equal(
        common_effect_1.intervened_graph, common_effect_intervene_1)

    common_effect_1.intervene(2)
    assert np.array_equal(
        common_effect_1.intervened_graph, common_effect_intervene_2)

    causal_chain_1 = hyp_space["causal_chain_1"]

    causal_chain_intervene_0 = np.array([[0, 1, 0], [0, 0, 1], [0, 0, 0]])
    causal_chain_intervene_1 = np.array([[0, 0, 0], [0, 0, 1], [0, 0, 0]])
    causal_chain_intervene_2 = np.array([[0, 1, 0], [0, 0, 0], [0, 0, 0]])

    causal_chain_1.intervene(0)
    assert np.array_equal(
        causal_chain_1.intervened_graph, causal_chain_intervene_0)

    causal_chain_1.intervene(1)
    assert np.array_equal(
        causal_chain_1.intervened_graph, causal_chain_intervene_1)

    causal_chain_1.intervene(2)
    assert np.array_equal(
        causal_chain_1.intervened_graph, causal_chain_intervene_2)