RenatoGeh / gospn

A free, open-source inference and learning library for Sum-Product Networks (SPN)
BSD 3-Clause "New" or "Revised" License
23 stars 5 forks source link

got NaN value #1

Closed pribadihcr closed 7 years ago

pribadihcr commented 7 years ago

hi @RenatoGeh

I tried run go main.go

I got the following error (sample): ... Creating new leaf... Sample size: 321, scope size: 1 Creating new leaf... Sample size: 321, scope size: 1 Creating new leaf... Testing instance 0. Should be classified as 8. Pr(X=0|E) = antilog(NaN) = NaN Pr(X=1|E) = antilog(NaN) = NaN Pr(X=2|E) = antilog(NaN) = NaN Pr(X=3|E) = antilog(NaN) = NaN Pr(X=4|E) = antilog(NaN) = NaN Pr(X=5|E) = antilog(NaN) = NaN Pr(X=6|E) = antilog(NaN) = NaN Pr(X=7|E) = antilog(NaN) = NaN Pr(X=8|E) = antilog(NaN) = NaN Pr(X=9|E) = antilog(NaN) = NaN Pr(X=10|E) = antilog(NaN) = NaN Pr(X=11|E) = antilog(NaN) = NaN Pr(X=12|E) = antilog(NaN) = NaN Pr(X=13|E) = antilog(NaN) = NaN Pr(X=14|E) = antilog(NaN) = NaN ...

Is it ok got NaN value?

THanks hcr

RenatoGeh commented 7 years ago

I suspect it's from the numerical error of summing the anti-logs in sum nodes. The bug comes from a temporary solution I ended up forgetting to patch. The way I had coded, every node's value is actually the log of the real value. For the sum node I converted it back from log, summed the values, and then reapplied the log to the summation. This causes enough numerical errors for Go to consider it NaN. I'm working on a fix.

RenatoGeh commented 7 years ago

I just pushed a possible fix for your issue. Just as an additional comment/advice: classification on the olivetti 3-bit dataset is not recommended. There are too few samples for each class, plus each instantiation of a class can be quite distinct from other instantiations of the same class. Another problem is the compression I had to apply on the dataset (from 8-bit to 3-bit), which may cause even worse results. Because of that, the olivetti faces dataset will likely result in very poor classifications. I recommend using olivetti for image completion and using other more dedicated datasets (like Caltech-101) for classification. I plan on adding a normalized (scaled to fit implementational restrictions) Caltech-101 dataset soon. Let me know if your issue has been resolved.

RenatoGeh commented 7 years ago

I ran several tests and the values output seem to be correct.

I'm closing this issue, @pribadihcr