Example #1
0
    def test_convergence_with_map (self):
        """ Tests if we can still achieve convergence when using 
            parallel_map. """
        mu = [2, 1]
        s = [[.01, 0], [0, .01]]
        X = MultivariateLognormal (mu, s)
        N = 2000
        rvs_caller = lambda _: X.rvs ()
        rand_vals = parallel_map (rvs_caller, range (N), 5)
        mean = np.array ([.0, .0])
        for val in rand_vals:
            mean += val
        mean /= N
        assert all (abs (X.mean () - mean) / X.mean () < 1e-1)
        
        mu = [2, 1]
        s = [[.01, 0], [0, .01]]
        X = MultivariateLognormal (mu, s)
        N = 2000

        rvs_caller = lambda _: X.rvs ()
        rand_vals = parallel_map (rvs_caller, range (N), 5)
        mean = np.array ([.0, .0])
        for val in rand_vals:
            mean += val
        mean /= N
        assert all (abs (X.mean () - mean) / X.mean () < 1e-1)
Example #2
0
 def test_get_mean (self):
     """ Tests if one can get the mean of the random variable. """
     mu = [1, 2, 3, 4]
     S = np.array ([[2, 0, 0, 0], 
          [0, 1, 0, 0], 
          [0, 0, 4, 1],
          [0, 0, 1, 2]])
     X = MultivariateLognormal (mu, S)
     assert all (abs (X.mean () - np.exp (np.array (mu) \
             + S.diagonal () / 2)) < 1e-4)
Example #3
0
 def test_convergence_to_mean (self):
     """ Tests if the randomly generated values has a sample mean
         that converges to the correct mean. """
     mu = [2, 1]
     s = [[.01, 0], [0, .01]]
     X = MultivariateLognormal (mu, s)
     N = 2000
     mean = np.array ([.0, .0])
     for i in range (N):
         mean += X.rvs ()
     mean /= N
     assert all (abs (X.mean () - mean) / X.mean () < 1e-1)
     
     mu = [2, 1]
     s = [[.01, 0], [0, .01]]
     X = MultivariateLognormal (mu, s)
     N = 2000
     mean = np.array ([.0, .0])
     for i in range (N):
         mean += X.rvs ()
     mean /= N
     assert all (abs (X.mean () - mean) / X.mean () < 1e-1)