guyz / HMM

Python Hidden Markov Models framework
131 stars 66 forks source link

How to estimate covariance in logs? #2

Open anilmullapudi opened 7 years ago

anilmullapudi commented 7 years ago

Hi,

while calculating covariance matrix in logs, i have modified the _reestimateMixtures() method in the file _ContinuousHMM.py as follows.

` numer = numpy.matrix(numpy.zeros( (self.d,self.d), dtype=self.precision)) denom = numpy.matrix(numpy.zeros( (self.d,self.d), dtype=self.precision)) for t in xrange(len(observations)):

vector_as_mat = numpy.matrix( (observations[t]-self.means[j][m]), dtype=self.precision )
 numer += (self._eta(t,len(observations)-1)*numpy.exp(gamma_mix[t][j][m])*numpy.dot( vector_as_mat.T, vector_as_mat))
 denom += (self._eta(t,len(observations)-1)*numpy.exp(gamma_mix[t][j][m]))

covars_new[j][m] = numer/denom covars_new[j][m] = covars_new[j][m] + cov_prior[j][m]`

Problem is while training, some times the numer and denom in the above method are becoming zero's. and as a result, my covariance matrix contains all the Nan values.

Can anyone please help me, how to avoid covariance matrix not to contain nan values.

jitesharora commented 6 years ago

Hi anil, I was trying to use this codebase for continuous HMM and I am facing the same issue. Did you get it fixed or were you able to find a library online where a good implementation of this model is done. I have been stuck for many days. It would be great if you could help me out.

Thanks in Advance :)

ashu3194 commented 2 years ago

Pandas will ignore the pairwise correlation if it has a nan value in one of the observations