Search in sources :

Example 11 with FactorNode

use of anytimeExactBeliefPropagation.Model.Node.FactorNode in project aic-expresso by aic-sri-international.

the class Tests method testFunction.

private static void testFunction(String modelName, Model m, boolean printAll) {
    Iterator<FactorNode> bfsExpander = new BFS(m);
    IncrementalBeliefPropagationWithConditioning sbp = new IncrementalBeliefPropagationWithConditioning(m);
    println("Exploring " + modelName);
    Bound inferenceResult = null;
    double totalTime = 0;
    while (bfsExpander.hasNext()) {
        long tStart = System.currentTimeMillis();
        inferenceResult = sbp.expandAndComputeInference(bfsExpander);
        long tEnd = System.currentTimeMillis();
        long tDelta = tEnd - tStart;
        double time = tDelta / 1000.0;
        totalTime += time;
        // ModelGenerator.printModel(m, false);
        if (printAll) {
            println("Number of ExtremePoints : " + inferenceResult.getArguments().size());
            Pair<Double, Double> minAndMaxProbabilityofQueryequalsTrue = ModelGenerator.maxMinProbability(inferenceResult, m);
            println("Minimal probability of Query = true : " + minAndMaxProbabilityofQueryequalsTrue.first + "\nMaximal probability of Query = true :" + minAndMaxProbabilityofQueryequalsTrue.second + "\nLength of interval (that is, (max - min)) : " + (minAndMaxProbabilityofQueryequalsTrue.second - minAndMaxProbabilityofQueryequalsTrue.first) + "\nTime to compute this iteration:" + time + ". Toatal time : " + totalTime);
            println("----------------- AllExplored : " + m.AllExplored() + "-----------------");
        }
    }
    if (!printAll)
        println(inferenceResult);
    println("Computation with SGDPLL");
    long tStart = System.currentTimeMillis();
    Expression LVE = ModelGenerator.lveCalculation(m);
    long tEnd = System.currentTimeMillis();
    long tDelta = tEnd - tStart;
    double time = tDelta / 1000.0;
    println(LVE + "\n" + "\nTime to compute:" + time);
}
Also used : Expression(com.sri.ai.expresso.api.Expression) Bound(com.sri.ai.grinder.library.bounds.Bound) FactorNode(anytimeExactBeliefPropagation.Model.Node.FactorNode) BFS(anytimeExactBeliefPropagation.Model.BFS)

Aggregations

FactorNode (anytimeExactBeliefPropagation.Model.Node.FactorNode)11 VariableNode (anytimeExactBeliefPropagation.Model.Node.VariableNode)7 Expression (com.sri.ai.expresso.api.Expression)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 BFS (anytimeExactBeliefPropagation.Model.BFS)3 Bound (com.sri.ai.grinder.library.bounds.Bound)3 DefaultExtensionalMultiSet (com.sri.ai.expresso.core.DefaultExtensionalMultiSet)2 Node (anytimeExactBeliefPropagation.Model.Node.Node)1 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1