use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor in project aic-praise by aic-sri-international.
the class ExpressionFactorTest method testGetVariables.
@Test
public void testGetVariables() {
Theory theory = new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, false), new LinearRealArithmeticTheory(false, false), new TupleTheory(), new PropositionalTheory());
Context context = new TrueContext(theory);
Expression expression = parse("{{ (on I in 1..10) I + J }}");
Factor factor = new DefaultExpressionFactor(expression, context);
List<? extends Variable> factorFreeVariables = factor.getVariables();
assertEquals(1, factorFreeVariables.size());
assertEquals("[J]", factorFreeVariables.toString());
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor in project aic-praise by aic-sri-international.
the class ExpressionFactorTest method testMultiply1.
@Test
public void testMultiply1() {
Theory theory = new CommonTheory();
Context context = new TrueContext(theory);
Expression a = DefaultSymbol.createSymbol("a");
ExpressionFactor aFactor = new DefaultExpressionFactor(a, context);
Expression b = DefaultSymbol.createSymbol("b");
ExpressionFactor bFactor = new DefaultExpressionFactor(b, context);
Factor abFactor = (ExpressionFactor) aFactor.multiply(bFactor);
assertEquals("a * b", abFactor.toString());
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor in project aic-praise by aic-sri-international.
the class ExpressionFactorTest method testMultiply2.
@Test
public void testMultiply2() {
Theory theory = new CommonTheory();
Context context = new TrueContext(theory);
Expression a = DefaultSymbol.createSymbol("a");
ExpressionFactor aFactor = new DefaultExpressionFactor(a, context);
Factor result = (ExpressionFactor) aFactor.multiply(IDENTITY_FACTOR);
assertEquals(aFactor, result);
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor in project aic-praise by aic-sri-international.
the class ExactBPExpressionBasedSolver method replaceQuerySymbolByQueryExpressionIfNeeded.
protected Expression replaceQuerySymbolByQueryExpressionIfNeeded(ExpressionBasedProblem problem, Expression normalizedMarginal) {
ExpressionFactor expressionFactor = (ExpressionFactor) normalizedMarginal;
Expression normalizedMarginalWithQueryExpression = super.replaceQuerySymbolByQueryExpressionIfNeeded(problem, normalizedMarginal);
ExpressionFactor result = new DefaultExpressionFactor(normalizedMarginalWithQueryExpression, expressionFactor.getContext());
result.setExplanation(expressionFactor.getExplanation());
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor in project aic-praise by aic-sri-international.
the class ExpressionFactorTest method testInvert.
@Test
public void testInvert() {
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes("U", "Boolean", "V", "Boolean");
ExpressionFactor factorUV = new DefaultExpressionFactor(parse("if U and V then 2 else 3"), context);
Factor invertedFactor = factorUV.invert();
assertEquals("if U then if V then 0.5 else 1/3 else 1/3", invertedFactor.toString());
}
Aggregations