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