fixed error in calculating training improvement
fixed error in calculating training improvement

Model.log_probabiltiy() used to be able to take in multiple sequences, calculate the log probability of all the sequences given the model, and return that number. With the introduction of MultivariateDistribution, this had to be removed as it was impossible to distinguish between a multivariate distribution and passing in multiple sequences. However, I incorrectly patched this by calculating sum( Model.log_probability( sequence ) for sequence in sequences ). We do not want the sum of the log probabilities, we want the log-sum-exp of them, because we are adding probabilities, not log probabilities. 

This was fixed by using reduce( lambda x, y: pair_lse( x, y ), map( model.log_probability, sequences ) ). In short, this will map the log probability function onto all the sequences individually, and then perform pair_lse on a growing chain. As a recap, taken from the python documentation, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates ((((1+2)+3)+4)+5). In the same way, it would now calculate pair_lse( pair_lse( pair_lse( pair_lse( 1, 2 ), 3 ), 4 ), 5 ).
jmschrei/yahmm