Perl Exercises
1. In
/home/bios546 is the file hmm_data.txt.
It contains data pertaining to the rain-or-sun, walk-clean-shop hidden
Markov model we discussed in class. The
file has 2 line: the first line is the weather on each day (R or S), and the second
line is the activity (W, C, or S). Input
this data, then split it so that each character goes into a separate array
element. There should thus be two
arrays, one for weather and the other for activity, and the array elements
should correspond so the same array index will give the weather and activity
for the same day. Then, determine the
emission probabilities for all 3 activities in each type of weather, and also
the transition probabilities (R -> R, R -> S, S -> R, and S ->
S).
2. Take what you wrote in #1 above and put the code that counts the transitions into a separate function that is called for each individual transition. Do the same for emissions: put the function that determines the type of emission and weather into a function that is called once for each day. Be sure to pass all variables in through the @_ array, and return all results with a return statement.