Esempio n. 1
0
 def _do_mstep(self, stats, params, covars_prior=1e-2, **kwargs):
     super(GMMHMM, self)._do_mstep(stats, params)
     # All that is left to do is to apply covars_prior to the
     # parameters updated in _accumulate_sufficient_statistics.
     for state, g in enumerate(self.gmms):
         norm = stats['norm'][state]
         if 'w' in params:
             g.weights = normalize(norm)
         if 'm' in params:
             g.means = stats['means'][state] / norm[:, np.newaxis]
         if 'c' in params:
             if g.cvtype == 'tied':
                 g.covars = ((stats['covars'][state]
                              + covars_prior * np.eye(g.n_features))
                             / norm.sum())
             else:
                 cvnorm = np.copy(norm)
                 shape = np.ones(g._covars.ndim)
                 shape[0] = np.shape(g._covars)[0]
                 cvnorm.shape = shape
                 if g.cvtype == 'spherical' or g.cvtype == 'diag':
                     g.covars = (stats['covars'][state]
                                 + covars_prior) / cvnorm
                 elif g.cvtype == 'full':
                     eye = np.eye(g.n_features)
                     g.covars = ((stats['covars'][state]
                                  + covars_prior * eye[np.newaxis, :, :])
                                 / cvnorm)
Esempio n. 2
0
    def _init(self, obs, params='ste'):
        super(MultinomialHMM, self)._init(obs, params=params)

        if 'e' in params:
            emissionprob = normalize(np.random.rand(self.n_components,
                                                    self.n_symbols), 1)
            self.emissionprob = emissionprob
Esempio n. 3
0
    def _do_mstep(self, stats, params, **kwargs):
        # Based on Huang, Acero, Hon, "Spoken Language Processing",
        # p. 443 - 445
        if 's' in params:
            self.startprob = normalize(
                np.maximum(self.startprob_prior - 1.0 + stats['start'], 1e-20))
        if 't' in params:
	    A = self.transmat_prior - 1.0 + stats['trans']
	    s = np.sum(A,1)
#            print(s)
            self.transmat = (A.T/s).T
Esempio n. 4
0
 def test_normalize_with_axis_3D(self):
     A = np.random.rand(10, 4, 5) + 1.0
     for axis in range(3):
         Anorm = gmm.normalize(A, axis)
         self.assertTrue(np.all(gmm.almost_equal(Anorm.sum(axis), 1.0)))
Esempio n. 5
0
 def test_normalize_2D(self):
     A = np.random.rand(10, 4) + 1.0
     Anorm = gmm.normalize(A)
     self.assertAlmostEqual(Anorm.sum(), 1.0)
Esempio n. 6
0
File: test_gmm.py Progetto: ronw/gm
 def test_normalize_with_axis_3D(self):
     A = np.random.rand(10, 4, 5) + 1.0
     for axis in range(3):
         Anorm = gmm.normalize(A, axis)
         self.assertTrue(np.all(gmm.almost_equal(Anorm.sum(axis), 1.0)))
Esempio n. 7
0
File: test_gmm.py Progetto: ronw/gm
 def test_normalize_2D(self):
     A = np.random.rand(10, 4) + 1.0
     Anorm = gmm.normalize(A)
     self.assertAlmostEqual(Anorm.sum(), 1.0)