python CRF-SDM

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python CRF-SDM相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# coding:utf-8
import math

x1 = 5
x2 = 0
x3 = 1

w_tab = {}

w_tab['S'] = {}
w_tab['S']['A'] = (x1 + 10)/20.0
w_tab['S']['V'] = (x2 + 11)/20.0
w_tab['S']['N'] = (x3 + 12)/20.0
w_tab['A'] = {}
w_tab['A']['N'] = (x1 + x2)/20.0
w_tab['A']['V'] = (x2 + x3)/20.0
w_tab['V']={}
w_tab['V']['N'] = (x1 + x3)/20.0
w_tab['V']['V'] = (x1 + 4)/20.0
w_tab['N'] = {}
w_tab['N']['N'] = (x2 + 5)/20.0
w_tab['N']['V'] = (x3 + 6)/20.0
w_tab['N']['Sfin'] = (x1 + 1)/20.0
w_tab['V']['Sfin'] = (x2 + 2)/20.0


alfa = [0,0,0,0,0,0,0]
alfa[0] = 1.0
alfa[1] = math.exp(w_tab['S']['A'])
alfa[2] = math.exp(w_tab['S']['V'])
alfa[3] = math.exp(w_tab['S']['N'])
alfa[4] = alfa[1] * math.exp(w_tab['A']['N']) \
		+ alfa[2] * math.exp(w_tab['V']['N']) \
		+ alfa[3] * math.exp(w_tab['N']['N'])
alfa[5] = alfa[1] * math.exp(w_tab['A']['V']) \
		+ alfa[2] * math.exp(w_tab['V']['V']) \
		+ alfa[3] * math.exp(w_tab['N']['V'])

alfa[6] = alfa[4] * math.exp(w_tab['N']['Sfin']) + \
		  alfa[5] * math.exp(w_tab['V']['Sfin'])

beta = [0,0,0,0,0,0,0]
beta[0] = 1.0
beta[1] = beta[0] * math.exp(w_tab['N']['Sfin'])
beta[2] = beta[0] * math.exp(w_tab['V']['Sfin'])
beta[3] = beta[1] * math.exp(w_tab['A']['N']) + beta[2] * math.exp(w_tab['A']['V'])
beta[4] = beta[1] * math.exp(w_tab['V']['N']) + beta[2] * math.exp(w_tab['V']['V'])
beta[5] = beta[1] * math.exp(w_tab['N']['N']) + beta[2] * math.exp(w_tab['N']['V'])
beta[6] = beta[3] * math.exp(w_tab['S']['A']) + \
		  beta[4] * math.exp(w_tab['S']['V']) + \
		  beta[5] * math.exp(w_tab['S']['N'])

# print(alfa[6])
# print(beta[6])

ans1 = (alfa[0] * beta[3] * math.exp(w_tab['S']['A']))/alfa[6]
ans2 = (alfa[0] * beta[4] * math.exp(w_tab['S']['V']))/alfa[6]
ans3 = (alfa[0] * beta[5] * math.exp(w_tab['S']['N']))/alfa[6]
ans4 = (alfa[1] * beta[1] * math.exp(w_tab['A']['N']))/alfa[6]
ans5 = (alfa[1] * beta[2] * math.exp(w_tab['A']['V']))/alfa[6]
ans6 = (alfa[2] * beta[1] * math.exp(w_tab['V']['N']))/alfa[6]
ans7 = (alfa[2] * beta[2] * math.exp(w_tab['V']['V']))/alfa[6]
ans8 = (alfa[3] * beta[1] * math.exp(w_tab['N']['N']))/alfa[6]
ans9 = (alfa[3] * beta[2] * math.exp(w_tab['N']['V']))/alfa[6]
ans10 = (alfa[4] * beta[0] * math.exp(w_tab['N']['Sfin']))/alfa[6]
ans11 = (alfa[5] * beta[0] * math.exp(w_tab['V']['Sfin']))/alfa[6]

print(ans1)
print(ans2)
print(ans3)
print(ans4)
print(ans5)
print(ans6)
print(ans7)
print(ans8)
print(ans9)
print(ans10)
print(ans11)


w_tab['S']['A'] = w_tab['S']['A'] + (1-ans1)
w_tab['S']['V'] = w_tab['S']['V'] + (0-ans2)
w_tab['S']['N'] = w_tab['S']['N'] + (0-ans3)
w_tab['A']['N'] = w_tab['A']['N'] + (1-ans4)
w_tab['A']['V'] = w_tab['A']['V'] + (0-ans5)
w_tab['V']['N'] = w_tab['V']['N'] + (0-ans6)
w_tab['V']['V'] = w_tab['V']['V'] + (0-ans7)
w_tab['N']['N'] = w_tab['N']['N'] + (0-ans8)
w_tab['N']['V'] = w_tab['N']['V'] + (0-ans9)
w_tab['N']['Sfin'] = w_tab['N']['Sfin'] + (1-ans10)
w_tab['V']['Sfin'] = w_tab['V']['Sfin'] + (0-ans11)

print(w_tab)

以上是关于python CRF-SDM的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python