Beispiel #1
0
def create_hmm():
    emit_states = range( len(vq.gen_alphabet()) )
    emit_domain = Alphabet( emit_states )

    trans_p = [ [0.9, 0.05 , 0.05],
                [ 0.1, 0.8 ,0.1],
                [ 0.1, 0.1, 0.8]]
    emit_p = generate_emit_p()
    pi = [ 0.9, 0.05, 0.05 ]

    return HMMFromMatrices( emit_domain,
                            DiscreteDistribution(emit_domain),
                            trans_p,
                            emit_p,
                            pi
                            ),emit_domain
Beispiel #2
0
def generate_emit_p():
    straight    = [ vq.dataset_to_alphabet(gen.straight())   for x in xrange(50) ]
    left_turns  = [ vq.dataset_to_alphabet(gen.left_turn())  for x in xrange(100) ]
    right_turns = [ vq.dataset_to_alphabet(gen.right_turn()) for x in xrange(100) ]
    data_sets = [ straight, left_turns, right_turns ]
    gen_data_set = { 0: {}, 1: {}, 2: {} }

    for idx, dataset in enumerate(data_sets):
        for sample in dataset: 
            for alpha in sample:
                if alpha not in gen_data_set[idx]:
                    gen_data_set[idx][alpha] = 1
                else:
                    gen_data_set[idx][alpha] += 1

    alpha_size = len(vq.gen_alphabet() )
    emit_p = [  [0.01 for x in xrange(alpha_size) ] for x in xrange(3) ]

    for idx, stats in gen_data_set.iteritems():
        for k,v in stats.iteritems():
            emit_p[idx][k] = v

    return normalize_emit_probabilites( emit_p )