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