KullbackLeiblerDistanceCalculator returning NaN

60 views
Skip to first unread message

Popolon

unread,
Jul 9, 2011, 5:33:43 AM7/9/11
to Jahmm HMM library
Hi, first of all I wanted to thank you for this package, since it is
quite awesome.

However, recently I've been having an issue with the
KullbackLeiblerDistanceCalculator. It is returning null, and I can't
understand why.

I have two lists of observations:

list1:
[0, 0, 1, 0, 0, 1, 0, 0, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 3, 3, 1, 3, 3,
1, 3]
[3, 3, 1, 3, 3, 1, 3, 3, 1, 4, 4, 1, 4, 4, 1, 4, 4, 1, 4, 0, 1, 0, 0,
1, 0, 0]
[2, 2, 1, 2, 0, 1, 4, 4, 1, 4, 4, 1, 4, 4, 1, 0, 0, 1, 0, 0, 1, 0]
[0, 0, 1, 0, 2, 1, 3, 3, 1, 2, 2, 1, 2, 0, 1, 0, 0, 1, 0, 0, 1, 0, 4,
1, 4, 4, 1, 4, 4, 1, 4, 4, 1, 3]
[2, 2, 1, 2, 0, 1, 4, 4, 1, 4, 0, 1, 0, 0, 1, 0, 0, 1, 4, 4, 1, 4]

list2:
[2, 2, 2, 2, 2, 2, 2, 0, 4, 4, 4, 4, 4, 4, 4, 0, 2, 0, 4, 0, 2, 0, 4,
0, 2, 2, 2, 2, 2, 2, 2, 0, 4, 4, 4, 4, 4, 4, 4]
[4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 4, 3, 2, 3, 4, 3, 2,
3, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2]
[2, 2, 2, 2, 0, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2,
2, 0, 4, 4, 4, 4, 4, 4, 4]
[2, 2, 2, 2, 0, 4, 4, 4, 4, 0, 2, 0, 4, 0, 2, 3, 4, 3, 2, 3, 4, 4, 4,
4, 0, 0, 0, 0, 0, 2, 2, 0, 4, 4, 2, 2, 2, 2, 2, 2, 2, 3]
[2, 2, 2, 2, 0, 4, 4, 4, 4, 0, 2, 0, 4, 0, 2, 0, 4, 0, 2, 2, 2, 2, 0,
4, 4, 4, 4, 4, 4, 4, 3]

And I learn two HMMs with 5 hidden states each in the following way:

Hmm<ObservationInteger> hmm1 = new Hmm<ObservationInteger>(nStates,new
OpdfIntegerFactory(action_table.size()));
Hmm<ObservationInteger> hmm2 = new Hmm<ObservationInteger>(nStates,new
OpdfIntegerFactory(action_table.size()));

BaumWelchLearner bwl = new BaumWelchLearner();
for (int i = 0; i < 10; i++) {
hmm1 = bwl.iterate(hmm1, lo1);
hmm2 = bwl.iterate(hmm2, lo2);
}

Then when I try to compute their distance, this call
"klc.distance(hmm2,hmm1)" returns a proper number, but this call
"klc.distance(hmm1,hmm2)", returns NaN. I've been trying to trace the
problem back, but it's a bit hard, since the computations take many
steps. I was wondering if any one has found this issue, and if you had
any tips.

Thanks a lot!

santi

Jean-Marc François

unread,
Jul 17, 2011, 5:05:04 PM7/17/11
to jahmm-...@googlegroups.com
Hi,

Are you sure there is a problem? The Kullback-Leibler distance is not
symetric, you might want to check the
KullbackLeiblerDistanceCalculator#symetricDistance() method.

Best,
Jean-Marc

Santi Ontañón

unread,
Jul 18, 2011, 11:54:36 AM7/18/11
to jahmm-...@googlegroups.com
Yeah, I know it is not symmetric. In fact, I've been playing around some more, and if instead of 10 iterations of the BaumWelchLearner, I run 1000 or 10000, I always get a NaN as a response from KullbackLeiblerDistanceCalculator, whatever the order.

I looked deeper into it, and I tracked down the problem to this:

In the scale method of the class ForwardBackwardScaledCalculator, the "sum" is sometimes zero, i.e. all the elements of "table" are 0. Since you then scale them all back dividing by "sum", they all get the "NaN" value.

Do you think the problem might be the way I call the BaumWelchLearner? Does it even make sense for all the elements in "table" to be 0?

Thanks a lot for your response!

santi

> --
> You received this message because you are subscribed to the Google Groups "Jahmm HMM library" group.
> To post to this group, send email to jahmm-...@googlegroups.com.
> To unsubscribe from this group, send email to jahmm-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/jahmm-discuss?hl=en.
>

Reply all
Reply to author
Forward
0 new messages