Search in sources :

Example 16 with Categorical

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

the class AssignmentsIteratorTest method test2.

@Test
public void test2() {
    Registry registry = new DefaultRegistry();
    Type myType = new Categorical("People", 2, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
    Symbol x = makeSymbol("X");
    Symbol y = makeSymbol("Y");
    String expected = "{X=oscar, Y=oscar}\n" + "{X=mary, Y=oscar}\n" + "{X=oscar, Y=mary}\n" + "{X=mary, Y=mary}";
    Symbol myTypeExpression = makeSymbol(myType.getName());
    registry = registry.makeNewContextWithAddedType(myType);
    registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myTypeExpression, y, myTypeExpression));
    AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
    String actual = join("\n", assignmentsIterator);
    // System.out.println(actual);
    assertEquals(expected, actual);
}
Also used : AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Type(com.sri.ai.expresso.api.Type) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Symbol(com.sri.ai.expresso.api.Symbol) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Registry(com.sri.ai.grinder.api.Registry) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 17 with Categorical

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

the class AssignmentsIteratorTest method test3.

@Test
public void test3() {
    Registry registry = new DefaultRegistry();
    Type peopleType = new Categorical("People", 4, arrayList(makeSymbol("oscar"), makeSymbol("mary")));
    Type petsType = new Categorical("Pets", 3, arrayList(makeSymbol("fido"), makeSymbol("purrs")));
    Symbol x = makeSymbol("X");
    Symbol y = makeSymbol("Y");
    String expected = "{X=oscar, Y=fido}\n" + "{X=mary, Y=fido}\n" + "{X=people3, Y=fido}\n" + "{X=people4, Y=fido}\n" + "{X=oscar, Y=purrs}\n" + "{X=mary, Y=purrs}\n" + "{X=people3, Y=purrs}\n" + "{X=people4, Y=purrs}\n" + "{X=oscar, Y=pets3}\n" + "{X=mary, Y=pets3}\n" + "{X=people3, Y=pets3}\n" + "{X=people4, Y=pets3}";
    Symbol myPeopleTypeExpression = makeSymbol(peopleType.getName());
    Symbol myPetsTypeExpression = makeSymbol(petsType.getName());
    registry = registry.makeNewContextWithAddedType(peopleType);
    registry = registry.makeNewContextWithAddedType(petsType);
    registry = registry.makeCloneWithAdditionalRegisteredSymbolsAndTypes(map(x, myPeopleTypeExpression, y, myPetsTypeExpression));
    AssignmentMapsIterator assignmentsIterator = new AssignmentMapsIterator(list(x, y), registry);
    String actual = join("\n", assignmentsIterator);
    // System.out.println(actual);
    assertEquals(expected, actual);
}
Also used : AssignmentMapsIterator(com.sri.ai.grinder.helper.AssignmentMapsIterator) Type(com.sri.ai.expresso.api.Type) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) Symbol(com.sri.ai.expresso.api.Symbol) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Registry(com.sri.ai.grinder.api.Registry) DefaultRegistry(com.sri.ai.grinder.core.DefaultRegistry) Categorical(com.sri.ai.expresso.type.Categorical) Test(org.junit.Test)

Example 18 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 19 with Categorical

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

the class SampleCommonInterpreterTest method testCategoricalExample1.

@Test
public void testCategoricalExample1() {
    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 20 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.makeNewContextWithAddedType(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.core.TrueContext) Context(com.sri.ai.grinder.api.Context) Type(com.sri.ai.expresso.api.Type) Categorical(com.sri.ai.expresso.type.Categorical) TrueContext(com.sri.ai.grinder.core.TrueContext) Test(org.junit.Test)

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