use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class TableFactorBoxBuilder method makeABoxFactorHavingTheBoxesExtremes.
private static TableFactor makeABoxFactorHavingTheBoxesExtremes(TableFactor first, TableFactor second) {
ArrayList<TableVariable> variables = Util.arrayList(TABLE_BOX_VARIABLE);
variables.addAll(first.getVariables());
ArrayList<Double> entries = new ArrayList<>(first.getVariables().size() * 2);
entries.addAll(first.getEntries());
entries.addAll(second.getEntries());
TableFactor result = new TableFactor(variables, entries);
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 TableFactorBoxBuilder method copyFactorInDifferentOrder.
private static TableFactor copyFactorInDifferentOrder(ArrayList<TableVariable> arrayList, TableFactor factor) {
TableFactor result = new TableFactor(arrayList, arrayListFilledWith(-1.0, numEntries(arrayList)));
ArrayList<TableVariable> var = new ArrayList<>(factor.getVariables());
for (ArrayList<Integer> notFreeVariablesInstantiation : in(getCartesianProduct(var))) {
LinkedHashMap<TableVariable, Integer> mapOfInstantiations = new LinkedHashMap<>();
addValuesToMapFromVariableToInstantiation(var, notFreeVariablesInstantiation, mapOfInstantiations);
result.setEntryFor(mapOfInstantiations, factor.getEntryFor(mapOfInstantiations));
}
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 TableFactorBoxBuilder method variablesWithoutElement.
public static void variablesWithoutElement(ArrayList<TableVariable> varaibles) {
ArrayList<TableVariable> variablesWithoutBoxVariable;
variablesWithoutBoxVariable = new ArrayList<>(varaibles.size() - 1);
for (TableVariable v : varaibles) {
if (!v.equals(TABLE_BOX_VARIABLE)) {
variablesWithoutBoxVariable.add(v);
}
}
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.
the class TableFactorBoxBuilder method main.
public static void main(String[] args) {
TableVariable A = new TableVariable("A", 2);
TableVariable B = new TableVariable("B", 2);
TableVariable C = new TableVariable("C", 2);
TableVariable D = new TableVariable("D", 2);
TableFactor fABCD = new TableFactor(arrayList(A, B, C, D), arrayList(0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5));
TableFactor fBoxABCD = new TableFactor(arrayList(TABLE_BOX_VARIABLE, A, B, C, D), arrayList(0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 10., 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 11.0, 11.1, 11.2, 11.3, 11.4, 11.5));
ArrayList<TableVariable> list = arrayList(A, B, C, D, TABLE_BOX_VARIABLE);
TableFactor fABCDBox = new TableFactor(list);
LinkedHashMap<TableVariable, Integer> map = new LinkedHashMap<>();
for (ArrayList<Integer> instantiation : in(getCartesianProduct(list))) {
addValuesToMapFromVariableToInstantiation(list, instantiation, map);
fABCDBox.setEntryFor(map, fBoxABCD.getEntryFor(map));
}
println(fABCD);
println(fBoxABCD);
println(fABCDBox);
Pair<TableFactor, TableFactor> pair = divideABoxFactorIntoTwoHalves(fBoxABCD);
println("Lower box: " + pair.first);
println("Higher box: " + pair.second);
pair = divideABoxFactorIntoTwoHalves(fABCDBox);
println("Lower box: " + pair.first);
println("Higher box: " + pair.second);
println(maxOrMinOut(fABCD, arrayList(A, B), arrayList(C, D), (newValue, oldValue) -> (newValue < oldValue)));
println(maxOrMinOut(fABCD, arrayList(A, B), arrayList(C, D), (newValue, oldValue) -> (newValue > oldValue)));
println("BoxFactor" + makeABoxFactorHavingTheBoxesExtremes(fABCD, fABCD));
// -----------------------------------------------
IntensionalConvexHullOfFactors ICHOF = new IntensionalConvexHullOfFactors(Util.list(TABLE_BOX_VARIABLE, A, B), fABCDBox);
println(ICHOF);
println(makeTableBox(ICHOF));
TableFactor fCBDA = copyFactorInDifferentOrder(arrayList(D, B, TABLE_BOX_VARIABLE, C, A), fABCDBox);
ICHOF = new IntensionalConvexHullOfFactors(Util.list(A, TABLE_BOX_VARIABLE, B), fCBDA);
println(makeTableBox(ICHOF));
}
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 instantiateAllEdgesOfAICHOF.
// private static List<TableFactor> listOfFactorsRepresentedByThePolytope(IntensionalConvexHullOfFactors polytope) {
// List<Box> boxesGeneratedByInstantiatingNonBoxVariablesInTheConvexHull = instantiateAllEdgesOfAICHOF(polytope);
// List<TableFactor> nonNormalizedFactors = new LinkedList<>();
// for(Box b : boxesGeneratedByInstantiatingNonBoxVariablesInTheConvexHull) {
// nonNormalizedFactors.addAll(instantiateAllEdgesOfABox(b));
// }
// List<TableFactor> nonNormalizedFactors = instantiateAllEdgesOfAICHOF(polytope);
// return nonNormalizedFactors;
// }
private static List<TableFactor> instantiateAllEdgesOfAICHOF(IntensionalConvexHullOfFactors polytope) {
TableFactor factor = (TableFactor) polytope.getFactor();
ArrayList<TableVariable> indexes = indexesThatAreNotTableBoxVariable(polytope);
boolean isABox = indexes.size() < polytope.getIndices().size();
List<TableFactor> result = new LinkedList<>();
for (List<Integer> instantiations : in(TableFactor.getCartesianProduct(indexes))) {
TableFactor subFactor = TableFactor.copyToSubTableFactor(factor, indexes, instantiations);
if (isABox) {
List<TableFactor> factorsFromBox = instantiateAllEdgesOfABox(new Box(TABLE_BOX_VARIABLE, subFactor));
result.addAll(factorsFromBox);
} else {
if (!isNullProbability(subFactor)) {
result.add(subFactor);
}
}
}
return result;
}
Aggregations