Exemple #1
0
 def testProbs(self):
     c_0 = distribs.Discrete('x', [0])
     c_1 = distribs.Discrete('x', [1])
     d_0 = distribs.Mixture([c_0, c_1], probs=(0.3, 0.7))
     d_1 = distribs.Mixture([c_0, c_1], probs=(0.0, 1.0))
     for _ in range(5):
         self.assertTrue(d_0.contains(d_0.sample()))
     for _ in range(5):
         self.assertEqual(d_1.sample(), {'x': 1})
Exemple #2
0
 def testSamplingContainmentSetMinusMultiple(self):
     base = distribs.Continuous('x', 2, 10)
     hold_out = distribs.Mixture([
         distribs.Discrete('x', [1, 4, 6]),
         distribs.Discrete('x', [3, 8, 9, 12]),
         distribs.Continuous('x', 3, 5),
     ])
     contained = [{'x': value} for value in [2.5, 5.5, 7, 9.5]]
     not_contained = [{'x': value} for value in [4, 6, 9, 11]]
     d = distribs.SetMinus(base, hold_out)
     test_sampling_and_containment(self, d, contained, not_contained)
Exemple #3
0
 def testSamplingContainmentMixtureMultiple(self):
     dists = [
         distribs.Continuous('x', 0, 2),
         distribs.Continuous('x', 1, 5),
         distribs.Continuous('x', 9, 12),
         distribs.Discrete('x', [7, 10]),
         distribs.Discrete('x', [14]),
     ]
     contained = [0.5, 4, 11, 7, 14]
     not_contained = [5.5, 6, 8, 13]
     d = distribs.Mixture(dists)
     contained = [{'x': value} for value in contained]
     not_contained = [{'x': value} for value in not_contained]
     test_sampling_and_containment(self, d, contained, not_contained)
Exemple #4
0
 def testSamplingContainmentMixtureTwo(self, c_0, c_1, contained,
                                       not_contained):
     d = distribs.Mixture((c_0, c_1))
     contained = [{'x': value} for value in contained]
     not_contained = [{'x': value} for value in not_contained]
     test_sampling_and_containment(self, d, contained, not_contained)
Exemple #5
0
    def testCornerUnion(self):
        square_0 = distribs.Product([
            distribs.Continuous('x', 0, 3),
            distribs.Continuous('y', 0, 3),
        ])
        hold_out_0 = distribs.Product([
            distribs.Continuous('x', 1, 3),
            distribs.Continuous('y', 0, 2),
        ])
        square_1 = distribs.Product([
            distribs.Continuous('x', 2, 5),
            distribs.Continuous('y', 0, 3),
        ])
        hold_out_1 = distribs.Product([
            distribs.Continuous('x', 2, 4),
            distribs.Continuous('y', 1, 3),
        ])
        corner_0 = distribs.SetMinus(square_0, hold_out_0)
        corner_1 = distribs.SetMinus(square_1, hold_out_1)
        corner_union = distribs.Mixture([corner_0, corner_1])

        contained = [
            {
                'x': 0.5,
                'y': 0.5
            },
            {
                'x': 0.5,
                'y': 2.5
            },
            {
                'x': 2.5,
                'y': 2.5
            },
            {
                'x': 2.5,
                'y': 0.5
            },
            {
                'x': 4.5,
                'y': 0.5
            },
            {
                'x': 4.5,
                'y': 2.5
            },
        ]
        not_contained = [
            {
                'x': 1.5,
                'y': 0.5
            },
            {
                'x': 1.5,
                'y': 1.5
            },
            {
                'x': 2.5,
                'y': 1.5
            },
            {
                'x': 3.5,
                'y': 1.5
            },
            {
                'x': 3.5,
                'y': 2.5
            },
        ]
        test_sampling_and_containment(self, corner_union, contained,
                                      not_contained)
Exemple #6
0
 def testRaisesError(self):
     c_0 = distribs.Discrete('x', [0])
     c_1 = distribs.Discrete('y', [1])
     with self.assertRaises(ValueError):
         distribs.Mixture((c_0, c_1))