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();
}
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");
}
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");
}
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());
}
}
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());
}
Aggregations