当前位置: 首页>>代码示例>>Python>>正文


Python hmm.GaussianHMM方法代码示例

本文整理汇总了Python中hmmlearn.hmm.GaussianHMM方法的典型用法代码示例。如果您正苦于以下问题:Python hmm.GaussianHMM方法的具体用法?Python hmm.GaussianHMM怎么用?Python hmm.GaussianHMM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hmmlearn.hmm的用法示例。


在下文中一共展示了hmm.GaussianHMM方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def process(self):
        females, males = self.get_file_paths(self.females_training_path,
                                             self.males_training_path)
        # collect voice features
        female_voice_features = self.collect_features(females)
        male_voice_features   = self.collect_features(males)
        # generate gaussian mixture models
        females_gmm = hmm.GaussianHMM(n_components=3)
        males_gmm   = hmm.GaussianHMM(n_components=3)
        ubm         = hmm.GaussianHMM(n_components=3)
        # fit features to models
        females_gmm.fit(female_voice_features)
        males_gmm.fit(male_voice_features)
        ubm.fit(np.vstack((female_voice_features, male_voice_features)))
        # save models
        self.save_gmm(females_gmm, "females")
        self.save_gmm(males_gmm,   "males")
        self.save_gmm(males_gmm,   "ubm") 
开发者ID:SuperKogito,项目名称:Voice-based-gender-recognition,代码行数:20,代码来源:ModelsTrainer.py

示例2: test_score_samples_and_decode

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_score_samples_and_decode(self):
        h = hmm.GaussianHMM(self.n_components, self.covariance_type,
                            init_params="st")
        h.means_ = self.means
        h.covars_ = self.covars

        # Make sure the means are far apart so posteriors.argmax()
        # picks the actual component used to generate the observations.
        h.means_ = 20 * h.means_

        gaussidx = np.repeat(np.arange(self.n_components), 5)
        n_samples = len(gaussidx)
        X = self.prng.randn(n_samples, self.n_features) + h.means_[gaussidx]
        h._init(X)
        ll, posteriors = h.score_samples(X)

        assert posteriors.shape == (n_samples, self.n_components)
        assert np.allclose(posteriors.sum(axis=1), np.ones(n_samples))

        viterbi_ll, stateseq = h.decode(X)
        assert np.allclose(stateseq, gaussidx) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:23,代码来源:test_gaussian_hmm.py

示例3: test_fit_zero_variance

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_fit_zero_variance(self):
        # Example from issue #2 on GitHub.
        X = np.asarray([
            [7.15000000e+02, 5.85000000e+02, 0.00000000e+00, 0.00000000e+00],
            [7.15000000e+02, 5.20000000e+02, 1.04705811e+00, -6.03696289e+01],
            [7.15000000e+02, 4.55000000e+02, 7.20886230e-01, -5.27055664e+01],
            [7.15000000e+02, 3.90000000e+02, -4.57946777e-01, -7.80605469e+01],
            [7.15000000e+02, 3.25000000e+02, -6.43127441e+00, -5.59954834e+01],
            [7.15000000e+02, 2.60000000e+02, -2.90063477e+00, -7.80220947e+01],
            [7.15000000e+02, 1.95000000e+02, 8.45532227e+00, -7.03294373e+01],
            [7.15000000e+02, 1.30000000e+02, 4.09387207e+00, -5.83621216e+01],
            [7.15000000e+02, 6.50000000e+01, -1.21667480e+00, -4.48131409e+01]
        ])

        h = hmm.GaussianHMM(3, self.covariance_type)
        h.fit(X) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:18,代码来源:test_gaussian_hmm.py

示例4: GMM_HMM

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def GMM_HMM(O, lengths, n_states, verbose=False):
    # the first step initial a GMM_HMM model
    # input:
    #     O, array, (n_samples, n_features), observation
    #     lengths, list, lengths of sequence
    #     n_states, number of states
    # output:
    #     S, the best state sequence
    #     A, the transition probability matrix of the HMM model

    # model = hmm.GMMHMM(n_components=n_states, n_mix=4, covariance_type="diag", n_iter=1000, verbose=verbose).fit(O, lengths)
    model = hmm.GaussianHMM(n_components=n_states, covariance_type='diag', n_iter=1000, verbose=verbose).fit(O, lengths)

    pi = model.startprob_
    A = model.transmat_
    _, S = model.decode(O, algorithm='viterbi')
    gamma = model.predict_proba(O)
    pickle.dump(model, open('C:/Users/Administrator/Desktop/HMM_program/save/GMM_HMM_model.pkl', 'wb'))

    return S, A, gamma 
开发者ID:JINGEWU,项目名称:Stock-Market-Trend-Analysis-Using-HMM-LSTM,代码行数:22,代码来源:GMM_HMM.py

示例5: __init__

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def __init__(self, model_name='GaussianHMM', n_components=4, cov_type='diag', n_iter=1000):
        self.model_name = model_name
        self.n_components = n_components
        self.cov_type = cov_type
        self.n_iter = n_iter
        self.models = []

        if self.model_name == 'GaussianHMM':
            self.model = hmm.GaussianHMM(n_components=self.n_components, 
                    covariance_type=self.cov_type, n_iter=self.n_iter)
        else:
            raise TypeError('Invalid model type')

    # X is a 2D numpy array where each row is 13D 
开发者ID:PacktPublishing,项目名称:Python-Machine-Learning-Cookbook-Second-Edition,代码行数:16,代码来源:speech_recognizer.py

示例6: process

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def process(self):
        files = self.get_file_paths(self.females_training_path, self.males_training_path)
        # read the test directory and get the list of test audio files
        for file in files:
            self.total_sample += 1
            print("%10s %8s %1s" % ("--> TESTING", ":", os.path.basename(file)))

            #self.ffmpeg_silence_eliminator(file, file.split('.')[0] + "_without_silence.wav")

            # extract MFCC & delta MFCC features from audio
            try: 
                # vector = self.features_extractor.extract_features(file.split('.')[0] + "_without_silence.wav")
                vector = self.features_extractor.extract_features(file)
                spk_gmm = hmm.GaussianHMM(n_components=16)      
                spk_gmm.fit(vector)
                self.spk_vec = spk_gmm.means_
                print(self.spk_vec.shape)
                prediction = list(self.model.predict_classes(self.spk_vec))
                print(prediction)
                if prediction.count(0) <= prediction.count(1) : sc = 1
                else                                          : sc = 0
                
                genders = {0: "female", 1: "male"}
                winner = genders[sc]
                expected_gender = file.split("/")[1][:-1]
                print(expected_gender)
                
                print("%10s %6s %1s" % ("+ EXPECTATION",":", expected_gender))
                print("%10s %3s %1s" %  ("+ IDENTIFICATION", ":", winner))
    
                if winner != expected_gender: self.error += 1
                print("----------------------------------------------------")
    

            except : print("Error")
            # os.remove(file.split('.')[0] + "_without_silence.wav")
            
            
        accuracy     = ( float(self.total_sample - self.error) / float(self.total_sample) ) * 100
        accuracy_msg = "*** Accuracy = " + str(round(accuracy, 3)) + "% ***"
        print(accuracy_msg) 
开发者ID:SuperKogito,项目名称:Voice-based-gender-recognition,代码行数:43,代码来源:GenderIdentifier.py

示例7: process

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def process(self):
        females, males = self.get_file_paths(self.females_training_path,
                                             self.males_training_path)
        files = females + males
        # collect voice features
        features = {"female" : np.asarray(()), "male" : np.asarray(())}
        
        for file in files:
            print("%10s %8s %1s" % ("--> TESTING", ":", os.path.basename(file)))
            print(features["female"].shape, features["male"].shape)
            # extract MFCC & delta MFCC features from audio
            try: 
                # vector = self.features_extractor.extract_features(file.split('.')[0] + "_without_silence.wav")
                vector  = self.features_extractor.extract_features(file)
                spk_gmm = hmm.GaussianHMM(n_components=16)      
                spk_gmm.fit(vector)
                spk_vec = spk_gmm.means_
                gender  = file.split("/")[1][:-1]
                print(gender)
                # stack super vectors
                if features[gender].size == 0:  features[gender] = spk_vec
                else                         :  features[gender] = np.vstack((features[gender], spk_vec))
            
            except:
                pass
        
        # save models
        self.save_gmm(features["female"], "females")
        self.save_gmm(features["male"],   "males") 
开发者ID:SuperKogito,项目名称:Voice-based-gender-recognition,代码行数:31,代码来源:ModelsTrainer.py

示例8: test_bad_covariance_type

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_bad_covariance_type(self):
        with pytest.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() 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:10,代码来源:test_gaussian_hmm.py

示例9: test_sample

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_sample(self, n=1000):
        h = hmm.GaussianHMM(self.n_components, self.covariance_type)
        h.startprob_ = self.startprob
        h.transmat_ = self.transmat
        # Make sure the means are far apart so posteriors.argmax()
        # picks the actual component used to generate the observations.
        h.means_ = 20 * self.means
        h.covars_ = np.maximum(self.covars, 0.1)

        X, state_sequence = h.sample(n, random_state=self.prng)
        assert X.shape == (n, self.n_features)
        assert len(state_sequence) == n 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:14,代码来源:test_gaussian_hmm.py

示例10: test_fit

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_fit(self, params='stmc', n_iter=5, **kwargs):
        h = hmm.GaussianHMM(self.n_components, self.covariance_type)
        h.startprob_ = self.startprob
        h.transmat_ = normalized(
            self.transmat + np.diag(self.prng.rand(self.n_components)), 1)
        h.means_ = 20 * self.means
        h.covars_ = self.covars

        lengths = [10] * 10
        X, _state_sequence = h.sample(sum(lengths), random_state=self.prng)

        # Mess up the parameters and see if we can re-learn them.
        # TODO: change the params and uncomment the check
        h.fit(X, lengths=lengths)
        # assert log_likelihood_increasing(h, X, lengths, n_iter) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:17,代码来源:test_gaussian_hmm.py

示例11: test_fit_ignored_init_warns

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_fit_ignored_init_warns(self, caplog):
        h = hmm.GaussianHMM(self.n_components, self.covariance_type)
        h.startprob_ = self.startprob
        h.fit(np.random.randn(100, self.n_components))
        assert len(caplog.records) == 1
        assert "will be overwritten" in caplog.records[0].getMessage() 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:8,代码来源:test_gaussian_hmm.py

示例12: test_fit_sequences_of_different_length

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_fit_sequences_of_different_length(self):
        lengths = [3, 4, 5]
        X = self.prng.rand(sum(lengths), self.n_features)

        h = hmm.GaussianHMM(self.n_components, self.covariance_type)
        # This shouldn't raise
        # ValueError: setting an array element with a sequence.
        h.fit(X, lengths=lengths) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:10,代码来源:test_gaussian_hmm.py

示例13: test_fit_with_length_one_signal

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_fit_with_length_one_signal(self):
        lengths = [10, 8, 1]
        X = self.prng.rand(sum(lengths), self.n_features)

        h = hmm.GaussianHMM(self.n_components, self.covariance_type)
        # This shouldn't raise
        # ValueError: zero-size array to reduction operation maximum which
        #             has no identity
        h.fit(X, lengths=lengths) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:11,代码来源:test_gaussian_hmm.py

示例14: test_covar_is_writeable

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def test_covar_is_writeable(self):
        h = hmm.GaussianHMM(n_components=1, covariance_type="diag",
                            init_params="c")
        X = np.random.normal(size=(1000, 5))
        h._init(X)

        # np.diag returns a read-only view of the array in NumPy 1.9.X.
        # Make sure this doesn't prevent us from fitting an HMM with
        # diagonal covariance matrix. See PR#44 on GitHub for details
        # and discussion.
        assert h._covars_.flags["WRITEABLE"] 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:13,代码来源:test_gaussian_hmm.py

示例15: __init__

# 需要导入模块: from hmmlearn import hmm [as 别名]
# 或者: from hmmlearn.hmm import GaussianHMM [as 别名]
def __init__(self, num_components=4, num_iter=1000):
        self.n_components = num_components
        self.n_iter = num_iter

        self.cov_type = 'diag' 
        self.model_name = 'GaussianHMM' 

        self.models = []

        self.model = hmm.GaussianHMM(n_components=self.n_components, 
                covariance_type=self.cov_type, n_iter=self.n_iter)

    # 'training_data' is a 2D numpy array where each row is 13-dimensional 
开发者ID:PacktPublishing,项目名称:Artificial-Intelligence-with-Python,代码行数:15,代码来源:speech_recognizer.py


注:本文中的hmmlearn.hmm.GaussianHMM方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。