Search in sources :

Example 26 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 tree.

private static List<TableFactor> tree(int depth, int childrenPerNode, Function<ArrayList<TableVariable>, ArrayList<Double>> entryGen, int cardinality) {
    TableVariable[][] treeVars = treeVariables(depth, childrenPerNode, cardinality);
    List<TableFactor> result = new ArrayList<>();
    for (int i = 0; i < depth; i++) {
        for (int j = 0; j < pow(childrenPerNode, i); j++) {
            ArrayList<TableVariable> vars = listWithVariableNodeAndItschildren(depth, childrenPerNode, treeVars, i, j);
            TableFactor newNode = new TableFactor(vars, entryGen.apply(vars));
            result.add(newNode);
        }
    }
    return result;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 27 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 PerformanceTest method constructEquivalentRandomFactorsRepresentedInDifferentWays.

// / FACTOR CONSTRUCTION METHODS ////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////
private List<Factor> constructEquivalentRandomFactorsRepresentedInDifferentWays(SpecsForRandomTableFactorGeneration factorSpecs) {
    TableFactor tableFactor = makeRandomTableFactor(factorSpecs, FROM_VARIABLE_INDEX_TO_NAME, RANDOM);
    ArrayList<Factor> factors = new ArrayList<>(NUMBER_OF_TESTED_FACTORS);
    if (includeTableFactor) {
        addTableFactorToListOfFactors(tableFactor, factors);
    }
    if (includeTreeBasedExpressionFactors) {
        addTreeBasedExpressionFactorsToListOfFactors(tableFactor, factors);
    }
    if (includeLinearTableExpressionFactors) {
        addLinearTableExpressionFactorsToListOfFactors(tableFactor, factors);
    }
    return factors;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) RandomTableFactorMaker.makeRandomTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) RandomTableFactorMaker.makeRandomTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor) ArrayList(java.util.ArrayList)

Example 28 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 PerformanceTest method addTreeBasedExpressionFactorsToListOfFactors.

private void addTreeBasedExpressionFactorsToListOfFactors(TableFactor tableFactor, ArrayList<Factor> factors) {
    Factor newFactor;
    for (Theory theory : THEORIES_TO_TEST) {
        newFactor = TABLE_TO_EXPRESSION_FACTOR_CONVERTER.convert(tableFactor, theory, true);
        factors.add(newFactor);
    }
}
Also used : Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) RandomTableFactorMaker.makeRandomTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor)

Example 29 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 PerformanceTest method addLinearTableExpressionFactorsToListOfFactors.

private void addLinearTableExpressionFactorsToListOfFactors(TableFactor tableFactor, ArrayList<Factor> factors) {
    Factor newFactor;
    for (Theory theory : THEORIES_TO_TEST) {
        newFactor = TABLE_TO_EXPRESSION_FACTOR_CONVERTER.convert(tableFactor, theory, false);
        factors.add(newFactor);
    }
}
Also used : Theory(com.sri.ai.grinder.api.Theory) DifferenceArithmeticTheory(com.sri.ai.grinder.theory.differencearithmetic.DifferenceArithmeticTheory) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) RandomTableFactorMaker.makeRandomTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor)

Example 30 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 testf2f1SumOutV1.

@Test
public void testf2f1SumOutV1() {
    println();
    println("SUM OUT V1 from F2*F1");
    println("------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V1);
    TableFactor f2f1SumOutV1 = (TableFactor) (f2.multiply(f1)).sumOut(variablesToSumOut);
    f2f1SumOutV1.setName("f2f1SumOutV1");
    println(f2f1SumOutV1);
    assertEquals("f2f1SumOutV1[{V2:card=3}, {V4:card=2}, {V3:card=4}]: [22.0, 22.0, 22.0, 22.0, " + "24.0, 24.0, 24.0, 24.0, " + "42.0, 42.0, 42.0, 42.0, " + "44.0, 44.0, 44.0, 44.0, " + "62.0, 62.0, 62.0, 62.0, " + "64.0, 64.0, 64.0, 64.0]", f2f1SumOutV1.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)

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