Search in sources :

Example 1 with BFS

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

the class Tests method testing3.

public static List<TupleOfData> testing3(String modelName, Model m, Integer... parameter) {
    List<TupleOfData> result = new ArrayList<TupleOfData>();
    int id = 0;
    m.clearExploredGraph();
    Iterator<FactorNode> bfsExpander = new BFS(m);
    IncrementalBeliefPropagationWithConditioning sbp = new IncrementalBeliefPropagationWithConditioning(m);
    while (bfsExpander.hasNext()) {
        TupleOfData t = new TupleOfData();
        long tStart = System.currentTimeMillis();
        Bound inferenceResult = sbp.expandAndComputeInference(bfsExpander);
        long tEnd = System.currentTimeMillis();
        long tDelta = tEnd - tStart;
        t.time = tDelta / 1000.0;
        t.typeOfComputationUsed = "S-BP";
        t.graphicalModelName = modelName;
        t.id = id++;
        t.numberOfExtremePoints = inferenceResult.getArguments().size();
        Pair<Double, Double> minAndMaxProbabilityofQueryequalsTrue = ModelGenerator.maxMinProbability(inferenceResult, m);
        t.minAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.first;
        t.maxAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.second;
        t.IntervalLength = t.maxAndMaxProbabilityofQueryequalsTrue - t.minAndMaxProbabilityofQueryequalsTrue;
        t.allExplored = m.AllExplored();
        for (int i = 0; i < parameter.length && i < t.parameter.length; i++) {
            t.parameter[i] = parameter[i];
        }
        result.add(t);
        println("....");
    }
    TupleOfData t = new TupleOfData();
    long tStart = System.currentTimeMillis();
    Expression inferenceLVE = ModelGenerator.lveCalculation(m);
    Bound EncapsulatingInference = Bounds.makeSingleElementBound(inferenceLVE, true);
    Pair<Double, Double> minAndMaxProbabilityofQueryequalsTrue = ModelGenerator.maxMinProbability(EncapsulatingInference, m);
    long tEnd = System.currentTimeMillis();
    long tDelta = tEnd - tStart;
    t.time = tDelta / 1000.0;
    t.minAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.first;
    t.maxAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.second;
    t.typeOfComputationUsed = "SGDPLL";
    t.graphicalModelName = modelName;
    t.id = id++;
    t.numberOfExtremePoints = 0;
    t.IntervalLength = 0;
    t.allExplored = true;
    for (int i = 0; i < parameter.length && i < t.parameter.length; i++) {
        t.parameter[i] = parameter[i];
    }
    result.add(t);
    println("------------------------------------------------------------");
    return result;
}
Also used : ArrayList(java.util.ArrayList) Bound(com.sri.ai.grinder.library.bounds.Bound) FactorNode(anytimeExactBeliefPropagation.Model.Node.FactorNode) BFS(anytimeExactBeliefPropagation.Model.BFS) Expression(com.sri.ai.expresso.api.Expression)

Example 2 with BFS

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

the class Tests method testing.

/**
 * This tests a model and, instead of printing information, stores its in a list of data structures
 * each element of the list corresponds to a iteration of the algorithm
 * @param modelName
 * @param m
 * @param parameter
 * @return
 */
public static List<TupleOfData> testing(String modelName, Model m, Integer... parameter) {
    List<TupleOfData> result = new ArrayList<TupleOfData>();
    int id = 0;
    m.clearExploredGraph();
    Iterator<FactorNode> bfsExpander = new BFS(m);
    IncrementalBeliefPropagationWithConditioning sbp = new IncrementalBeliefPropagationWithConditioning(m);
    double tTotalTime = 0;
    while (bfsExpander.hasNext()) {
        TupleOfData t = new TupleOfData();
        long tStart = System.currentTimeMillis();
        Bound inferenceResult = sbp.expandAndComputeInference(bfsExpander);
        long tEnd = System.currentTimeMillis();
        long tDelta = tEnd - tStart;
        t.time = tDelta / 1000.0;
        tTotalTime += tDelta / 1000.0;
        t.totalTime += tTotalTime;
        t.typeOfComputationUsed = "S-BP";
        t.graphicalModelName = modelName;
        t.id = id++;
        t.numberOfExtremePoints = inferenceResult.getArguments().size();
        Pair<Double, Double> minAndMaxProbabilityofQueryequalsTrue = ModelGenerator.maxMinProbability(inferenceResult, m);
        t.minAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.first;
        t.maxAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.second;
        t.IntervalLength = t.maxAndMaxProbabilityofQueryequalsTrue - t.minAndMaxProbabilityofQueryequalsTrue;
        t.allExplored = m.AllExplored();
        for (int i = 0; i < parameter.length && i < t.parameter.length; i++) {
            t.parameter[i] = parameter[i];
        }
        result.add(t);
        println("....");
    }
    TupleOfData t = new TupleOfData();
    long tStart = System.currentTimeMillis();
    Expression inferenceLVE = ModelGenerator.lveCalculation(m);
    Bound encapsulatingInference = Bounds.makeSingleElementBound(inferenceLVE, true);
    Pair<Double, Double> minAndMaxProbabilityofQueryequalsTrue = ModelGenerator.maxMinProbability(encapsulatingInference, m);
    long tEnd = System.currentTimeMillis();
    long tDelta = tEnd - tStart;
    t.time = tDelta / 1000.0;
    t.totalTime = t.time;
    t.minAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.first;
    t.maxAndMaxProbabilityofQueryequalsTrue = minAndMaxProbabilityofQueryequalsTrue.second;
    t.typeOfComputationUsed = "SGDPLL";
    t.graphicalModelName = modelName;
    t.id = id++;
    t.numberOfExtremePoints = 0;
    t.IntervalLength = 0;
    t.allExplored = true;
    for (int i = 0; i < parameter.length && i < t.parameter.length; i++) {
        t.parameter[i] = parameter[i];
    }
    result.add(t);
    println("------------------------- Done -----------------------------------");
    return result;
}
Also used : ArrayList(java.util.ArrayList) Bound(com.sri.ai.grinder.library.bounds.Bound) FactorNode(anytimeExactBeliefPropagation.Model.Node.FactorNode) BFS(anytimeExactBeliefPropagation.Model.BFS) Expression(com.sri.ai.expresso.api.Expression)

Example 3 with BFS

use of anytimeExactBeliefPropagation.Model.BFS 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

BFS (anytimeExactBeliefPropagation.Model.BFS)3 FactorNode (anytimeExactBeliefPropagation.Model.Node.FactorNode)3 Expression (com.sri.ai.expresso.api.Expression)3 Bound (com.sri.ai.grinder.library.bounds.Bound)3 ArrayList (java.util.ArrayList)2