Пример #1
0
 def test_introduced_bias_reversed_sign(self) -> None:
     cbn = CausalBayesianNetwork([("A", "D"), ("A", "Y")])
     cbn.add_cpds(A=discrete_uniform([0, 1]), D=lambda a: 0, Y=lambda a: a)
     assert introduced_total_effect(cbn, "A", "D", "Y") == pytest.approx(-1)
     cbn.add_cpds(Y=lambda a: -a)
     assert introduced_total_effect(
         cbn, "A", "D", "Y", adapt_marginalized=True) == pytest.approx(-1)
Пример #2
0
    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)
Пример #3
0
 def test_introduced_bias_reversed_sign(self) -> None:
     cbn = CausalBayesianNetwork([("A", "D"), ("A", "Y")])
     cbn.add_cpds(
         UniformRandomCPD("A", [0, 1]),
         FunctionCPD("D", lambda a: 0),
         FunctionCPD("Y", lambda a: a),
     )
     assert introduced_total_effect(cbn, "A", "D", "Y") == pytest.approx(-1)
     cbn.add_cpds(FunctionCPD("Y", lambda a: -a))
     assert introduced_total_effect(
         cbn, "A", "D", "Y", adapt_marginalized=True) == pytest.approx(-1)
Пример #4
0
 def test_introduced_bias_y_nodep_x(
         imputed_cid_introduced_bias: CID) -> None:
     # Modified model where Y doesn't depend on X
     cid = imputed_cid_introduced_bias
     cid.add_cpds(FunctionCPD("Y", lambda x, z: z))  # type: ignore
     cid.impute_conditional_expectation_decision("D", "Y")
     assert introduced_total_effect(cid, "A", "D", "Y", 0,
                                    1) == pytest.approx(1 / 3)
Пример #5
0
 def test_introduced_bias_x_nodep_z(
         imputed_cid_introduced_bias: CID) -> None:
     # Modified model where X doesn't depend on Z
     cid = imputed_cid_introduced_bias
     cid.add_cpds(X=lambda a, z: a)  # type: ignore
     cid.impute_conditional_expectation_decision("D", "Y")
     assert introduced_total_effect(cid, "A", "D", "Y", 0,
                                    1) == pytest.approx(0)