Esempio n. 1
0
 def test_mv_mixture_rvs_random(self):
     cov3 = np.array([[1., 0.5, 0.75], [0.5, 1.5, 0.6], [0.75, 0.6, 2.]])
     mu = np.array([-1, 0.0, 2.0])
     mu2 = np.array([4, 2.0, 2.0])
     mvn3 = mvd.MVNormal(mu, cov3)
     mvn32 = mvd.MVNormal(mu2, cov3 / 2.)
     np.random.seed(0)
     res = mv_mixture_rvs([0.4, 0.6], 5000, [mvn3, mvn32], 3)
     npt.assert_almost_equal(np.array([res.std(),
                                       res.mean(),
                                       res.var()]),
                             np.array([1.874, 1.733, 3.512]),
                             decimal=1)
Esempio n. 2
0
 def test_mv_mixture_rvs_random(self):
     cov3 = np.array([[ 1.  ,  0.5 ,  0.75],
                    [ 0.5 ,  1.5 ,  0.6 ],
                    [ 0.75,  0.6 ,  2.  ]])
     mu = np.array([-1, 0.0, 2.0])
     mu2 = np.array([4, 2.0, 2.0])
     mvn3 = mvd.MVNormal(mu, cov3)
     mvn32 = mvd.MVNormal(mu2, cov3/2.)
     np.random.seed(0)
     res = mv_mixture_rvs([0.4, 0.6], 5000, [mvn3, mvn32], 3)
     npt.assert_almost_equal(
             np.array([res.std(),res.mean(),res.var()]),
             np.array([1.874,1.733,3.512]),
             decimal=1)
Esempio n. 3
0
 def test_mv_mixture_rvs_fixed(self):
     np.random.seed(1234)
     cov3 = np.array([[1., 0.5, 0.75], [0.5, 1.5, 0.6], [0.75, 0.6, 2.]])
     mu = np.array([-1, 0.0, 2.0])
     mu2 = np.array([4, 2.0, 2.0])
     mvn3 = mvd.MVNormal(mu, cov3)
     mvn32 = mvd.MVNormal(mu2, cov3 / 2)
     res = mv_mixture_rvs([0.2, 0.8], 10, [mvn3, mvn32], 3)
     npt.assert_almost_equal(
         res,
         np.array([[-0.23955497, 1.73426482, 0.36100243],
                   [2.52063189, 1.0832677, 1.89947131],
                   [4.36755379, 2.14480498, 2.22003966],
                   [3.1141545, 1.21250505, 2.58511199],
                   [4.1980202, 2.50017561, 1.87324933],
                   [3.48717503, 0.91847424, 2.14004598],
                   [3.55904133, 2.74367622, 0.68619582],
                   [3.60521933, 1.57316531, 0.82784584],
                   [3.86102275, 0.6211812, 1.33016426],
                   [3.91074761, 2.037155, 2.22247051]]))
Esempio n. 4
0
 def test_mv_mixture_rvs_fixed(self):
     np.random.seed(1234)
     cov3 = np.array([[ 1.  ,  0.5 ,  0.75],
                    [ 0.5 ,  1.5 ,  0.6 ],
                    [ 0.75,  0.6 ,  2.  ]])
     mu = np.array([-1, 0.0, 2.0])
     mu2 = np.array([4, 2.0, 2.0])
     mvn3 = mvd.MVNormal(mu, cov3)
     mvn32 = mvd.MVNormal(mu2, cov3/2)
     res = mv_mixture_rvs([0.2, 0.8], 10, [mvn3, mvn32], 3)
     npt.assert_almost_equal(
             res,
             np.array([[-0.23955497,  1.73426482,  0.36100243],
                    [ 2.52063189,  1.0832677 ,  1.89947131],
                    [ 4.36755379,  2.14480498,  2.22003966],
                    [ 3.1141545 ,  1.21250505,  2.58511199],
                    [ 4.1980202 ,  2.50017561,  1.87324933],
                    [ 3.48717503,  0.91847424,  2.14004598],
                    [ 3.55904133,  2.74367622,  0.68619582],
                    [ 3.60521933,  1.57316531,  0.82784584],
                    [ 3.86102275,  0.6211812 ,  1.33016426],
                    [ 3.91074761,  2.037155  ,  2.22247051]]))
Esempio n. 5
0
print('diff', mvt3_cdf0 - 0.3026855)
a = [0.0, 0.5, 1.0]
mvt3_cdf1 = mvt3.cdf(a)
print(mvt3_cdf1)
print((xt < np.array(a)).all(-1).mean(0))
print('R', 0.1946621)  # "error": 0.0002524817)
print('R', 0.1946217)  # "error:"2.748699e-06    with smaller abseps)
print('diff', mvt3_cdf1 - 0.1946217)

assert_array_almost_equal(mvt3_cdf0, 0.3026855, decimal=5)
assert_array_almost_equal(mvt3_cdf1, 0.1946217, decimal=5)

import statsmodels.distributions.mixture_rvs as mix
mu2 = np.array([4, 2.0, 2.0])
mvn32 = mvd.MVNormal(mu2, cov3 / 2., 4)
md = mix.mv_mixture_rvs([0.4, 0.6], 5, [mvt3, mvt3n], 3)
rvs = mix.mv_mixture_rvs([0.4, 0.6], 2000, [mvn3, mvn32], 3)
#rvs2 = rvs[:,:2]
import matplotlib.pyplot as plt
fig = plt.figure()
fig.add_subplot(2, 2, 1)
plt.plot(rvs[:, 0], rvs[:, 1], '.', alpha=0.25)
plt.title('1 versus 0')
fig.add_subplot(2, 2, 2)
plt.plot(rvs[:, 0], rvs[:, 2], '.', alpha=0.25)
plt.title('2 versus 0')
fig.add_subplot(2, 2, 3)
plt.plot(rvs[:, 1], rvs[:, 2], '.', alpha=0.25)
plt.title('2 versus 1')
#plt.show()
Esempio n. 6
0
print 'diff', mvt3_cdf0 - 0.3026855
a = [0.0, 0.5, 1.0]
mvt3_cdf1 = mvt3.cdf(a)
print mvt3_cdf1
print (xt<np.array(a)).all(-1).mean(0)
print 'R', 0.1946621 # "error": 0.0002524817
print 'R', 0.1946217 # "error:"2.748699e-06    with smaller abseps
print 'diff', mvt3_cdf1 - 0.1946217

assert_array_almost_equal(mvt3_cdf0, 0.3026855, decimal=5)
assert_array_almost_equal(mvt3_cdf1, 0.1946217, decimal=5)

import statsmodels.distributions.mixture_rvs as mix
mu2 = np.array([4, 2.0, 2.0])
mvn32 = mvd.MVNormal(mu2, cov3/2., 4)
md = mix.mv_mixture_rvs([0.4, 0.6], 5, [mvt3, mvt3n], 3)
rvs = mix.mv_mixture_rvs([0.4, 0.6], 2000, [mvn3, mvn32], 3)
#rvs2 = rvs[:,:2]
import matplotlib.pyplot as plt
fig = plt.figure()
fig.add_subplot(2, 2, 1)
plt.plot(rvs[:,0], rvs[:,1], '.', alpha=0.25)
plt.title('1 versus 0')
fig.add_subplot(2, 2, 2)
plt.plot(rvs[:,0], rvs[:,2], '.', alpha=0.25)
plt.title('2 versus 0')
fig.add_subplot(2, 2, 3)
plt.plot(rvs[:,1], rvs[:,2], '.', alpha=0.25)
plt.title('2 versus 1')
#plt.show()