Search in sources :

Example 11 with TableVariable

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

the class AnytimeExactBPTest2 method getListOfListOfInstantiations.

public static List<List<Integer>> getListOfListOfInstantiations(List<Variable> ListOfVariables) {
    List<List<Integer>> listOflistOfInstantiations = new ArrayList<>();
    for (Variable v : ListOfVariables) {
        TableVariable tv = (TableVariable) v;
        ArrayList<Integer> toAdd = new ArrayList<>(tv.getCardinality());
        for (int i = 0; i < tv.getCardinality(); i++) {
            toAdd.add(i);
        }
        listOflistOfInstantiations.add(toAdd);
    }
    return listOflistOfInstantiations;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 12 with TableVariable

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

the class AnytimeExactBPTest2 method isingModel.

public static Pair<TableVariable, TableFactorNetwork> isingModel(String queryName, int gridSize, double potential) {
    Pair<TableVariable, TableFactorNetwork> pairQueryNet;
    // TestCases.isingModelGridWithRandomWeigthsAndPotetial(gridSize, potential);
    List<TableFactor> factors = null;
    TableVariable query = null;
    for (TableFactor f : factors) {
        for (TableVariable v : f.getVariables()) {
            if (v.getName().equals(queryName)) {
                query = v;
            // Util.println("Query not null");
            }
        }
    // Util.println(f.getVariables());
    }
    TableFactorNetwork tfn = new TableFactorNetwork(factors);
    pairQueryNet = new Pair<>(query, tfn);
    return pairQueryNet;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 13 with TableVariable

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

the class BenchmarkingIsingModel method testAEBP.

private static void testAEBP(AEBPTestingDataFrame df, int nRepetitions, int timeLimit, int complexity, LinkedList<Pair<Double, Double>> weights, BiFunction<Integer, Pair<Double, Double>, List<? extends Factor>> networkGenerator, BiFunction<Integer, List<TableFactor>, TableVariable> getQuery, String netName) {
    for (Pair<Double, Double> weight : weights) {
        for (int i = 0; i < nRepetitions; i++) {
            @SuppressWarnings("unchecked") List<TableFactor> network = (List<TableFactor>) networkGenerator.apply(complexity, weight);
            TableVariable query = getQuery.apply(complexity, network);
            testAEBPP(df, i, timeLimit, network, query, netName + " - " + complexity);
        }
    }
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) List(java.util.List) LinkedList(java.util.LinkedList) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 14 with TableVariable

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

the class BenchmarkingIsingModel method testEBP.

private static void testEBP(AEBPTestingDataFrame df, int nRepetitions, LinkedList<Integer> complexities, LinkedList<Pair<Double, Double>> weights, BiFunction<Integer, Pair<Double, Double>, List<? extends Factor>> networkGenerator, BiFunction<Integer, List<TableFactor>, TableVariable> getQuery, String netName) {
    // TestEBP
    for (Integer complexity : complexities) {
        for (Pair<Double, Double> weight : weights) {
            @SuppressWarnings("unchecked") List<TableFactor> network = (List<TableFactor>) networkGenerator.apply(complexity, weight);
            TableVariable query = getQuery.apply(complexity, network);
            testEBPP(df, nRepetitions, network, query, netName + " - " + complexity);
        }
    }
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) List(java.util.List) LinkedList(java.util.LinkedList) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 15 with TableVariable

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

the class TableFactorTest method testf2SumOutV2.

public void testf2SumOutV2() {
    println();
    println("SUM OUT V2 from F2");
    println("------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V2);
    TableFactor f2SumOutV2 = (TableFactor) f2.sumOut(variablesToSumOut);
    f2SumOutV2.setName("f2SumOutV2");
    println(f2SumOutV2);
    assertEquals("f2SumOutV2[{V4:card=2}]: [63.0, 66.0]", f2SumOutV2.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)

Aggregations

TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)49 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)34 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)13 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)10 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)8 LinkedHashMap (java.util.LinkedHashMap)8 List (java.util.List)8 TableFactor.copyToSubTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor)7 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)6 Pair (com.sri.ai.util.base.Pair)6 Expression (com.sri.ai.expresso.api.Expression)4 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)3 DefaultDatapoint (com.sri.ai.praise.learning.parameterlearning.representation.dataset.DefaultDatapoint)3 DefaultDataset (com.sri.ai.praise.learning.parameterlearning.representation.dataset.DefaultDataset)3 TableBayesianNode (com.sri.ai.praise.learning.parameterlearning.representation.table.TableBayesianNode)3 Util (com.sri.ai.util.Util)3 Util.arrayList (com.sri.ai.util.Util.arrayList)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3