use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.
the class Box method makeTableFactorBox.
private static TableFactor makeTableFactorBox(TableFactor phiMin, TableFactor phiMax) {
ArrayList<TableVariable> variables = Util.arrayList(TABLE_BOX_VARIABLE);
variables.addAll(phiMax.getVariables());
ArrayList<Double> entries = new ArrayList<>(phiMin.getEntries());
entries.addAll(phiMax.getEntries());
TableFactor result = new TableFactor(variables, entries);
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor in project aic-praise by aic-sri-international.
the class Box method getPhiMin.
public TableFactor getPhiMin() {
TableFactor tableFactor = (TableFactor) this.getFactor();
TableFactor result = TableFactor.copyToSubTableFactor(tableFactor, list(TABLE_BOX_VARIABLE), list(0));
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor 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.TableFactor 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.TableFactor in project aic-praise by aic-sri-international.
the class Polytopes method boxPolytopes.
private static Polytope boxPolytopes(List<Polytope> toBeBoxed) {
LinkedList<Polytope> boxedPolytopes = list();
for (Polytope p : toBeBoxed) {
if (p instanceof IntensionalConvexHullOfFactors && !((IntensionalConvexHullOfFactors) p).getIndices().isEmpty() && ((IntensionalConvexHullOfFactors) p).getFactor() instanceof TableFactor) {
// Box boxedP = TableFactorBoxBuilder.makeTableBox((IntensionalConvexHullOfFactors) p);
Box boxedP = Box.boxIt((IntensionalConvexHullOfFactors) p);
boxedPolytopes.add(boxedP);
} else {
boxedPolytopes.add(p);
}
}
Polytope result = Polytope.multiply(boxedPolytopes);
return result;
}
Aggregations