📄 continuousmixhmm.py
字号:
import ghmm# example code for a continuous HMM with gaussian mixtures as emissionsF = ghmm.Float() # emission domain of this modelA = [[0.25,0.5,0.25],[0.3,0.2,0.5],[0.3,0.3,0.4]] # transition matrix# Parameters of emission distributions # Interpretation of B matrix for the mixture case (Example with three states and three components each):# B = [ # [ ["mu11","mu12","mu13"],["sig11","sig12","sig13"],["w11","w12","w13"] ],# [ ["mu21","mu22","mu23"],["sig21","sig22","sig23"],["w21","w22","w23"] ],# [ ["mu31","mu32","mu33"],["sig31","sig32","sig33"],["w31","w32","w33"] ],# ]B = [[ [0.0,1.0,2.0],[1.0,2.5,5.5], [0.5,0.3,0.2]], [ [2.0,6.0,1.0],[1.0,0.5,0.7], [0.1,0.5,0.4]], [ [4.0,5.0,1.0],[1.0,2.5,2.0], [0.3,0.3,0.4]] ]pi = [1.0,0.0,0.0] # initial probabilities per statemodel = ghmm.HMMFromMatrices(F,ghmm.GaussianMixtureDistribution(F), A, B, pi)# modify model parameters (examples)p = model.getInitial(2)model.setInitial(2,0.5)model.setInitial(0,0.5) # re-set transition from state 0 to state 1trans = model.getTransition(0,1)model.setTransition(0,1,0.6)# re-setting emission of state 1model.setEmission(1,1,[5.0,0.6,0.2])# re-normalize model parametersmodel.normalize()print model# sample single sequence of length 50seq = model.sampleSingle(50)# sample 10 sequences of length 50seq_set = model.sample(10,50)# get log P(seq | model)logp = model.loglikelihood(seq)# cacluate viterbi path path = model.viterbi(seq)# train model parametersmodel.baumWelch(seq_set,5,0.01)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -