栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

隐马尔可夫算法

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

隐马尔可夫算法

import numpy as np

start = np.array([0.6,0.4])
t_p = np.array([[0.7,0.3],
                [0.4,0.6]])
e_m = np.array([[0.1,0.4,0.5],
               [0.6,0.3,0.1]])
one = np.zeros(2)
twosun = np.zeros(2)
tworain = np.zeros(2)
threesun = np.zeros(2)
threerain = np.zeros(2)
twoday = np.zeros(2)
threeday = np.zeros(2)
def one_day(start,e_m):
    for i in range(0,2):
        one[i] = start[i]*e_m[i][0]
    return one

def two_sun(t_p,e_m,maxbefore):
    for i in range(0,2):
        twosun[i] = maxbefore[i]*t_p[i][1]*e_m[1][1]
    return twosun


def two_rain(t_p,e_m,maxbefore):
    for i in range(0,2):
        tworain[i] = maxbefore[i]*t_p[i][0]*e_m[0][1]
    return tworain


def three_sun(t_p,e_m,maxbefore):
    for i in range(0,2):
        threesun[i] = maxbefore[i]*t_p[i][1]*e_m[1][2]
    return threesun

def three_rain(t_p,e_m,maxbefore):
    for i in range(0,2):
        threerain[i] = maxbefore[i]*t_p[i][0]*e_m[0][2]
    return threerain


oneday = one_day(start,e_m)
r1 = oneday[0]
s1 = oneday[1]
moneday = np.max(oneday)



twosun = two_sun(t_p,e_m,oneday)
rs2 = twosun[0]
ss2 = twosun[1]
mtwosun = np.max(twosun)
if mtwosun == rs2:
    twos = "1r 2s"
else:
    twos = "1s 2s"

tworain = two_rain(t_p,e_m,oneday)
rr2 = tworain[0]
sr2 = tworain[1]
mtworain = np.max(tworain)
if mtworain == sr2:
    twor = "1s 2r"
else:
    twor = "1r 2r"

if mtworain > mtwosun:
    mtwoday = mtworain

else:
    mtwoday = mtwosun


twoday[0]= mtworain
twoday[1] =mtwosun

threesun = three_sun(t_p,e_m,twoday)
rs3 = threesun[0]
ss3 = threesun[1]
threerain = three_rain(t_p,e_m,twoday)
rr3 = threerain[0]
sr3 = threerain[1]
mthreesun = np.max(threesun)
mthreerain =np.max(threerain)


if mthreesun > mthreerain:
    mthreeday = mthreesun

else:
    mthreeday = mthreerain


if mthreesun > mthreerain:
    if mthreesun == rs3:
        print(twor +"3s")
    else:
        print(twos +"3s")
else:
    if mthreerain == sr3:
        print(twos + " 3r")
    else:
        print(twor + " 3r")



p = moneday*mtwoday*mthreeday
print(p)

1s 2r 3r
0.00013934591999999998
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/294676.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号