Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApproxLP non stable results. #60

Open
rcabanasdepaz opened this issue Feb 14, 2021 · 2 comments
Open

ApproxLP non stable results. #60

rcabanasdepaz opened this issue Feb 14, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@rcabanasdepaz
Copy link
Collaborator

ApproxLP occasionally produces NaN results for queries that are solvable.

Consider this code:

        double eps = 0.000000001; // eps > 0. If set to 0.0, the inference will not work.

        DAGModel model = new DAGModel();
        int x = model.addVariable(2);
        int u = model.addVariable(3);
        model.addParent(x,u);

        BayesianFactor ifx = new BayesianFactor(model.getDomain(x,u));
        ifx.setData(new double[] {
                1., 0.,
                1., 0.,
                0., 1.,
        });
        model.setFactor(x, ifx);

        IntervalFactor ifu = new IntervalFactor(model.getDomain(u), model.getDomain());
        ifu.set(new double[] { 0, 0, 0.8-eps}, new double[] { 0.2, 0.2, 0.8 });
        model.setFactor(u, ifu);

        for(int i=0;i<100;i++) {
            ApproxLP2 inference = new ApproxLP2();
            double[] upper = inference.query(model, x).getUpper();
            System.out.println(Arrays.toString(upper));
        }

The out would be:

[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[NaN, NaN]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
[0.20000000099999993, 0.8]
...
``
@rcabanasdepaz rcabanasdepaz added the bug Something isn't working label Feb 14, 2021
@rcabanasdepaz rcabanasdepaz self-assigned this Feb 14, 2021
@rcabanasdepaz
Copy link
Collaborator Author

rcabanasdepaz commented Feb 14, 2021

With changes at a3beffb, now the random seed can be specified having always the same behaviour. So no this is reproducible:

        double eps = 0.000000001; // eps > 0. If set to 0.0, the inference will not work.

        DAGModel model = new DAGModel();
        int x = model.addVariable(2);
        int u = model.addVariable(3);
        model.addParent(x,u);

        BayesianFactor ifx = new BayesianFactor(model.getDomain(x,u));
        ifx.setData(new double[] {
                1., 0.,
                1., 0.,
                0., 1.,
        });
        model.setFactor(x, ifx);

        IntervalFactor ifu = new IntervalFactor(model.getDomain(u), model.getDomain());
        ifu.set(new double[] { 0, 0, 0.8-eps}, new double[] { 0.2, 0.2, 0.8 });
        model.setFactor(u, ifu);


        ApproxLP2 inference;
        RandomUtil.setRandomSeed(0);
        inference = new ApproxLP2();
        double[] upper = inference.query(model, x).getUpper();  // works: [0.20000000099999993, 0.8]
        System.out.println(Arrays.toString(upper));


        RandomUtil.setRandomSeed(22);
        inference = new ApproxLP2();
        upper = inference.query(model, x).getUpper();   //NaN, NaN
        System.out.println(Arrays.toString(upper));


Any idea? @davidhuber

@cbonesana
Copy link
Member

I noted something similar myself; with the same linear problem but different time and space, the solver return different results. No idea how to control that. Maybe is a know issue of the org.apache.commons.math3 library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants