dattalab / pyhsmm-library-models

library models built on top of pyhsmm
0 stars 1 forks source link

log_likelihood on LHSMM requires recomputation, even after resampling #57

Closed alexbw closed 10 years ago

alexbw commented 10 years ago

Calling model.log_likelihood() takes a long time on the LHSMM model, even after just having resampled (in parallel).

mattjj commented 10 years ago

The newer stuff (like subHMMs) save the log likelihood (you can see it being returned separately from the parallel message passing) and then save it in each state sequence object so that it can be immediately returned from a call to the state sequence object's log_likelihood method. Want to try backporting that feature to the LHSMM?

One hint is that if you have the betastarl messages, the log likelihood is computed by np.logaddexp.reduce(s.aBl[0] + s.pi_0 + betastarl[0]).

alexbw commented 10 years ago

Thanks, this is all taken care of on my end in my mixins.

On Fri, Dec 20, 2013 at 3:40 PM, Matthew Johnson notifications@github.comwrote:

The newer stuff (like subHMMs) save the log likelihood (you can see it being returned separately from the parallel message passing) and then save it in each state sequence object so that it can be immediately returned from a call to the state sequence object's log_likelihood method. Want to try backporting that feature to the LHSMM?

One hint is that if you have the betastarl messages, the log likelihood is computed by np.logaddexp.reduce(s.aBl[0] + s.pi_0 + betastarl[0]).

— Reply to this email directly or view it on GitHubhttps://github.com/dattalab/pyhsmm-library-models/issues/57#issuecomment-31039977 .

mattjj commented 10 years ago

I'm confused... does the LHSMM now return the likelihood without recomputation? That should be in pyhsmm (like the other models that support this feature), not in the interface wrapper.

alexbw commented 10 years ago

Nope, it's in my interface wrapper only. I took 20-30 mins to look where to make the replacement in library_models.py, but didn't see a clear spot to do it. I'll look again soon.

On Mon, Dec 23, 2013 at 11:49 AM, Matthew Johnson notifications@github.comwrote:

I'm confused... does the LHSMM now return the likelihood without recomputation? That should be in pyhsmm (like the other models that support this feature), not in the interface wrapper.

— Reply to this email directly or view it on GitHubhttps://github.com/dattalab/pyhsmm-library-models/issues/57#issuecomment-31129560 .

mattjj commented 10 years ago

It is a bit buried so we can work together on it. I should have been more helpful in my above comment.

Here's how the HMMStatesPython log_likelihood method :

    def log_likelihood(self):
        if self._loglike is None:
            self.messages_forwards_normalized() # NOTE: sets self._loglike
        return self._loglike

It counts on the messages routine to set self._loglike, and then just returns it. (When parameters change, the likelihood should change, so that cached value should be changed; that's what happens in the clear_caches method.)

I think that's a clean strategy, and we basically need to make it happen with the appropriate LHSMM states class. One way to be sure of which states class to use would be to use ipdb: set a breakpoint at the model's log_likelihood (or just import ipdb; ipdb.set_trace() right before calling model.log_likelihood()) and then step into the call to see where it's going and hence where it should be hitting a cache instead of re-running messages.