use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class PartitionTree method messageFromVariableToFactor.
public Bound messageFromVariableToFactor() {
Bound childrenProduct = this.childrenProduct();
Context context = this.model.getContext();
Theory theory = this.model.getTheory();
ArrayList<Expression> varToSum = this.getVarToSumInMessageFromVariableToFactor();
return childrenProduct.summingBound(varToSum, context, theory);
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class BasicTest method debug.
private void debug(Expression problem) {
Theory theory = new DifferenceArithmeticTheory(true, true);
Context context = new TrueContext(theory);
context = context.putGlobalObject(BRUTE_FORCE_CHECKING_OF_NON_CONDITIONAL_PROBLEMS, "Yes");
Expression symbolicSolution = theory.evaluate(problem, context);
println(symbolicSolution);
BruteForceInterpreter bruteForceInterpreter = new BruteForceCommonInterpreter();
Expression bruteForceSolution = bruteForceInterpreter.apply(problem, context);
println(bruteForceSolution);
Assert.assertEquals(bruteForceSolution, symbolicSolution);
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class SummationOnDifferenceArithmeticAndPolynomialStepSolverTest method runTest.
private void runTest(Expression variable, String constraintString, Expression body, Expression expected, Context context) {
Theory theory = context.getTheory();
SingleVariableDifferenceArithmeticConstraint constraint = new SingleVariableDifferenceArithmeticConstraint(variable, true, theory);
constraint = (SingleVariableDifferenceArithmeticConstraint) constraint.conjoin(parse(constraintString), context);
Expression typeExpression = context.getTypeExpressionOfRegisteredSymbol(variable);
SingleQuantifierEliminationProblem problem = new DefaultSingleQuantifierEliminationProblem(new Sum(), variable, typeExpression, constraint, body);
ExpressionStepSolver stepSolver = new SummationOnDifferenceArithmeticAndPolynomialStepSolver(problem);
Expression actual = stepSolver.solve(context);
expected = simplify(expected, context);
System.out.println("sum({{ (on " + variable + " in " + GrinderUtil.getTypeExpressionOfExpression(variable, context) + ") " + body + " : " + constraintString + " }} = " + actual + "\n");
if (!expected.equals(actual)) {
Expression difference = apply(MINUS, expected, actual);
Expression differenceResult = simplify(difference, context);
if (!differenceResult.equals(ZERO)) {
System.err.println("Expressions are not equal and even difference is not zero");
System.err.println("Expected: " + expected);
System.err.println("Actual: " + actual);
System.err.println("Difference: " + differenceResult);
fail("Expressions are not equal and even difference is not zero. Expected: " + expected + ", actual: " + actual);
}
}
// TODO: correctness test against grounding
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class ModelGenerator method MaxMinProbability.
public static Pair<Double, Double> MaxMinProbability(Bound b, Model m) {
Context context = m.getContext();
Theory theory = m.getTheory();
Expression query = m.getQuery().getValue();
Type type = context.getTypeOfRegisteredSymbol(query);
if (type.getName().equals("Boolean")) {
double maxProbabilityOfTrue = -1;
double minProbabilityOfTrue = 10;
if (b.isExtensionalBound()) {
DefaultExtensionalBound extensionalBound = (DefaultExtensionalBound) b;
List<Expression> listOfElements = extensionalBound.getArguments();
for (Expression distribution : listOfElements) {
// replace and evaluate
Expression replacingQueryByTrue = distribution.replaceAllOccurrences(query, parse("true"), context);
Expression evaluating = theory.evaluate(replacingQueryByTrue, context);
// convert to double
double value = evaluating.doubleValue();
// update max and min
if (value > maxProbabilityOfTrue) {
maxProbabilityOfTrue = value;
}
if (value < minProbabilityOfTrue) {
minProbabilityOfTrue = value;
}
}
Pair<Double, Double> result = new Pair<>(minProbabilityOfTrue, maxProbabilityOfTrue);
return result;
} else if (b.isIntensionalBound()) {
}
}
return null;
}
use of com.sri.ai.grinder.api.Theory in project aic-expresso by aic-sri-international.
the class BruteForceFallbackTheoryTest method runTest.
private static void runTest(String expressionString, String expectedString, String... symbolsAndTypes) {
Theory theory = new BruteForceFallbackTheory(new DifferenceArithmeticTheory(false, true));
Context context = new TrueContext(theory);
context = context.extendWithSymbolsAndTypes(symbolsAndTypes);
Expression expression = parse(expressionString);
Expression expected = parse(expectedString);
Expression actual = theory.evaluate(expression, context);
println(actual);
assertEquals(expected, actual);
}
Aggregations