dattalab / pyhsmm-library-models

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

fix Viterbi assertion errors #1

Closed mattjj closed 11 years ago

mattjj commented 11 years ago
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-6-43d9ac658924> in <module>()
      1 lhsmmModel = pymouse.lhsmm.LHSMM(means, sigmas, n_iter=10, n_iter_burnin=10)
----> 2 lhsmmModel.fit(data)

/home/alexbw/Code/pymouse/lhsmm.py in fit(self, X, y)
    178         # Last, a Viterbi EM step.
    179         print "Maximum-likelihood calculation on the highest-likelihood sample"
--> 180         self.viterbi_em_likelihoods_ = self.hsmm_model.Viterbi_EM_fit()
    181 
    182         # Save the results

/home/alexbw/Code/pyhsmm/models.pyc in Viterbi_EM_fit(self)
    265 
    266     def Viterbi_EM_fit(self):
--> 267         return self.MAP_EM_fit()
    268 
    269     def MAP_EM_step(self):

/home/alexbw/Code/pyhsmm/basic/pybasicbayes/abstractions.pyc in MAP_EM_fit(self, tol, maxiter)
    211 
    212     def MAP_EM_fit(self,tol=1e-1,maxiter=100):
--> 213         return self._EM_fit(self.MAP_EM_step,tol=tol,maxiter=maxiter)
    214 
    215     @abc.abstractmethod

/home/alexbw/Code/pyhsmm/basic/pybasicbayes/abstractions.pyc in _EM_fit(self, method, tol, maxiter)
    184         likes = []
    185         for itr in xrange(maxiter):
--> 186             method()
    187             likes.append(self.log_likelihood())
    188             if len(likes) > 1:

/home/alexbw/Code/pyhsmm/models.pyc in MAP_EM_step(self)
    268 
    269     def MAP_EM_step(self):
--> 270         return self.Viterbi_EM_step()
    271 
    272     def Viterbi_EM_step(self):

/home/alexbw/Code/pyhsmm/plugins/pyhsmm_library_models/library_models.py in Viterbi_EM_step(self)
    308         for state, distn in enumerate(self.dur_distns):
    309             distn.max_likelihood(
--> 310                     [s.durations[s.stateseq_norep == state] for s in self.states_list])
    311 
    312     def reset(self,stateseq_norep=None,durations=None,

/home/alexbw/Code/pyhsmm/basic/pybasicbayes/distributions.pyc in max_likelihood(self, data, weights, *args, **kwargs)
   1603                     return super(Wrapper,self).max_likelihood(data-self.r,weights=None,*args,**kwargs)
   1604                 else:
-> 1605                     return super(Wrapper,self).max_likelihood([d-self.r for d in data],weights=None,*args,**kwargs)
   1606 
   1607     Wrapper.__name__ = cls.__name__ + 'Variant'

/home/alexbw/Code/pyhsmm/basic/pybasicbayes/distributions.pyc in max_likelihood(self, data, weights)
   1534     def max_likelihood(self,data,weights=None):
   1535         if weights is None:
-> 1536             n, tot = self._get_statistics(data)
   1537         else:
   1538             n, tot = self._get_weighted_statistics(data,weights)

/home/alexbw/Code/pyhsmm/basic/pybasicbayes/distributions.pyc in _get_statistics(self, data)
   1461             n, tot = data.shape[0], data.sum()
   1462         else:
-> 1463             assert all(np.all(d >= 0) for d in data)
   1464             n = sum(d.shape[0] for d in data)
   1465             tot = sum(d.sum() for d in data)

AssertionError: 
mattjj commented 11 years ago

Fixed in 37e862a (see correctness_tests/library-hsmm-synthetic-viterbi.py)