use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class Box method makeFactorWithAPermutationOfTheEntriesOnPhiMaxAndPhiMin.
private static TableFactor makeFactorWithAPermutationOfTheEntriesOnPhiMaxAndPhiMin(TableFactor phiMin, TableFactor phiMax, ArrayList<Integer> binaryNumber) {
ArrayList<Double> phiMinEntries = phiMin.getEntries();
ArrayList<Double> phiMaxEntries = phiMax.getEntries();
ArrayList<Double> newEntries = new ArrayList<>(phiMin.getEntries().size());
for (int i = 0; i < binaryNumber.size(); i++) {
newEntries.add(binaryNumber.get(i) == 0 ? phiMinEntries.get(i) : phiMaxEntries.get(i));
}
ArrayList<TableVariable> variables = (ArrayList<TableVariable>) phiMax.getVariables();
TableFactor result = new TableFactor(variables, newEntries);
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class AnytimeExactBPTest3 method main.
public static void main(String[] args) {
for (Integer i : list(1, 2, 3, 4)) {
testing(TestCases.treeWithExponentialGaussianRandomEntries(10, i, 2, .3, .1), 20, new TableVariable("g_0_0", 2), "treeExpGauss" + i);
}
List<TableFactor> fs = TestCases.TableFactorALARM();
testing(fs, 500, new TableVariable("g22", 3), "alarmante");
/* for(Integer i : list(-2,-1,0,1)) {
testing((List<TableFactor>) TestCases.isingModelGridWithWeigthsAndPotetialNormalyDistributed(20, Math.pow(10, i), true),
5,
new TableVariable("10_10", 2),
"IsingNormalRandom" + i);
}
println(factors.get(27).getVariables());
for(TableFactor f : factors) {
println(f);
}
List<TableFactor> factors = TestCases.getListOfTableFactors("Seg","BN_8");
testing(factors,
5000,
factors.get(27).getVariables().get(0),
"promedas-");
*/
ArrayList<File> Files = TestCases.retrieveUAIFilesInFolder("Segmentation");
int i = 0;
for (File file : Files) {
println(i++ + "---------------" + file.getName() + "---------------");
}
for (File file : Files) {
file = Files.get(48);
println("---------------" + file.getName() + "---------------");
List<TableFactor> factors = TestCases.getListOfTableFactors("Segmentation", file.getName());
testing(factors, 20, factors.get(0).getVariables().get(0), "Segmentation-" + file.getName() + "0");
testing(factors, 200, factors.get(10).getVariables().get(0), "Segmentation-" + file.getName() + "1");
testing(factors, 20, factors.get(15).getVariables().get(0), "Segmentation-" + file.getName() + "2");
}
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class AnytimeExactBPTest3 method testingALARM.
public static void testingALARM() {
ArrayList<TableFactor> factors = TestCases.TableFactorALARM();
LinkedHashSet<TableVariable> variablesInALARM = new LinkedHashSet<>();
for (TableFactor f : factors) {
variablesInALARM.addAll(f.getVariables());
}
println(variablesInALARM);
for (TableVariable v : variablesInALARM) {
testing(factors, 20, v, "Alarm-Var=" + v);
}
}
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 getMaxMinProbabilityFromIntensionalConvHull.
private static ArrayList<Double> getMaxMinProbabilityFromIntensionalConvHull(IntensionalConvexHullOfFactors polytopeOnQuery, boolean maxOrMin) {
TableFactor factor = (TableFactor) polytopeOnQuery.getFactor();
TableVariable query = (TableVariable) polytopeOnQuery.getFreeVariables().iterator().next();
List<Variable> variablesInOrder = new ArrayList<>(polytopeOnQuery.getIndices());
List<List<Integer>> listOflistOfInstantiations = getListOfListOfInstantiations(variablesInOrder);
Iterator<ArrayList<Integer>> iter = getCartesianProductWithValuesOfVariablesToSum(listOflistOfInstantiations);
Double[] resultArray = maxOrMin ? initializeWithValue(query.getCardinality(), -1.0) : initializeWithValue(query.getCardinality(), 2.0);
for (ArrayList<Integer> instantiation : in(iter)) {
LinkedHashMap<Variable, Integer> mapOfInstantiations = new LinkedHashMap<>();
int k = 0;
for (Variable v : variablesInOrder) {
mapOfInstantiations.put(v, instantiation.get(k++));
}
ArrayList<Double> nonNormalizedProbabilitiesForThisInstantiation = new ArrayList<>(query.getCardinality());
for (int i = 0; i < query.getCardinality(); i++) {
mapOfInstantiations.put(query, i);
nonNormalizedProbabilitiesForThisInstantiation.add(factor.getEntryFor(mapOfInstantiations));
}
Double[] normalizedProba = nomalize(nonNormalizedProbabilitiesForThisInstantiation);
for (int i = 0; i < normalizedProba.length; i++) {
if (maxOrMin && normalizedProba[i] > resultArray[i]) {
resultArray[i] = normalizedProba[i];
}
if (!maxOrMin && normalizedProba[i] < resultArray[i]) {
resultArray[i] = normalizedProba[i];
}
}
}
ArrayList<Double> result = new ArrayList<>();
for (int i = 0; i < resultArray.length; i++) {
result.add(resultArray[i]);
}
return result;
}
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 importUAIFile.
public static Pair<TableVariable, TableFactorNetwork> importUAIFile(String fileName) {
Pair<TableVariable, TableFactorNetwork> pairQueryNet = new Pair<>();
try {
FileReader modelFile = new FileReader(new File("").getAbsolutePath() + "/UAITests/" + fileName);
UAIModel model = UAIModelReader.read(modelFile);
// Converting the network
pairQueryNet.second = new TableFactorNetwork(model);
// get one variable and test over the network
ArrayList<Variable> vars = new ArrayList<>(pairQueryNet.second.getBs());
// pick any variable
pairQueryNet.first = (TableVariable) vars.get(0);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pairQueryNet;
}
Aggregations