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;
}
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;
}
Aggregations