1 """Generic functions which are useful for working with HMMs.
2
3 This just collects general functions which you might like to use in
4 dealing with HMMs.
5 """
6
7 -def pretty_print_prediction(emissions, real_state, predicted_state,
8 emission_title = "Emissions",
9 real_title = "Real State",
10 predicted_title = "Predicted State",
11 line_width = 75):
12 """Print out a state sequence prediction in a nice manner.
13
14 Arguments:
15
16 o emissions -- The sequence of emissions of the sequence you are
17 dealing with.
18
19 o real_state -- The actual state path that generated the emissions.
20
21 o predicted_state -- A state path predicted by some kind of HMM model.
22 """
23
24 title_length = max(len(emission_title), len(real_title),
25 len(predicted_title)) + 1
26 seq_length = line_width - title_length
27
28
29 emission_title = emission_title.ljust(title_length)
30 real_title = real_title.ljust(title_length)
31 predicted_title = predicted_title.ljust(title_length)
32
33 cur_position = 0
34
35 while 1:
36 if (cur_position + seq_length) < len(emissions):
37 extension = seq_length
38 else:
39 extension = len(emissions) - cur_position
40
41 print "%s%s" % (emission_title,
42 emissions[cur_position:cur_position + seq_length])
43 print "%s%s" % (real_title,
44 real_state[cur_position:cur_position + seq_length])
45 print "%s%s\n" % (predicted_title,
46 predicted_state[cur_position:
47 cur_position + seq_length])
48
49 if (len(emissions) < (cur_position + seq_length)):
50 break
51
52 cur_position += seq_length
53