示例#1
0
 def _generate_sample_from_state(self, state, random_state=None):
     if self._cvtype == 'tied':
         cv = self._covars
     else:
         cv = self._covars[state]
     return sample_gaussian(self._means[state], cv, self._cvtype,
                            random_state=random_state)
示例#2
0
    def _test_sample_gaussian_diag(self, ndim, n=10000):
        mu = np.random.randint(10) * np.random.rand(ndim)
        cv = (np.random.rand(ndim) + 1.0)**2

        samples = gmm.sample_gaussian(mu, cv, cvtype='diag', n=n)

        if ndim > 1:
            axis = 1
        else:
            axis = None
        assert_array_almost_equal(samples.mean(axis), mu, decimal=1)
        assert_array_almost_equal(samples.var(axis), cv, decimal=1)
示例#3
0
文件: test_gmm.py 项目: ronw/gm
    def _test_sample_gaussian_diag(self, ndim, n=10000):
        mu = np.random.randint(10) * np.random.rand(ndim)
        cv = (np.random.rand(ndim) + 1.0)**2

        samples = gmm.sample_gaussian(mu, cv, cvtype='diag', n=n)

        if ndim > 1:
            axis = 1
        else:
            axis = None
        assert_array_almost_equal(samples.mean(axis), mu, decimal=1)
        assert_array_almost_equal(samples.var(axis), cv, decimal=1)
示例#4
0
    def _test_sample_gaussian_full(self, ndim, n=10000):
        mu = np.random.randint(10) * np.random.rand(ndim)
        cv = _generate_random_spd_matrix(ndim)

        samples = gmm.sample_gaussian(mu, cv, cvtype='full', n=n)

        if ndim > 1:
            axis = 1
        else:
            axis = None
        assert_array_almost_equal(samples.mean(axis), mu, decimal=1)
        assert_array_almost_equal(np.cov(samples), cv, decimal=1)
示例#5
0
文件: test_gmm.py 项目: ronw/gm
    def _test_sample_gaussian_full(self, ndim, n=10000):
        mu = np.random.randint(10) * np.random.rand(ndim)
        cv = _generate_random_spd_matrix(ndim)

        samples = gmm.sample_gaussian(mu, cv, cvtype='full', n=n)

        if ndim > 1:
            axis = 1
        else:
            axis = None
        assert_array_almost_equal(samples.mean(axis), mu, decimal=1)
        assert_array_almost_equal(np.cov(samples), cv, decimal=1)