def test_make_cpmf_PrXcZ_variant_1() -> None: V0 = Variable([0, 1, 1, 1, 0, 1, 0, 1]) V1 = Variable([0, 0, 1, 1, 0, 1, 1, 1]) PrXZ = PMF(JointVariables(V0, V1)) PrXZ.IDs(1000, 1111) assert PrXZ.IDs() == (1000, 1111) assert PrXZ.p((0, 0)) == 2 / 8 assert PrXZ.p((0, 1)) == 1 / 8 assert PrXZ.p((1, 0)) == 1 / 8 assert PrXZ.p((1, 1)) == 4 / 8
def test_pmf_summing_over_variable(): V0 = Variable([0, 1, 1, 1, 0, 1, 0, 1]) V1 = Variable([0, 0, 1, 1, 0, 1, 1, 1]) V2 = Variable([0, 0, 0, 0, 1, 0, 1, 1]) V3 = Variable([0, 0, 0, 0, 0, 0, 1, 1]) V0.ID = 1000 V1.ID = 1111 V2.ID = 1222 V3.ID = 1333 Pr = PMF(JointVariables(V0, V1, V2, V3)) assert Pr.IDs() == (1000, 1111, 1222, 1333) assert Pr.p((0, 0, 0, 0)) == 1 / 8 assert Pr.p((1, 0, 0, 0)) == 1 / 8 assert Pr.p((1, 1, 0, 0)) == 3 / 8 assert Pr.p((0, 0, 1, 0)) == 1 / 8 assert Pr.p((0, 1, 1, 1)) == 1 / 8 assert Pr.p((1, 1, 1, 1)) == 1 / 8 Pr = Pr.sum_over(V2.ID) assert sum(Pr.probabilities.values()) == 1 assert Pr.p((0, 0, 0)) == 2 / 8 assert Pr.p((1, 0, 0)) == 1 / 8 assert Pr.p((1, 1, 0)) == 3 / 8 assert Pr.p((0, 1, 1)) == 1 / 8 assert Pr.p((1, 1, 1)) == 1 / 8 assert Pr.IDs() == (V0.ID, V1.ID, V3.ID) Pr = Pr.sum_over(V1.ID) assert sum(Pr.probabilities.values()) == 1 assert Pr.p((0, 0)) == 2 / 8 assert Pr.p((1, 0)) == 4 / 8 assert Pr.p((0, 1)) == 1 / 8 assert Pr.p((1, 1)) == 1 / 8 assert Pr.IDs() == (V0.ID, V3.ID) Pr = Pr.sum_over(V0.ID) assert sum(Pr.probabilities.values()) == 1 print(Pr.probabilities) assert Pr.p(0) == 6 / 8 assert Pr.p(1) == 2 / 8 assert Pr.IDs() == (V3.ID,)
def create_joint_pmf(self, values_as_indices=True) -> PMF: pmf = PMF(None) pmf.probabilities = self.joint_values_and_probabilities( values_as_indices=values_as_indices) pmf.IDs(*self.variable_IDs) return pmf