Exemple #1
0
    def test_attributes(self):
        h = hmm.MultinomialHMM(self.n_components)

        self.assertEqual(h.n_components, self.n_components)

        h.startprob_ = self.startprob
        h.transmat_ = self.transmat
        h.emissionprob_ = self.emissionprob
        assert_array_almost_equal(h.emissionprob_, self.emissionprob)
        with assert_raises(ValueError):
            h.emissionprob_ = []
            h._check()
        with assert_raises(ValueError):
            h.emissionprob_ = np.zeros(
                (self.n_components - 2, self.n_features))
            h._check()
Exemple #2
0
    def test_attributes(self):
        h = hmm.MultinomialHMM(self.n_components)

        self.assertEqual(h.n_components, self.n_components)

        h.startprob_ = self.startprob
        h.transmat_ = self.transmat
        h.emissionprob_ = self.emissionprob
        assert_array_almost_equal(h.emissionprob_, self.emissionprob)
        with assert_raises(ValueError):
            h.emissionprob_ = []
            h._check()
        with assert_raises(ValueError):
            h.emissionprob_ = np.zeros((self.n_components - 2,
                                        self.n_features))
            h._check()
Exemple #3
0
 def test_bad_covariance_type(self):
     with assert_raises(ValueError):
         h = hmm.GaussianHMM(20, covariance_type='badcovariance_type')
         h.means_ = self.means
         h.covars_ = []
         h.startprob_ = self.startprob
         h.transmat_ = self.transmat
         h._check()
Exemple #4
0
 def test_bad_covariance_type(self):
     with assert_raises(ValueError):
         h = hmm.GaussianHMM(20, covariance_type='badcovariance_type')
         h.means_ = self.means
         h.covars_ = []
         h.startprob_ = self.startprob
         h.transmat_ = self.transmat
         h._check()
Exemple #5
0
    def test_base_hmm_attributes(self):
        n_components = 20
        startprob = self.prng.rand(n_components)
        startprob = startprob / startprob.sum()
        transmat = self.prng.rand(n_components, n_components)
        transmat /= np.tile(
            transmat.sum(axis=1)[:, np.newaxis], (1, n_components))

        h = StubHMM(n_components)

        self.assertEqual(h.n_components, n_components)

        h.startprob_ = startprob
        assert_array_almost_equal(h.startprob_, startprob)

        with assert_raises(ValueError):
            h.startprob_ = 2 * startprob
            h._check()
        with assert_raises(ValueError):
            h.startprob_ = []
            h._check()
        with assert_raises(ValueError):
            h.startprob_ = np.zeros((n_components - 2, 2))
            h._check()

        h.startprob_ = startprob
        h.transmat_ = transmat
        assert_array_almost_equal(h.transmat_, transmat)
        with assert_raises(ValueError):
            h.transmat_ = 2 * transmat
            h._check()
        with assert_raises(ValueError):
            h.transmat_ = []
            h._check()
        with assert_raises(ValueError):
            h.transmat_ = np.zeros((n_components - 2, n_components))
            h._check()
Exemple #6
0
    def test_base_hmm_attributes(self):
        n_components = 20
        startprob = self.prng.rand(n_components)
        startprob = startprob / startprob.sum()
        transmat = self.prng.rand(n_components, n_components)
        transmat /= np.tile(transmat.sum(axis=1)
                            [:, np.newaxis], (1, n_components))

        h = StubHMM(n_components)

        self.assertEqual(h.n_components, n_components)

        h.startprob_ = startprob
        assert_array_almost_equal(h.startprob_, startprob)

        with assert_raises(ValueError):
            h.startprob_ = 2 * startprob
            h._check()
        with assert_raises(ValueError):
            h.startprob_ = []
            h._check()
        with assert_raises(ValueError):
            h.startprob_ = np.zeros((n_components - 2, 2))
            h._check()

        h.startprob_ = startprob
        h.transmat_ = transmat
        assert_array_almost_equal(h.transmat_, transmat)
        with assert_raises(ValueError):
            h.transmat_ = 2 * transmat
            h._check()
        with assert_raises(ValueError):
            h.transmat_ = []
            h._check()
        with assert_raises(ValueError):
            h.transmat_ = np.zeros((n_components - 2, n_components))
            h._check()