Search in sources :

Example 26 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class GrinderUtilTest method testIsCategoricalTypeSubtypeOf.

@Test
public void testIsCategoricalTypeSubtypeOf() {
    Categorical categoricalType = new Categorical("TestCategorical1", 10, parse("a"), parse("b"), parse("c"));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, BOOLEAN_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, INTEGER_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, REAL_TYPE));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new IntegerInterval("Integer")));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new IntegerInterval("0..4")));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new RealInterval("Real")));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new RealInterval("[-0.5;4.5]")));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new FunctionType(categoricalType)));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new FunctionType(categoricalType, categoricalType)));
    // NOTE: Categorical types equality is based on name.
    Assert.assertTrue(isTypeSubtypeOf(categoricalType, new Categorical("TestCategorical1", 10, parse("a"), parse("b"), parse("c"))));
    Assert.assertTrue(isTypeSubtypeOf(categoricalType, new Categorical("TestCategorical1", 5, parse("x"), parse("y"), parse("z"))));
    Assert.assertFalse(isTypeSubtypeOf(categoricalType, new Categorical("TestCategorical2", 10, parse("a"), parse("b"), parse("c"))));
}
Also used : IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) FunctionType(com.sri.ai.expresso.type.FunctionType) Categorical(com.sri.ai.expresso.type.Categorical) RealInterval(com.sri.ai.expresso.type.RealInterval) Test(org.junit.Test)

Example 27 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method testCategoricalEg1.

@Test
public void testCategoricalEg1() {
    updateContextWithIndexAndType("N", new Categorical("Person", 100));
    String intensionalSet = "{{(on I in Person) if I != person1 then 20 else 30 : I != person2 }}";
    String[][] functionNamesAndExactValues = new String[][] { { "sum", "1990" }, { "max", "30" }, { "product", "950737950171172051122527404032000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } };
    runSampleCompareToExact(100, true, intensionalSet, functionNamesAndExactValues);
}
Also used : Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 28 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class LambdaBetaReductionSimplifierTest method testSimpleReduction.

@Test
public void testSimpleReduction() {
    Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("ann"), makeSymbol("bob")));
    Context context = new TrueContext();
    context = context.add(peopleType);
    Assert.assertEquals(parse("if X = ann then 0 else if X = bob then 0 else 0"), simplifier.apply(parse("(lambda : if X = ann then 0 else if X = bob then 0 else 0)()"), context));
    Assert.assertEquals(parse("if ann = ann then 0 else if ann = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People : if X = ann then 0 else if X = bob then 0 else 0)(ann)"), context));
    Assert.assertEquals(parse("if ann = ann then 0 else if bob = bob then 0 else 0"), simplifier.apply(parse("(lambda X in People, Y in People : if X = ann then 0 else if Y = bob then 0 else 0)(ann, bob)"), context));
}
Also used : TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Context(com.sri.ai.grinder.sgdpllt.api.Context) Type(com.sri.ai.expresso.api.Type) Categorical(com.sri.ai.expresso.type.Categorical) TrueContext(com.sri.ai.grinder.sgdpllt.core.TrueContext) Test(org.junit.Test)

Example 29 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class SampleCommonInterpreterTest method testSumOverCategoricalDomain.

@Test
public void testSumOverCategoricalDomain() {
    updateContextWithIndexAndType("N", new Categorical("People", 5, parse("p1"), parse("p2"), parse("p3"), parse("p4"), parse("p5")));
    // NOTE: random picks p1 and p2
    runTest(2, true, "sum({{(on N in People) 2}})", "10");
    // NOTE: keep this order of calls as the fixed Random will pick p3 and p4
    runTest(2, true, "sum({{(on N in People) if N = p3 then 4 else 2}})", "15");
    // NOTE: picks p5 and p5
    runTest(2, true, "sum({{(on N in People) 2 : N != p2}})", "8");
}
Also used : Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 30 with Categorical

use of com.sri.ai.expresso.type.Categorical in project aic-expresso by aic-sri-international.

the class CompoundTheoryWithDifferenceArithmeticTest method makeTheoryTestingSupport.

@Override
protected TheoryTestingSupport makeTheoryTestingSupport() {
    TheoryTestingSupport result = 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);
    result.setVariableNamesAndTypesForTesting(variablesAndTypes);
    return result;
}
Also used : EqualityTheory(com.sri.ai.grinder.sgdpllt.theory.equality.EqualityTheory) Type(com.sri.ai.expresso.api.Type) AbstractTheoryTestingSupport(com.sri.ai.grinder.sgdpllt.core.constraint.AbstractTheoryTestingSupport) TheoryTestingSupport(com.sri.ai.grinder.sgdpllt.tester.TheoryTestingSupport) DifferenceArithmeticTheory(com.sri.ai.grinder.sgdpllt.theory.differencearithmetic.DifferenceArithmeticTheory) IntegerInterval(com.sri.ai.expresso.type.IntegerInterval) PropositionalTheory(com.sri.ai.grinder.sgdpllt.theory.propositional.PropositionalTheory) Categorical(com.sri.ai.expresso.type.Categorical) CompoundTheory(com.sri.ai.grinder.sgdpllt.theory.compound.CompoundTheory)

Aggregations

Categorical (com.sri.ai.expresso.type.Categorical)39 Test (org.junit.Test)30 Type (com.sri.ai.expresso.api.Type)19 Expression (com.sri.ai.expresso.api.Expression)13 IntegerInterval (com.sri.ai.expresso.type.IntegerInterval)10 FunctionType (com.sri.ai.expresso.type.FunctionType)6 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)5 RealInterval (com.sri.ai.expresso.type.RealInterval)5 TupleType (com.sri.ai.expresso.type.TupleType)5 Symbol (com.sri.ai.expresso.api.Symbol)4 IntegerExpressoType (com.sri.ai.expresso.type.IntegerExpressoType)4 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)4 Registry (com.sri.ai.grinder.api.Registry)4 Context (com.sri.ai.grinder.api.Context)3 DefaultRegistry (com.sri.ai.grinder.core.DefaultRegistry)3 TrueContext (com.sri.ai.grinder.core.TrueContext)3 Beta (com.google.common.annotations.Beta)2 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)2 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)2 AssignmentMapsIterator (com.sri.ai.grinder.helper.AssignmentMapsIterator)2