예제 #1
0
    def test_normalize(self):
        d = PiecewiseUniform([0, .5, 1.0], [.3, .7])
        self.assertAlmostEqual(1.0, get_distribution_sum(d), delta=1e-5)

        d = PiecewiseUniform([0, .5, 1.0], [3, 7])
        self.assertAlmostEqual(1.0, get_distribution_sum(d), delta=1e-5)

        d = PiecewiseUniform([0, 13, 84, 104], [3, 7, 2])
        self.assertAlmostEqual(1.0, get_distribution_sum(d), delta=1e-5)
예제 #2
0
 def test_expected_value_simple(self):
     d = PiecewiseUniform([0,1], [1.0])
     f = PiecewiseFunction([-np.inf, np.inf], [lambda x: x])
     self.assertAlmostEqual(numerical_expected_value(d, f), 0.5, delta=1e-3)
예제 #3
0
 def test_analystic_ev_with_single_regions(self):
     d = PiecewiseUniform([0,1], [1.0])
     f = PiecewiseDefiniteIntegralFunction([0, 1], [lambda x: x])
     self.assertEqual(analytic_expected_value(d, f), 1.0)
예제 #4
0
 def test_piecewise_function_and_distribution(self):
     d = PiecewiseUniform([-10, 0, 10], [1.0, 9.0])
     f = PiecewiseFunction([-np.inf, 0, np.inf], [lambda x: 1, lambda x: 10])
     self.assertAlmostEqual(numerical_expected_value(d, f), (.9 * 10 + .1), delta=1e-3)
예제 #5
0
 def test_piecewise_distribution(self):
     d = PiecewiseUniform([-100, 0, 100], [1.0, 10.0])
     f = lambda x: 1.0
     self.assertAlmostEqual(numerical_expected_value(d, f, resolution=0.1), 1.0, delta=1e-1)
예제 #6
0
 def test_piecewise_function(self):
     d = PiecewiseUniform([-100, 100], [1.0])
     f = PiecewiseFunction([-np.inf, 0, np.inf], [lambda x: 1, lambda x: 10])
     self.assertAlmostEqual(numerical_expected_value(d, f, resolution=0.1), 11 / 2, delta=1e-1)
예제 #7
0
 def test_ev_gaussian(self):
     d = PiecewiseUniform([-100,100], [1.0])
     f = lambda x: np.exp(-(x**2) / 0.1)
     self.assertAlmostEqual(numerical_expected_value(d, f, resolution=0.1), 0.0, delta=1e-1)