Search in sources :

Example 46 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class SelectExpressionsSatisfyingComparisonStepSolverTest method test.

@Test
public void test() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new DifferenceArithmeticTheory(true, true));
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    List<String> expressionStrings;
    Expression bound;
    Expression expected;
    expressionStrings = list("I", "J");
    bound = parse("J");
    expected = parse("if I < J then list(I) else list()");
    runTest(expressionStrings, bound, expected, context);
    expressionStrings = list("I", "2", "J");
    bound = parse("3");
    expected = parse("if I < 3 then if J < 3 then list(I, 2, J) else list(I, 2) else if J < 3 then list(2, J) else list(2)");
    runTest(expressionStrings, bound, expected, context);
    expressionStrings = list();
    bound = parse("3");
    expected = parse("list()");
    runTest(expressionStrings, bound, expected, context);
    expressionStrings = list("I", "2", "J");
    bound = parse("infinity");
    expected = parse("list(I, 2, J)");
    runTest(expressionStrings, bound, expected, context);
    expressionStrings = list("I", "2", "J");
    bound = parse("-infinity");
    expected = parse("list()");
    runTest(expressionStrings, bound, expected, context);
    expressionStrings = list("I", "2", "infinity");
    bound = parse("3");
    expected = parse("if I < 3 then list(I, 2) else list(2)");
    runTest(expressionStrings, bound, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) Test(org.junit.Test)

Example 47 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class IntensionalSetConditionSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval nType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("N", nType.toString()), Arrays.asList(nType), context);
    simplifier = new IntensionalSetConditionSimplifier();
}
Also used : IntensionalSetConditionSimplifier(com.sri.ai.grinder.library.set.IntensionalSetConditionSimplifier) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 48 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class DistributeIntersectionOverUnionSimplifierTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new TupleTheory()));
    IntegerInterval intType = new IntegerInterval(1, 10);
    context = (Context) GrinderUtil.extendRegistryWith(map("M", intType.toString(), "N", intType.toString()), Arrays.asList(intType), context);
    simplifier = new DistributeIntersectionOverUnionSimplifier();
}
Also used : DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) DistributeIntersectionOverUnionSimplifier(com.sri.ai.grinder.library.set.invsupport.DistributeIntersectionOverUnionSimplifier) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

Example 49 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class Tests method main.

public static void main(String[] args) {
    // Theory initialization
    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);
    context = context.extendWithSymbolsAndTypes("A", "Boolean");
    Model m;
    String modelName;
    modelName = "Ising Model";
    m = new Model(IsingModel(3, 2, context, parse("Boolean")), theory, true);
    testFunction(modelName, m, true);
    // modelName = "Line Model";
    // m = new Model(lineModel(10, context, parse("Boolean")),theory, true);
    // 
    // testFunction(modelName, m,true);
    // 
    // modelName = "Binary Tree Model";
    // m = new Model(nTreeModel(4, 2, context, parse("Boolean")),theory, true);
    // 
    // testFunction(modelName, m,true);
    // 
    // modelName = "Random Model";
    // m = new Model(ModelGenerator.randomModel(8, 10, context, parse("Boolean")),theory, true);
    // 
    // testFunction(modelName, m,true);
    modelName = "Ising Model";
    List<List<TupleOfData>> listOdModelsToPrintInFile = new ArrayList<>();
    // m = new Model(IsingModel(20, 4, context, parse("Boolean")),theory, true);
    // List<InferenceResult> IsingModel2X2 = testing("IsingModel",m,2,2);
    // listOdModelsToPrintInFile.add(IsingModel2X2);
    // println("ok");
    // 
    // m = new Model(IsingModel(3, 3, context, parse("Boolean")),theory, true);
    // List<InferenceResult> IsingModel3X3 = testing("IsingModel",m,3,3);
    // listOdModelsToPrintInFile.add(IsingModel3X3);
    // println("ok");
    // 
    // m = new Model(IsingModel(3, 4, context, parse("Boolean")),theory, true);
    // List<InferenceResult> IsingModel3X4 = testing("IsingModel",m,3,4);
    // listOdModelsToPrintInFile.add(IsingModel3X4);
    // println("ok");
    // 
    // m = new Model(IsingModel(4, 4, context, parse("Boolean")),theory, true);
    // List<InferenceResult> IsingModel4X4 = testing("IsingModel",m,4,4);
    // listOdModelsToPrintInFile.add(IsingModel4X4);
    // println("ok");
    // 
    // //		m = new Model(IsingModel(4, 5, context, parse("Boolean")),theory, true);
    // //		List<InferenceResult> IsingModel4X5 = testing("IsingModel",m,4,5);
    // //		listOdModelsToPrintInFile.add(IsingModel4X5);
    // //		println("ok");
    // 
    // modelName = "Line Model";
    // m = new Model(lineModel(20, context, parse("Boolean")),theory, true);
    // List<InferenceResult> line10 = testing(modelName,m,4,5);
    // listOdModelsToPrintInFile.add(line10);
    // println("ok");
    modelName = "Binary Tree Model";
    m = new Model(IsingModel(4, 4, context, parse("Boolean")), theory, true);
    List<TupleOfData> btree = testing(modelName, m, 4, 5);
    listOdModelsToPrintInFile.add(btree);
    println("ok");
    testingAndWritingToFile(modelName + ".csv", listOdModelsToPrintInFile);
}
Also used : TrueContext(com.sri.ai.grinder.core.TrueContext) Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) 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) ArrayList(java.util.ArrayList) 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) Model(anytimeExactBeliefPropagation.Model.Model) IsingModel(anytimeExactBeliefPropagation.ModelGenerator.IsingModel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 50 with DifferenceArithmeticTheory

use of com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory in project aic-expresso by aic-sri-international.

the class InversionPerformanceEvaluationTest method setUp.

@Before
public void setUp() {
    context = new TrueContext(new CompoundTheory(new DifferenceArithmeticTheory(false, false), new EqualityTheory(false, false), new PropositionalTheory(), new TupleTheory()));
    updateContextWithIndexAndType("R", GrinderUtil.INTEGER_TYPE);
    context.conjoin(parse("R = 1"), context);
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) TrueContext(com.sri.ai.grinder.core.TrueContext) TupleTheory(com.sri.ai.grinder.theory.tuple.TupleTheory) Before(org.junit.Before)

Aggregations

DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)53 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)36 Context (com.sri.ai.grinder.api.Context)31 TrueContext (com.sri.ai.grinder.core.TrueContext)28 Expression (com.sri.ai.expresso.api.Expression)27 PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)26 Test (org.junit.Test)23 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)22 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)22 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)19 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)15 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)13 Before (org.junit.Before)12 Type (com.sri.ai.expresso.api.Type)10 Theory (com.sri.ai.grinder.api.Theory)7 FunctionType (com.sri.ai.expresso.type.FunctionType)6 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)5 LinkedHashMap (java.util.LinkedHashMap)5 StepSolver (com.sri.ai.grinder.api.StepSolver)4 UnificationStepSolver (com.sri.ai.grinder.theory.base.UnificationStepSolver)4