import sys from hmmlearn.hmm import MultinomialHMM import numpy as np dice_num = 3 x_num = 8 dice_hmm = MultinomialHMM(n_components=3, n_features=x_num, n_iter=100, params="ste", init_params="e") dice_hmm.startprob_ = np.ones(3) / 3.0 dice_hmm.transmat_ = np.ones((3, 3)) / 3.0 dice_hmm.emissionprob_ = np.array([[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]) dice_hmm.emissionprob_ /= dice_hmm.emissionprob_.sum(axis=1)[:, np.newaxis] X = np.array([[1], [6], [3], [5], [2], [7], [3], [5], [2], [4], [3], [6], [1], [5], [4]]) Z = dice_hmm.decode(X) # 问题A logprob = dice_hmm.score(X) # 问题B # 问题C x_next = np.dot(dice_hmm.transmat_, dice_hmm.emissionprob_) print("state: ", Z) print("logprob: ", logprob) print("prob of x_next: ", x_next)