def test_introduced_bias(imputed_cid_introduced_bias: CID) -> None: assert introduced_total_effect(imputed_cid_introduced_bias, "A", "D", "Y", 0, 1) == pytest.approx(-0.5) imputed_cid_introduced_bias.impute_conditional_expectation_decision( "D", "Y") assert introduced_total_effect(imputed_cid_introduced_bias, "A", "D", "Y", 0, 1) == pytest.approx(1 / 3)
def test_trim_example(cid_trim_example: CID) -> None: assert len(cid_trim_example.edges) == 12 assert set(cid_trim_example.get_parents("D2")) == { "Y1", "Y2", "D1", "Z1", "Z2" } req_graph = requisite_graph(cid_trim_example) assert len(req_graph.edges) == 7 assert set(req_graph.get_parents("D2")) == {"Y2"}
def imputed_cid_introduced_bias(cid_introduced_bias: CID) -> CID: cid_introduced_bias.impute_random_policy() return cid_introduced_bias
def imputed_cid_minimal(cid_minimal: CID) -> CID: cid_minimal.impute_random_policy() return cid_minimal
def test_grade_predictor(cid_grade_predictor: CID) -> None: assert set(admits_ri_list(cid_grade_predictor, "P")) == {"R", "HS"} cid_grade_predictor.remove_edge("HS", "P") assert set(admits_ri_list(cid_grade_predictor, "P")) == set()
def test_positive_quantitative_voc(cid_3node: CID) -> None: cid_3node.remove_edge("S", "D") assert quantitative_voc(cid_3node, "S") == pytest.approx( 1) # the agent at D no longer knows the value of S
def test_impute_cond_expectation_decision(cid_introduced_bias: CID) -> None: cid_introduced_bias.impute_conditional_expectation_decision("D", "Y") eu_ce = cid_introduced_bias.expected_utility({}) assert eu_ce == pytest.approx(-0.1666, abs=1e-2)
def test_grade_predictor_removed_edge(cid_grade_predictor: CID) -> None: cid_grade_predictor.remove_edge("HS", "P") assert set(admits_voi_list(cid_grade_predictor, "P")) == {"R", "HS", "E", "Gr"}
def test_scaled_utility(cid_5node_scaled_utility: CID) -> None: cid_5node_scaled_utility.impute_random_policy() assert cid_5node_scaled_utility.expected_utility({}) == 6.0
def test_impute_optimal_policy(cid_insufficient_recall: CID) -> None: cid_insufficient_recall.impute_optimal_policy() assert cid_insufficient_recall.expected_utility({}) == 1
def test_solve_2dec_cid(cid_2dec: CID) -> None: solution = cid_2dec.solve() cpd = solution["D2"] assert np.array_equal(cpd.values, np.array([[1, 0], [0, 1]])) cid_2dec.add_cpds(*list(solution.values())) assert cid_2dec.expected_utility({}) == 1
def test_has_no_sufficient_recall(cid_2dec: CID) -> None: cid_2dec.remove_edge("S2", "D2") assert not cid_2dec.sufficient_recall()
def test_has_sufficient_recall(cid_2dec: CID) -> None: assert cid_2dec.sufficient_recall()