use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor in project aic-praise by aic-sri-international.
the class PolytopeTest method testGetEquivalentAtomicPolytope.
@Test
public void testGetEquivalentAtomicPolytope() {
product = Polytope.multiply(list(simplexU));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
println("Atomic polytope on u equivalent to " + product + ": " + actual);
expected = simplexU;
assertEquals(expected, actual);
product = Polytope.multiply(list(simplexU, convexHullUV));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
println("Atomic polytope on u equivalent to " + product + ": " + actual);
expected = simplexU;
assertEquals(expected, actual);
product = Polytope.multiply(list(simplexU, convexHullUFreeVBound, convexHullVW));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
println("Atomic polytope on u equivalent to " + product + ": " + actual);
expected = simplexU;
assertEquals(expected, actual);
product = Polytope.multiply(list(simplexU, convexHullUV));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
println("Atomic polytope on u equivalent to " + product + ": " + actual);
expected = simplexU;
assertEquals(expected, actual);
product = Polytope.multiply(list(simplexU, convexHullUFreeVBound));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
println("Atomic polytope on u equivalent to " + product + ": " + actual);
expected = simplexU;
assertEquals(expected, actual);
try {
product = Polytope.multiply(list(simplexU, convexHullUBoundVFree));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
fail("Should have failed because V is free in polytope but query is U");
} catch (AssertionError e) {
if (!e.getMessage().contains("free variables")) {
fail("Should have complained about free variables");
}
}
product = Polytope.multiply(list(convexHullUFreeVBound, convexHullVW));
actual = Polytopes.getEquivalentAtomicPolytopeOn(u, product);
println("Atomic polytope on u equivalent to " + product + ": " + actual);
ExpressionFactor expectedExpressionFactor = new DefaultExpressionFactor(parse("if U then if V then if W then 8 else 10 else 15 else if V then if W then 12 else 15 else 15"), context);
expected = new IntensionalConvexHullOfFactors(list(v, w), expectedExpressionFactor);
println(expected.toString());
println(actual.toString());
// factor are compared by reference, not value
assertEquals(expected.toString(), actual.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 testSumOut.
@Test
public void testSumOut() {
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes("U", "Boolean", "V", "Boolean");
ExpressionVariable u = new DefaultExpressionVariable(parse("U"));
List<ExpressionVariable> variablesToSumOut = new ArrayList<>();
variablesToSumOut.add(u);
ExpressionFactor factorUV = new DefaultExpressionFactor(parse("if U and V then 2 else 3"), context);
Factor summedOutFactor = factorUV.sumOut(variablesToSumOut);
assertEquals("if V then 5 else 6", summedOutFactor.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 testAdd2.
@Test
public void testAdd2() {
Theory theory = new CommonTheory();
Context context = new TrueContext(theory);
Expression a = DefaultSymbol.createSymbol("a");
ExpressionFactor aFactor = new DefaultExpressionFactor(a, context);
Factor result = (ExpressionFactor) aFactor.add(IDENTITY_FACTOR);
System.out.println(result.toString());
assertEquals("1 + a", result.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 testMultiply4.
@Test
public void testMultiply4() {
Theory theory = new CommonTheory();
Context context = new TrueContext(theory);
Expression a = DefaultSymbol.createSymbol("a");
ExpressionFactor aFactor = new DefaultExpressionFactor(a, context);
ConstantFactor tenFactor = new ConstantFactor(10.);
Factor result = aFactor.multiply(tenFactor);
assertEquals("10 * a", result.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 testAdd1.
@Test
public void testAdd1() {
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.add(bFactor);
assertEquals("a + b", abFactor.toString());
}
Aggregations