analog-garage / dimple

Dimple: Java and Matlab libraries for probabilistic inference
Apache License 2.0
80 stars 17 forks source link

Intermittent 'Energy value is NaN' for solving a Binomial factor with Gibbs #4

Closed mattbarr-g closed 10 years ago

mattbarr-g commented 10 years ago

I receive an 'Energy value is NaN' about half of the time when using Gibbs on a simple factor graph using a binomial factor in the Matlab interface. The other half of the time, it samples fine and I get beliefs roughly equivalent to the BP solve (which works fine).

Simplified Matlab code directly below and error included afterward.

fg = FactorGraph();
fg.Solver = 'gibbs';
fg.Solver.setNumSamples(1000);
fg.Solver.setScansPerSample(2);
fg.Solver.setBurnInScans(100);

% Birds that coule be around to make a decision
birds = Discrete(1:30);

% Chance of deciding to leave
decide = .9;

% Count of the positive decisions to leave
todepart=Discrete(1:30);

% Add the binomial factor for birds deciding
fg.addFactor('Binomial',birds,decide,todepart)

% Definitely 16 birds, definitely
birds.Input=[0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0];

fg.solve();

todepart.Belief

Error message:

Error using FactorGraph/genericSolve (line 981)
Java exception occurred:
com.analog.lyric.dimple.exceptions.DimpleException: com.analog.lyric.dimple.exceptions.DimpleException: Energy value is NaN
    at com.analog.lyric.dimple.solvers.core.SFactorGraphBase.isSolverRunning(SFactorGraphBase.java:421)
    at com.analog.lyric.dimple.model.core.FactorGraph.isSolverRunning(FactorGraph.java:2746)
    at com.analog.lyric.dimple.matlabproxy.PFactorGraphVector.isSolverRunning(PFactorGraphVector.java:225)
Caused by: com.analog.lyric.dimple.exceptions.DimpleException: Energy value is NaN
    at com.analog.lyric.dimple.solvers.gibbs.samplers.generic.CDFSampler.nextSample(CDFSampler.java:101)
    at com.analog.lyric.dimple.solvers.gibbs.SDiscreteVariable.update(SDiscreteVariable.java:160)
    at com.analog.lyric.dimple.model.variables.VariableBase.update(VariableBase.java:209)
    at com.analog.lyric.dimple.schedulers.scheduleEntry.NodeScheduleEntry.update(NodeScheduleEntry.java:47)
    at com.analog.lyric.dimple.solvers.gibbs.SFactorGraph.iterate(SFactorGraph.java:314)
    at com.analog.lyric.dimple.solvers.gibbs.SFactorGraph.burnIn(SFactorGraph.java:287)
    at com.analog.lyric.dimple.solvers.gibbs.SFactorGraph.solveOneStep(SFactorGraph.java:272)
    at com.analog.lyric.dimple.solvers.core.SFactorGraphBase.solve(SFactorGraphBase.java:204)
    at com.analog.lyric.dimple.solvers.core.SFactorGraphBase$3.run(SFactorGraphBase.java:392)
    at java.lang.Thread.run(Thread.java:722)

Error in FactorGraph/solve (line 543)
            obj.genericSolve(@() obj.VectorObject.startSolver(),...

Error in MatrixObject/subsref (line 55)
                            builtin('subsref',obj,S);

Error in run (line 23)
fg.solve();
mattbarr-g commented 10 years ago

Just a clarification, the error only occurs when input is provided to the Discrete making up the number of trials, not the when input is provided to the Discrete making up the success count.

analog-cbarber commented 10 years ago

Internally this is bug https://bugzilla.cdcdesign.analog.com/show_bug.cgi?id=83

jgbernstein commented 10 years ago

Fixed