mominbuet / jahmm

Automatically exported from code.google.com/p/jahmm
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Exception "Matrix not positive defined" when calculating probability of a sequence of observations #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi! First I want to thanks the authors for their grat job.

Now my problem. I´m using a Hmm<ObservationVector> object and therefore
every state has a OpdfMultiGaussian?. When I try to calculate the
probability of a sequence of observation with this hmm (probability()
function) I got the next exception:

Exception in thread "main" java.lang.IllegalArgumentException?: Matrix is
not positive defined

    at
be.ac.ulg.montefiore.run.distributions.SimpleMatrix?.decomposeCholesky(SimpleMat
rix?.java:241)
at
be.ac.ulg.montefiore.run.distributions.MultiGaussianDistribution?.covarianceL(Mu
ltiGaussianDistribution?.java:101)
at
be.ac.ulg.montefiore.run.distributions.MultiGaussianDistribution?.covarianceInv(
MultiGaussianDistribution?.java:112)
at
be.ac.ulg.montefiore.run.distributions.MultiGaussianDistribution?.probability(Mu
ltiGaussianDistribution?.java:159)
at
be.ac.ulg.montefiore.run.jahmm.OpdfMultiGaussian?.probability(OpdfMultiGaussian?
.java:94)
at
be.ac.ulg.montefiore.run.jahmm.OpdfMultiGaussian?.probability(OpdfMultiGaussian?
.java:1)
at
be.ac.ulg.montefiore.run.jahmm.ForwardBackwardCalculator?.computeAlphaInit(Forwa
rdBackwardCalculator?.java:111)
at
be.ac.ulg.montefiore.run.jahmm.ForwardBackwardCalculator?.computeAlpha(ForwardBa
ckwardCalculator?.java:92)
at
be.ac.ulg.montefiore.run.jahmm.ForwardBackwardCalculator?.<init>(ForwardBackward
Calculator?.java:63)
at
be.ac.ulg.montefiore.run.jahmm.ForwardBackwardCalculator?.<init>(ForwardBackward
Calculator?.java:81)
at be.ac.ulg.montefiore.run.jahmm.Hmm.probability(Hmm.java:248) at
hmmcrossings.testMultiGaussianHmm.main(testMultiGaussianHmm.java:75) 

Following I copy the hmm:

Hmm v1.0

NbStates 2

State
Pi 1
A 0.5 0.5 
MultiGaussianOPDF [ [ 4,972 0 ] [ [ 36.636 -0 ] [ -0 0 ] ] ]

State
Pi 0
A 0 0 
MultiGaussianOPDF [ [ 4,987 147 ] [ [ 6.423 93.219 ] [ 93.219 56.051 ] ] ]

I´ve tried sequences of observations with just one element and with hundred
of them. I guess the problem is in the covariances matrix but I ´m not sure.

I´m working on Windows

What I´m doing wrong?? Any solution or advice???

Thanks you for your help!!!

Original issue reported on code.google.com by alvaroka...@gmail.com on 12 Aug 2009 at 9:45

GoogleCodeExporter commented 9 years ago
Hello, i have the same problem.

It could be that the problem comes from rounding inaccuracy. Covariances matrix 
could
end up in very low values (like 0,000000....1) which will be rounded to zero by 
your
computer and throws this exception.

from the collected vectors it is not directly possible to gain information 
about in
which matrix those values will end up...!? i'm not sure about it, but this is 
the
only way i could find to get around this problem. How about removing

    if ((d = m[j][j] - d) <= 0.)
        throw new IllegalArgumentException("Matrix is not positive defined");

from "SimpleMatrix.java:256"? I know, this check is done for a later 
formular... but
collected vector should not end up in values <=0 anyways...?

(i have not checked it in my example yet, this is only an idea so far!)

Original comment by vamos.be...@gmail.com on 27 May 2010 at 10:30

GoogleCodeExporter commented 9 years ago
edit: watch out: there is an initialization in the if clause! You still need 
"d = m[j][j] - d;" there...

Original comment by vamos.be...@gmail.com on 27 May 2010 at 10:35

GoogleCodeExporter commented 9 years ago
Is Comment 1 the only solution? Is there a better way to get around this error?

Original comment by zephyre...@gmail.com on 17 Jul 2012 at 10:32

GoogleCodeExporter commented 9 years ago
Has anyone a working fix for the "Matrix not positive defined" error?!

Original comment by dallas0...@gmail.com on 5 Feb 2013 at 3:17

GoogleCodeExporter commented 9 years ago
I regularized the covariance matrix (given as an argument to 
OpdfMultiGaussian). Worked out in my case! 

Original comment by jensen....@gmail.com on 9 Aug 2013 at 1:44

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello,
does anybody have a fix for that?
if so please reply here.
Thank you.

Original comment by chris.mi...@gmail.com on 12 Aug 2014 at 5:25