def setup_method(self, _): import scipy.io mat = scipy.io.loadmat(os.path.join(os.getcwd(), 'tests', 'data/speechDataDigits4And5.mat')) self.X = np.hstack([mat['train4'][0], mat['train5'][0]]) dim = self.X[0].shape[0] from mlpy.stats import normal_invwishart emission_prior = normal_invwishart(np.ones(dim), dim, dim + 1, 0.1 * np.eye(dim)) from mlpy.stats.dbn.hmm import GaussianHMM self.model = GaussianHMM(ncomponents=2, startprob_prior=[3, 2], emission_prior=emission_prior) self.model.fit(self.X, n_init=3)
class TestHMM(object): def setup_method(self, _): import scipy.io mat = scipy.io.loadmat(os.path.join(os.getcwd(), 'tests', 'data/speechDataDigits4And5.mat')) self.X = np.hstack([mat['train4'][0], mat['train5'][0]]) dim = self.X[0].shape[0] from mlpy.stats import normal_invwishart emission_prior = normal_invwishart(np.ones(dim), dim, dim + 1, 0.1 * np.eye(dim)) from mlpy.stats.dbn.hmm import GaussianHMM self.model = GaussianHMM(ncomponents=2, startprob_prior=[3, 2], emission_prior=emission_prior) self.model.fit(self.X, n_init=3) def test_score_sample(self): obs, hidden = self.model.sample(2, 10) self.model.score_samples(obs) def test_decode(self): obs = np.array([[-0.546801713509048, -0.419653261327029], [-0.935576633566449, -0.657506401748589], [-0.725820776888200, 0.599246387463915], [-0.704569013561647, -0.262774535633877], [0.687557416511721, 0.576826951661595], [-0.192086395176301, 0.115146226815108], [-0.132247659696746, -0.927512789802041], [-0.295411326485649, -0.0143719802889745], [0.927473783664851, 0.0131668616996862], [1.44181054016088, 1.20913420252569], [0.873087639691135, -0.881745308344566], [0.894788321023500, 1.20110834379367], [0.920403967222602, -0.158058390367012]]) self.model.decode(obs) def teardown_method(self, _): pass