Search in sources :

Example 6 with DefaultExpressionFactor

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());
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) CommonTheory(com.sri.ai.grinder.application.CommonTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Expression(com.sri.ai.expresso.api.Expression) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) Test(org.junit.Test)

Example 7 with DefaultExpressionFactor

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());
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) CommonTheory(com.sri.ai.grinder.application.CommonTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Expression(com.sri.ai.expresso.api.Expression) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 8 with DefaultExpressionFactor

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);
}
Also used : CommonTheory(com.sri.ai.grinder.application.CommonTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) CommonTheory(com.sri.ai.grinder.application.CommonTheory) LinearRealArithmeticTheory(com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory) Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Expression(com.sri.ai.expresso.api.Expression) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Example 9 with DefaultExpressionFactor

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;
}
Also used : DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) Expression(com.sri.ai.expresso.api.Expression)

Example 10 with DefaultExpressionFactor

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());
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) CommonTheory(com.sri.ai.grinder.application.CommonTheory) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

Aggregations

ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)16 DefaultExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)16 Context (com.sri.ai.grinder.api.Context)14 TrueContext (com.sri.ai.grinder.core.TrueContext)14 CommonTheory (com.sri.ai.grinder.application.CommonTheory)13 Test (org.junit.Test)13 Expression (com.sri.ai.expresso.api.Expression)12 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)12 ConstantFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor)12 Theory (com.sri.ai.grinder.api.Theory)9 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)9 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)9 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)9 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)9 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)9 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)9 ExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable)3 DefaultExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable)3 ArrayList (java.util.ArrayList)3 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)1