Search in sources :

Example 1 with AnytimeExactBP

use of com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest method solveWithAnytimeExactBP.

private Expression solveWithAnytimeExactBP(Expression query, ExpressionFactorNetwork factorNetwork, Context context) {
    Expression result;
    println("\nSolving with Anytime\n");
    long initialTime = System.currentTimeMillis();
    ExactBPNode<Variable, Factor> exactBP = new ExpressionExactBP(query, factorNetwork);
    AnytimeExactBP<Variable, Factor> anytimeExactBP = new AnytimeExactBP<>(exactBP);
    Approximation<Factor> current = null;
    while (anytimeExactBP.hasNext()) {
        current = anytimeExactBP.next();
        println("Current bound on " + exactBP.getMessageVariable() + ": " + current);
    }
    long finalTime = System.currentTimeMillis();
    if (current == null) {
        throw new Error("Anytime BP should have at least one approximation, but had none.");
    } else {
        ExpressionFactor resultFactor = (ExpressionFactor) ((IntensionalConvexHullOfFactors) current).getFactor();
        result = PRAiSEUtil.normalize(query, resultFactor, context);
        println("P(" + exactBP.getMessageVariable() + "): " + result);
        println("Time: " + (finalTime - initialTime) + " ms.");
    }
    return result;
}
Also used : ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) AnytimeExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP) Expression(com.sri.ai.expresso.api.Expression) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) ExpressionExactBP(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionExactBP)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)1 AnytimeExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP)1 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)1 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)1 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)1 ExpressionExactBP (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionExactBP)1