Search in sources :

Example 36 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 testf1SumOutV1V2V3.

@Test
public void testf1SumOutV1V2V3() {
    println();
    println("SUM OUT V1, V2, and V3 from F1");
    println("-------------------------------");
    ArrayList<TableVariable> variablesToSumOut = Util.arrayList(V1, V2, V3);
    ConstantFactor f1SumOutV1V2V3 = (ConstantFactor) f1.sumOut(variablesToSumOut);
    // f1SumOutV1V2V3.setName("f1SumOutV1V2V3");  cannot set name of a [now] ConstantFactor
    print("f1SumOutV1V2V3: ");
    println(f1SumOutV1V2V3);
    assertEquals("24.0", f1SumOutV1V2V3.toString());
    println();
}
Also used : ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Test(org.junit.Test)

Example 37 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 main.

public static void main(String[] args) {
    String[] fileNames = { // "1a1x.uai",
    "grid40x40.f5.wrap.uai", "or_chain_10.fg.uai", "1a2j.uai", "grid80x80.f10.uai", "1a3c.uai", "grid80x80.f10.wrap.uai", "grid80x80.f15.uai", "or_chain_1.fg.uai", "BN_0.uai", "BN_5.uai", "grid80x80.f15.uai", "BN_101.uai", "BN_6.uai", "grid80x80.f15.wrap.uai", "BN_10.uai", "grid10x10.f10.uai", "grid80x80.f2.uai", "BN_11.uai", "grid10x10.f10.wrap.uai", "grid80x80.f2.wrap.uai", "BN_12.uai", "grid10x10.f15.wrap.uai", "grid80x80.f5.uai", "BN_13.uai", "grid10x10.f5.wrap.uai", "grid80x80.f5.wrap.uai", "BN_14.uai", "grid20x20.f10.uai", "BN_15.uai", "grid20x20.f15.uai", "or_chain_1.fg.uai", "BN_16.uai", "grid20x20.f15.wrap.uai", "pedigree13.uai", "BN_18.uai", "grid20x20.f5.uai", "pedigree18.uai", "BN_1.uai", "grid20x20.f5.wrap.uai", "pedigree19.uai", "BN_2.uai", "grid40x40.f5.uai", "pedigree20.uai" };
    for (String fileName : fileNames) {
        println("----------" + fileName + "----------");
        printPlotToFile(fileName, 20);
    }
    Pair<TableVariable, TableFactorNetwork> pairQueryNet = isingModel("5_5", 10, .2);
    AEBPTestingDataFrame df = solveWithBothMethods(pairQueryNet.first, pairQueryNet.second, 180, "Ising");
    AEBPRPlotting.plottingTheInterval(df, true, "IsingWeightPointTwo");
}
Also used : TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 38 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 printPlotToFile.

public static void printPlotToFile(String fileName, double maxTime) {
    Pair<TableVariable, TableFactorNetwork> pairQueryNet = importUAIFile(fileName);
    AEBPTestingDataFrame df = solveWithBothMethods(pairQueryNet.first, pairQueryNet.second, maxTime, fileName.split(".uai")[0]);
    AEBPRPlotting.plottingTheInterval(df, true, fileName.split(".uai")[0] + ".pdf");
    AEBPRPlotting.plottingTheInterval(df, true, fileName.split(".uai")[0] + ".pdf");
    df.printToCsv(fileName.split(".uai")[0] + ".csv");
}
Also used : TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 39 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 testEBPP.

private static void testEBPP(AEBPTestingDataFrame df, int nRepetitions, List<TableFactor> network, TableVariable query, String netName) {
    TableFactorNetwork factorNetwork = new TableFactorNetwork(network);
    ExactBPNode<Variable, Factor> exactBP = new ExactBP(query, factorNetwork);
    for (int i = 0; i < nRepetitions; i++) {
        println("solveWithExactBP : " + netName);
        Pair<Double, Factor> p = solveAndPrint(exactBP);
        df.addRow(// run number
        i, // iteration
        -1, // minPTrue
        ((TableFactor) p.second).getEntries().get(0), // MaxPTrue
        ((TableFactor) p.second).getEntries().get(0), // iteration time
        p.first, // total time
        p.first, // InferenceMethodUsed
        "ExactBP", // GraphicalModelName
        netName + "; query: " + query.toString());
    }
}
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) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) ExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)

Example 40 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 TableBayesianNode method main.

public static void main(String[] args) {
    TableVariable sick = new TableVariable("sick", 2);
    TableVariable sun = new TableVariable("sun", 2);
    TableVariable cold = new TableVariable("cold", 2);
    TableBayesianNode sunNode = new TableBayesianNode(sun, arrayList());
    TableBayesianNode coldNode = new TableBayesianNode(cold, arrayList());
    TableBayesianNode sickNode = new TableBayesianNode(sick, arrayList(sun, cold));
    sickNode.setInitialCountsForAllPossibleChildAndParentsAssignments();
    ArrayList<Integer> childAndParentsValues = new ArrayList<Integer>();
    childAndParentsValues.add(1);
    childAndParentsValues.add(0);
    childAndParentsValues.add(1);
    sickNode.incrementCountForChildAndParentsAssignment(childAndParentsValues);
    sickNode.normalizeParameters();
    LinkedHashMap<TableVariable, Integer> variablesAndTheirValues = new LinkedHashMap<TableVariable, Integer>();
    variablesAndTheirValues.put(sick, 1);
    variablesAndTheirValues.put(sun, 0);
    variablesAndTheirValues.put(cold, 1);
    System.out.println("Testing entries:");
    System.out.println("entryFor(" + variablesAndTheirValues.get(sick) + ", [" + variablesAndTheirValues.get(sun) + ", " + variablesAndTheirValues.get(cold) + "]) = " + sickNode.getEntryFor(variablesAndTheirValues));
// System.out.println("all entries: " + node.getEntries());
}
Also used : ArrayList(java.util.ArrayList) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) LinkedHashMap(java.util.LinkedHashMap)

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