Search in sources :

Example 1 with ExpressionExactBP

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionExactBP 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)

Example 2 with ExpressionExactBP

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionExactBP in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest method solveWithExactBP.

private ExpressionFactor solveWithExactBP(Expression query, ExpressionFactorNetwork factorNetwork) {
    ExactBPNode<Variable, Factor> exactBP = new ExpressionExactBP(query, factorNetwork);
    ExpressionFactor result = (ExpressionFactor) exactBP.apply();
    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) 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

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