Search in sources :

Example 6 with TableFactor

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;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) LinkedList(java.util.LinkedList)

Example 7 with TableFactor

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;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 8 with TableFactor

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;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 9 with TableFactor

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;
}
Also used : ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Expression(com.sri.ai.expresso.api.Expression) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) DefaultExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)

Example 10 with TableFactor

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;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) ArrayList(java.util.ArrayList)

Aggregations

TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)52 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)36 ArrayList (java.util.ArrayList)19 Test (org.junit.Test)11 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)10 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)10 List (java.util.List)9 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)8 TableFactor.copyToSubTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor)8 Pair (com.sri.ai.util.base.Pair)7 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)6 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)6 LinkedHashMap (java.util.LinkedHashMap)6 Expression (com.sri.ai.expresso.api.Expression)5 DefaultExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionFactor)5 Util (com.sri.ai.util.Util)5 Util.arrayList (com.sri.ai.util.Util.arrayList)5 Util.println (com.sri.ai.util.Util.println)5 BiFunction (java.util.function.BiFunction)5 LinkedList (java.util.LinkedList)4