Search in sources :

Example 26 with PropositionalTheory

use of com.sri.ai.grinder.theory.propositional.PropositionalTheory in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas.

@Test
public void testCompoundTheoryWithDifferenceArithmeticWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    // using different testing variables and types to test distribution of testing information
    // to sub constraint theories.
    Categorical booleanType = BOOLEAN_TYPE;
    Categorical dogsType = new Categorical("Dogs", 4, arrayList(parse("fido"), parse("rex")));
    IntegerInterval oneTwoThree = new IntegerInterval(1, 3);
    Map<String, Type> variablesAndTypes = map("F", booleanType, "G", booleanType, "R", dogsType, "S", dogsType, "T", oneTwoThree, "U", oneTwoThree);
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 27 with PropositionalTheory

use of com.sri.ai.grinder.theory.propositional.PropositionalTheory in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testCompoundTheoryWithoutDifferenceArithmeticWithRandomDisjunctiveFormulas.

@Test
public void testCompoundTheoryWithoutDifferenceArithmeticWithRandomDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    runRandomDisjunctiveFormulasTest(theoryTestingSupport);
}
Also used : EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) Test(org.junit.Test)

Example 28 with PropositionalTheory

use of com.sri.ai.grinder.theory.propositional.PropositionalTheory in project aic-expresso by aic-sri-international.

the class ExpressionStepSolverToLiteralSplitterStepSolverAdapterTest method testPropositionalTheoryWithFixedDisjunctiveFormulas.

@Test
public void testPropositionalTheoryWithFixedDisjunctiveFormulas() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new PropositionalTheory());
    extendTestingVariables("P", theoryTestingSupport, "S", "T");
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    runTest(theoryTestingSupport, new GeneralFormulaExpressionTestStepSolver(Expressions.parse("P"), Expressions.parse("Q")), Expressions.parse("if P then if Q then P and Q else P and not Q else if Q then not P and Q else not P and not Q"), context);
    runTest(theoryTestingSupport, new GeneralFormulaExpressionTestStepSolver(Expressions.parse("P or Q"), Expressions.parse("R or Q")), Expressions.parse("if P then if R then (P or Q) and (R or Q) else if Q then (P or Q) and (R or Q) else (P or Q) and not (R or Q) else if Q then (P or Q) and (R or Q) else if R then not (P or Q) and (R or Q) else not (P or Q) and not (R or Q)"), context);
    runTest(theoryTestingSupport, new GeneralFormulaExpressionTestStepSolver(Expressions.parse("P or Q"), Expressions.parse("R or S")), Expressions.parse("if P then if R then (P or Q) and (R or S) else if S then (P or Q) and (R or S) else (P or Q) and not (R or S) else if Q then if R then (P or Q) and (R or S) else if S then (P or Q) and (R or S) else (P or Q) and not (R or S) else if R then not (P or Q) and (R or S) else if S then not (P or Q) and (R or S) else not (P or Q) and not (R or S)"), context);
}
Also used : Context(com.sri.ai.grinder.api.Context) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) Test(org.junit.Test)

Example 29 with PropositionalTheory

use of com.sri.ai.grinder.theory.propositional.PropositionalTheory 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;
    Triple<Set<Expression>, Context, Expression> a = IsingModel(4, 4, context, parse("Boolean"));
    println(a);
    m = new Model(a, theory, true);
    Expression b = ModelGenerator.lveCalculation(m);
    println(b);
    // 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) Set(java.util.Set) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) 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) Expression(com.sri.ai.expresso.api.Expression) IsingModel(anytimeExactBeliefPropagation.ModelGenerator.IsingModel) Model(anytimeExactBeliefPropagation.Model.Model) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with PropositionalTheory

use of com.sri.ai.grinder.theory.propositional.PropositionalTheory in project aic-expresso by aic-sri-international.

the class EvaluationTest method testEvaluationOfCardinalityExpressions.

@Test
public void testEvaluationOfCardinalityExpressions() {
    TheoryTestingSupport theoryTestingSupport = TheoryTestingSupport.make(makeRandom(), new CompoundTheory(new EqualityTheory(false, true), new DifferenceArithmeticTheory(false, true), new PropositionalTheory()));
    Map<String, Type> variablesAndTypes = new LinkedHashMap<>(theoryTestingSupport.getVariableNamesAndTypesForTesting());
    Type booleanType = variablesAndTypes.get("P");
    variablesAndTypes.put("S", booleanType);
    variablesAndTypes.put("T", booleanType);
    variablesAndTypes.put("U", booleanType);
    theoryTestingSupport.setVariableNamesAndTypesForTesting(variablesAndTypes);
    Context context = theoryTestingSupport.makeContextWithTestingInformation();
    String expressionString;
    Expression expected;
    expressionString = "| {{ (on I in 1..10) 3 : I != 4 and P }} |";
    expected = parse("if P then 9 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| I in 1..10 : I != 4 and P |";
    expected = parse("if P then 9 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on ) 3 : I != 4 and P }} |";
    expected = parse("if I != 4 then if P then 1 else 0 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| : I != 4 and P |";
    expected = parse("if I != 4 then if P then 1 else 0 else 0");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on ) 3 : P and not P }} |";
    expected = parse("0");
    runTest(expressionString, expected, context);
    expressionString = "| : P and not P |";
    expected = parse("0");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on I in 1..10, J in 1..2) 3 : I != 4 }} |";
    expected = parse("18");
    runTest(expressionString, expected, context);
    expressionString = "| I in 1..10, J in 1..2 : I != 4 |";
    expected = parse("18");
    runTest(expressionString, expected, context);
    expressionString = "| {{ (on I in 1..10, P in Boolean) 3 : I != 4 }} |";
    expected = parse("18");
    runTest(expressionString, expected, context);
    expressionString = "| I in 1..10, P in Boolean: I != 4 |";
    expected = parse("18");
    runTest(expressionString, expected, context);
}
Also used : Context(com.sri.ai.grinder.api.Context) EqualityTheory(com.sri.ai.grinder.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) Expression(com.sri.ai.expresso.api.Expression) TheoryTestingSupport(com.sri.ai.grinder.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) PropositionalTheory(com.sri.ai.grinder.theory.propositional.PropositionalTheory) CompoundTheory(com.sri.ai.grinder.theory.compound.CompoundTheory) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

PropositionalTheory (com.sri.ai.grinder.theory.propositional.PropositionalTheory)39 CompoundTheory (com.sri.ai.grinder.theory.compound.CompoundTheory)33 DifferenceArithmeticTheory (com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory)32 EqualityTheory (com.sri.ai.grinder.theory.equality.EqualityTheory)30 Context (com.sri.ai.grinder.api.Context)25 Expression (com.sri.ai.expresso.api.Expression)23 TrueContext (com.sri.ai.grinder.core.TrueContext)19 TheoryTestingSupport (com.sri.ai.grinder.tester.TheoryTestingSupport)18 Test (org.junit.Test)17 LinearRealArithmeticTheory (com.sri.ai.grinder.theory.linearrealarithmetic.LinearRealArithmeticTheory)16 Theory (com.sri.ai.grinder.api.Theory)11 TupleTheory (com.sri.ai.grinder.theory.tuple.TupleTheory)11 Type (com.sri.ai.expresso.api.Type)8 LinkedHashMap (java.util.LinkedHashMap)6 FunctionType (com.sri.ai.expresso.type.FunctionType)4 StepSolver (com.sri.ai.grinder.api.StepSolver)4 AbstractTheoryTestingSupport (com.sri.ai.grinder.core.constraint.AbstractTheoryTestingSupport)4 Rewriter (com.sri.ai.grinder.rewriter.api.Rewriter)4 UnificationStepSolver (com.sri.ai.grinder.theory.base.UnificationStepSolver)4 Before (org.junit.Before)4