Esempio n. 1
0
import ghmmwrapper
import ghmmhelper
import class_change


# A list of two transition matrices
swA = [
	[[0.9,0.1],[0.2,0.8]],
	[[0.3,0.7],[0.7,0.3]]
	]


# Interpretation of B matrix for the mixture case (Example with two states and two components each):
#  B = [ 
#      [  ["mu11","mu12"],["sig11","sig12"],["w11","w12"]   ],
#      [  ["mu21","mu22"],["sig21","sig22"],["w21","w22"]  ]
#      ]
# Note: below are two components with same mean for each state
swB = [ [[0.0,0.0],[0.5,0.5],[0.5,0.5]],
		[[10.0,10.0],[0.5,0.5],[0.5,0.5]] ]
swpi = [0.5,0.5]

swmodel = ghmm.HMMFromMatrices(ghmm.Float(),ghmm.GaussianMixtureDistribution(ghmm.Float), swA, swB, swpi)
swshort = ghmm.EmissionSequence(ghmm.Float(),[10.0]*4+[0.0]*5+[10.0]*4+[0.0]+[10.0]*5)

ghmmwrapper.setPythonSwitching(swmodel.cmodel,"class_change","getClass1")
swmodel.baumWelch(swshort,5,0.2)

ghmmwrapper.setPythonSwitching(swmodel.cmodel,"class_change","getClass2")
swmodel.baumWelch(swshort,5,0.2)
Esempio n. 2
0
def do1():

     # Interpretation of B matrix for the mixture case (Example with three states and two components each):
                    #  B = [ 
                    #      [ ["mu11","mu12"],["sig11","sig12"],["w11","w12"]   ],
                    #      [  ["mu21","mu22"],["sig21","sig22"],["w21","w22"]  ],
                    #      [  ["mu31","mu32"],["sig31","sig32"],["w31","w32"]  ],
                    #      ]



    F = ghmm.Float()            		   
    m2 = ghmm.HMMFromMatrices(F,ghmm.GaussianMixtureDistribution(F),
                             [[0.0,1.0,0],[0.5,0.0,0.5],[0.3,0.3,0.4]],
                          
                             [
                             [ [0.0,1.0],[1.0,0.5], [0.6,0.4] ],
                             [ [2.0,1.0],[1.0,0.5], [0.8,0.2] ],
                             [ [15.0,1.0],[1.0,0.5], [0.8,0.2] ]
                             ],
                         
                             [1.0,0,0])





    A = [[0.9,0.1],[0.2,0.8]]
    B = [ [[0.0,0.0],[0.1,0.1],[0.5,0.5]],
        [[10.0,10.0],[0.1,0.1],[0.5,0.5]] ]
    pi = [0.0,1.0]
    model = ghmm.HMMFromMatrices(ghmm.Float(),ghmm.GaussianMixtureDistribution(ghmm.Float), A, B, pi)

    #short = ghmm.EmissionSequence(ghmm.Float(),[0.0,10.0,10.0,0.0,10.0,0.0,10.0,10.0,0.0])
    #short2 = ghmm.EmissionSequence(ghmm.Float(),[10.0,0.0]*6)


    #print model
    #model.baumWelch(short2,1,0.2)
    #print model

    #def getClass(seq, k,t):
    #    classes = [0] * 10 + [1] * 10
    #    return classes[t]


    swA = [
        [[0.9,0.1],[0.2,0.8]],
        [[0.3,0.7],[0.7,0.3]]
        ]

    swB = [ [[0.0,0.0],[0.1,0.1],[0.5,0.5]],
        [[10.0,10.0],[0.1,0.1],[0.5,0.5]] ]
    swpi = [0.5,0.5]
    swmodel = ghmm.HMMFromMatrices(ghmm.Float(),ghmm.GaussianMixtureDistribution(ghmm.Float), swA, swB, swpi)
    ghmmwrapper.ghmm_c_class_change_alloc(swmodel.cmodel)


    swshort = ghmm.EmissionSequence(ghmm.Float(),[10.0]+[0.0]*5+[0.0]+[10.0]*5)

    classes = [0] * 12
    unique = class_change.testChange()
    unique.setData(classes)

    unique([],1,1)

    ghmmwrapper.setPythonSwitching(swmodel.cmodel,"XXXX","unique")   # "class_change","getClass"

    
    #print swshort

    swmodel.baumWelch(swshort,5,0.2)