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 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;
}
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 instantiateAllEdgesOfABox.
private static List<TableFactor> instantiateAllEdgesOfABox(Box box) {
TableFactor phiMin = box.getPhiMin();
TableFactor phiMax = box.getPhiMax();
List<TableFactor> result = new LinkedList<>();
Iterator<ArrayList<Integer>> cartesianProduct = getCartesianProductWitZerosAndOnes(phiMax.getEntries().size());
for (ArrayList<Integer> binaryNumber : in(cartesianProduct)) {
TableFactor newFactor = makeFactorWithAPermutationOfTheEntriesOnPhiMaxAndPhiMin(phiMin, phiMax, binaryNumber);
result.add(newFactor);
}
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 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.TableFactor in project aic-praise by aic-sri-international.
the class ConstantFactor method multiply.
@Override
public Factor multiply(Factor another) {
Factor result = null;
if (another instanceof ConstantFactor) {
ConstantFactor anotherConstant = (ConstantFactor) another;
result = multiplyTwoConstantFactors(anotherConstant);
} else if (another instanceof ExpressionFactor) {
ExpressionFactor anotherExpression = (ExpressionFactor) another;
result = evaluateAsFactor(Times.make(makeSymbol(getConstant()), (Expression) another), anotherExpression.getContext());
} else if (another instanceof TableFactor) {
TableFactor anotherTable = (TableFactor) another;
result = multiplyWithTableFactor(anotherTable);
} else {
throw new Error("Unknown class for another : class was " + another.getClass());
}
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 ConstantFactor method addATableFactor.
private TableFactor addATableFactor(TableFactor table) {
TableFactor result;
ArrayList<Double> newEntries = new ArrayList<>(table.getEntries().size());
for (Double entry : table.getEntries()) {
newEntries.add(getConstant() + entry);
}
result = new TableFactor(table.getVariables(), newEntries);
return result;
}
Aggregations