예제 #1
0
    def test_lmvnpdftied_consistent_with_lmvnpdffull(self):
        nstates = 4
        ndim = 20
        nobs = 200

        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        tiedcv = _generate_random_spd_matrix(ndim)
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        cv = np.tile(tiedcv, (nstates, 1, 1))

        reference = gmm.lmvnpdf(obs, mu, cv, 'full')
        lpr = gmm.lmvnpdf(obs, mu, tiedcv, 'tied')
        assert_array_almost_equal(lpr, reference)
예제 #2
0
파일: test_gmm.py 프로젝트: ronw/gm
    def test_lmvnpdftied_consistent_with_lmvnpdffull(self):
        nstates = 4
        ndim = 20
        nobs = 200
        
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        tiedcv = _generate_random_spd_matrix(ndim)
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        cv = np.tile(tiedcv, (nstates, 1, 1))

        reference = gmm.lmvnpdf(obs, mu, cv, 'full')
        lpr = gmm.lmvnpdf(obs, mu, tiedcv, 'tied')
        assert_array_almost_equal(lpr, reference)
예제 #3
0
    def _test_lmvnpdfspherical(self, ndim, nstates, nobs=100):
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        spherecv = np.random.rand(nstates, 1)**2 + 1
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        cv = np.tile(spherecv, (ndim, 1))
        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, spherecv, 'spherical')
        assert_array_almost_equal(lpr, reference)
예제 #4
0
파일: test_gmm.py 프로젝트: ronw/gm
    def _test_lmvnpdfspherical(self, ndim, nstates, nobs=100):
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        spherecv = np.random.rand(nstates, 1)**2 + 1
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        cv = np.tile(spherecv, (ndim, 1))
        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, spherecv, 'spherical')
        assert_array_almost_equal(lpr, reference)
예제 #5
0
파일: test_gmm.py 프로젝트: ronw/gm
    def _test_lmvnpdftied_with_diagonal_covariance(self, ndim, nstates, nobs=100):
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        tiedcv = (np.random.rand(ndim) + 1.0)**2
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        cv = np.tile(tiedcv, (nstates, 1))

        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, np.diag(tiedcv), 'tied')
        assert_array_almost_equal(lpr, reference)
예제 #6
0
파일: test_gmm.py 프로젝트: ronw/gm
    def _test_lmvnpdffull_with_diagonal_covariance(self, ndim, nstates, nobs=100):
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        cv = (np.random.rand(nstates, ndim) + 1.0)**2
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        fullcv = np.array([np.diag(x) for x in cv])

        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, fullcv, 'full')
        assert_array_almost_equal(lpr, reference)
예제 #7
0
    def _test_lmvnpdfdiag(self, ndim, nstates, nobs=100):
        # test the slow and naive implementation of lmvnpdf and
        # compare it to the vectorized version (gmm.lmvnpdf) to test
        # for correctness
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        cv = (np.random.rand(nstates, ndim) + 1.0)**2
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, cv, 'diag')
        assert_array_almost_equal(lpr, reference)
예제 #8
0
파일: test_gmm.py 프로젝트: ronw/gm
    def _test_lmvnpdfdiag(self, ndim, nstates, nobs=100):
        # test the slow and naive implementation of lmvnpdf and
        # compare it to the vectorized version (gmm.lmvnpdf) to test
        # for correctness
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        cv = (np.random.rand(nstates, ndim) + 1.0)**2
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, cv, 'diag')
        assert_array_almost_equal(lpr, reference)
예제 #9
0
    def _test_lmvnpdftied_with_diagonal_covariance(self,
                                                   ndim,
                                                   nstates,
                                                   nobs=100):
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        tiedcv = (np.random.rand(ndim) + 1.0)**2
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        cv = np.tile(tiedcv, (nstates, 1))

        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, np.diag(tiedcv), 'tied')
        assert_array_almost_equal(lpr, reference)
예제 #10
0
    def _test_lmvnpdffull_with_diagonal_covariance(self,
                                                   ndim,
                                                   nstates,
                                                   nobs=100):
        mu = np.random.randint(10) * np.random.rand(nstates, ndim)
        cv = (np.random.rand(nstates, ndim) + 1.0)**2
        obs = np.random.randint(10) * np.random.rand(nobs, ndim)

        fullcv = np.array([np.diag(x) for x in cv])

        reference = self._slow_lmvnpdfdiag(obs, mu, cv)
        lpr = gmm.lmvnpdf(obs, mu, fullcv, 'full')
        assert_array_almost_equal(lpr, reference)
예제 #11
0
 def _compute_log_likelihood(self, obs):
     return lmvnpdf(obs, self._means, self._covars, self._cvtype)