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 boxNormalizedFactors.
private static Box boxNormalizedFactors(List<TableFactor> normalizedFactors, ArrayList<TableVariable> variables) {
TableFactor phiMin = new TableFactor(variables);
TableFactor phiMax = new TableFactor(variables);
for (ArrayList<Integer> values : in(getCartesianProduct(variables))) {
Map<TableVariable, Integer> map = Util.mapFromListOfKeysAndListOfValues(variables, values);
List<Double> phiValues = mapIntoList(normalizedFactors, (f) -> f.getEntryFor(map));
phiMin.setEntryFor(map, Collections.min(phiValues));
phiMax.setEntryFor(map, Collections.max(phiValues));
}
return new Box(phiMin, phiMax);
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class Polytopes method IntensionalConvexHullToListOfFactors.
public static List<TableFactor> IntensionalConvexHullToListOfFactors(IntensionalConvexHullOfFactors polytope) {
TableFactor factor = (TableFactor) polytope.getFactor();
List<TableVariable> indexes = mapIntoArrayList(polytope.getIndices(), v -> (TableVariable) v);
List<List<Integer>> listOfListOfValues = mapIntoList(indexes, v -> mapIntoList(v.getValues(), o -> (Integer) o));
List<NullaryFunction<Iterator<Integer>>> iteratorForListOfVariableValues = mapIntoList(listOfListOfValues, element -> () -> element.iterator());
Iterator<ArrayList<Integer>> cartesianProduct = new CartesianProductIterator<Integer>(iteratorForListOfVariableValues);
List<TableFactor> result = new LinkedList<>();
for (List<Integer> instantiations : in(cartesianProduct)) {
result.add(TableFactor.copyToSubTableFactor(factor, indexes, instantiations));
}
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 RandomTableFactorMaker method makeRandomTableFactor.
public static TableFactor makeRandomTableFactor(SpecsForRandomTableFactorGeneration specs, Function<Integer, String> fromVariableIndexToName, Random random) {
ArrayList<TableVariable> variables = makeVariables(specs.cardinalities, fromVariableIndexToName);
ArrayList<Double> entries = makeUniformlyDistributedRandomEntries(specs, random);
TableFactor tableFactor = new TableFactor(variables, entries);
return tableFactor;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class TestCases method tableFactorIsingModel.
private static ArrayList<TableFactor> tableFactorIsingModel(int gridSize, BiFunction<Pair<Integer, Integer>, Pair<Integer, Integer>, ArrayList<Double>> pairwiseFactorentries, Function<Pair<Integer, Integer>, ArrayList<Double>> singleVariableFactorEntries) {
ArrayList<ArrayList<TableVariable>> variables = new ArrayList<>();
for (int i = 0; i < gridSize; i++) {
ArrayList<TableVariable> col = new ArrayList<>();
variables.add(col);
for (int j = 0; j < gridSize; j++) {
col.add(j, new TableVariable("A_" + i + "_" + j, 2));
}
}
ArrayList<TableFactor> result = new ArrayList<>();
for (int i = 0; i < gridSize - 1; i++) {
for (int j = 0; j < gridSize; j++) {
result.add(new TableFactor(arrayList(variables.get(i).get(j), variables.get(i + 1).get(j)), pairwiseFactorentries.apply(new Pair<>(i, j), new Pair<>(i + 1, j))));
}
}
for (int i = 0; i < gridSize; i++) {
for (int j = 0; j < gridSize - 1; j++) {
result.add(new TableFactor(arrayList(variables.get(i).get(j), variables.get(i).get(j + 1)), pairwiseFactorentries.apply(new Pair<>(i, j), new Pair<>(i, j + 1))));
}
}
if (!(singleVariableFactorEntries.apply(new Pair<>(0, 0)) == null)) {
for (int i = 0; i < gridSize; i++) {
for (int j = 0; j < gridSize; j++) {
result.add(new TableFactor(arrayList(variables.get(i).get(j)), singleVariableFactorEntries.apply(new Pair<>(i, j))));
}
}
}
return result;
}
Aggregations