Search in sources :

Example 21 with TableFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.

the class TableFactorTest method testMultiplicationf1f2.

@Test
public void testMultiplicationf1f2() {
    println();
    println("MULTIPLYING f1 * f2");
    println("-------------------");
    TableFactor f1f2 = (TableFactor) f1.multiply(f2);
    f1f2.setName("f1f2");
    println(f1f2);
    assertEquals("phi[{V1:card=2}, {V2:card=3}, {V3:card=4}, {V4:card=2}]: [11.0, 12.0, 11.0, 12.0, 11.0, 12.0, 11.0, 12.0, " + "21.0, 22.0, 21.0, 22.0, 21.0, 22.0, 21.0, 22.0, " + "31.0, 32.0, 31.0, 32.0, 31.0, 32.0, 31.0, 32.0, " + "11.0, 12.0, 11.0, 12.0, 11.0, 12.0, 11.0, 12.0, " + "21.0, 22.0, 21.0, 22.0, 21.0, 22.0, 21.0, 22.0, " + "31.0, 32.0, 31.0, 32.0, 31.0, 32.0, 31.0, 32.0]", f1.multiply(f2).toString());
    println();
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Test(org.junit.Test)

Example 22 with TableFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.

the class TableFactorTest method testf1SumOutV1.

@Test
public void testf1SumOutV1() {
    println();
    println("SUM OUT V1 from F1");
    println("------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V1);
    TableFactor f1SumOutV1 = (TableFactor) f1.sumOut(variablesToSumOut);
    f1SumOutV1.setName("f1SumOutV1");
    println(f1SumOutV1);
    assertEquals("f1SumOutV1[{V2:card=3}, {V3:card=4}]: [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0]", f1SumOutV1.toString());
    println();
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Test(org.junit.Test)

Example 23 with TableFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.

the class TableFactorTest method testf2SumOutV4.

public void testf2SumOutV4() {
    println();
    println("SUM OUT V4 from F2");
    println("------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V4);
    TableFactor f2SumOutV4 = (TableFactor) f2.sumOut(variablesToSumOut);
    f2SumOutV4.setName("f2SumOutV4");
    println(f2SumOutV4);
    assertEquals("f2SumOutV4[{V4:card=2}]: [13.0, 23.0, 33.0]", f2SumOutV4.toString());
    println();
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 24 with TableFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.

the class TableFactorTest method testf2f1SumOutV1V2.

@Test
public void testf2f1SumOutV1V2() {
    println();
    println("SUM OUT V1 and V2 from F2*F1");
    println("------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V1, V2);
    TableFactor f2f1SumOutV1V2 = (TableFactor) (f2.multiply(f1)).sumOut(variablesToSumOut);
    f2f1SumOutV1V2.setName("f2f1SumOutV1V2");
    println(f2f1SumOutV1V2);
    assertEquals("f2f1SumOutV1V2[{V4:card=2}, {V3:card=4}]: [126.0, 126.0, 126.0, 126.0, 132.0, 132.0, 132.0, 132.0]", f2f1SumOutV1V2.toString());
    println();
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Test(org.junit.Test)

Example 25 with TableFactor

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.

the class TestCases method treeWithRandomEntries.

public static List<TableFactor> treeWithRandomEntries(int depth, int childrenPerNode, int cardinality, Function<Random, Double> randomGen) {
    Random r = new Random();
    Function<ArrayList<TableVariable>, ArrayList<Double>> entryGen = (l) -> Util.fill(pow(cardinality, l.size()), () -> randomGen.apply(r));
    List<TableFactor> result = tree(depth, childrenPerNode, entryGen, cardinality);
    return result;
}
Also used : BiFunction(java.util.function.BiFunction) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) Random(java.util.Random) Expression(com.sri.ai.expresso.api.Expression) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) ArrayList(java.util.ArrayList) EQUAL(com.sri.ai.grinder.library.FunctorConstants.EQUAL) UAIModel(com.sri.ai.praise.core.representation.classbased.table.core.uai.UAIModel) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) Expressions.apply(com.sri.ai.expresso.helper.Expressions.apply) TrueContext(com.sri.ai.grinder.core.TrueContext) DefaultExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable) Math.round(java.lang.Math.round) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) Math.log(java.lang.Math.log) Context(com.sri.ai.grinder.api.Context) BigInteger(java.math.BigInteger) Double.max(java.lang.Double.max) Util.arrayList(com.sri.ai.util.Util.arrayList) ExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable) Pair(com.sri.ai.util.base.Pair) Math.exp(java.lang.Math.exp) CommonTheory(com.sri.ai.grinder.application.CommonTheory) Function(com.google.common.base.Function) UAIEvidenceReading(com.sri.ai.praise.core.representation.classbased.table.core.uai.parsing.UAIEvidenceReading) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) IOException(java.io.IOException) IF_THEN_ELSE(com.sri.ai.grinder.library.FunctorConstants.IF_THEN_ELSE) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) List(java.util.List) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol) UAIModelReader(com.sri.ai.praise.core.representation.classbased.table.core.uai.parsing.UAIModelReader) Util(com.sri.ai.util.Util) ExpressionFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionFactorNetwork) Util.println(com.sri.ai.util.Util.println) FileReader(java.io.FileReader) UAIModelToExpressionFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.UAIModelToExpressionFactorNetwork) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Random(java.util.Random) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList)

Aggregations

TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)52 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)36 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)11 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)10 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)10 List (java.util.List)9 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)8 TableFactor.copyToSubTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor)8 Pair (com.sri.ai.util.base.Pair)7 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)6 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)6 LinkedHashMap (java.util.LinkedHashMap)6 Expression (com.sri.ai.expresso.api.Expression)5 DefaultExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)5 Util (com.sri.ai.util.Util)5 Util.arrayList (com.sri.ai.util.Util.arrayList)5 Util.println (com.sri.ai.util.Util.println)5 BiFunction (java.util.function.BiFunction)5 LinkedList (java.util.LinkedList)4