隐马尔科夫模型 使用(下)
【摘要】 # !/usr/bin/python
# -*- coding:utf-8 -*-
import numpy as np
from hmmlearn import hmm
import matplotlib.pyplot as plt
import matplotlib as mpl
from sklearn.metrics.pairwise import pairw...
# !/usr/bin/python
# -*- coding:utf-8 -*-
import numpy as np
from hmmlearn import hmm
import matplotlib.pyplot as plt
import matplotlib as mpl
from sklearn.metrics.pairwise import pairwise_distances_argmin
import warnings
def expand(a, b): d = (b - a) * 0.05 return a-d, b+d
if __name__ == "__main__": warnings.filterwarnings("ignore") # hmmlearn(0.2.0) < sklearn(0.18) np.random.seed(0) n = 5 # 隐状态数目 n_samples = 1000 pi = np.random.rand(n) pi /= pi.sum() print('初始概率:', pi) A = np.random.rand(n, n) mask = np.zeros((n, n), dtype=np.bool) mask[0][1] = mask[0][4] = True mask[1][0] = mask[1][2] = True mask[2][1] = mask[2][3] = True mask[3][2] = mask[3][4] = True mask[4][0] = mask[4][3] = True A[mask] = 0 for i in range(n): A[i] /= A[i].sum() print('转移概率:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
文章来源: maoli.blog.csdn.net,作者:刘润森!,版权归原作者所有,如需转载,请联系作者。
原文链接:maoli.blog.csdn.net/article/details/89219503
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)