Search in sources :

Example 41 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 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;
}
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 42 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 getPhiMin.

public TableFactor getPhiMin() {
    TableFactor tableFactor = (TableFactor) this.getFactor();
    TableFactor result = TableFactor.copyToSubTableFactor(tableFactor, list(TABLE_BOX_VARIABLE), list(0));
    return result;
}
Also used : TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)

Example 43 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 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);
}
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)

Example 44 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 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;
}
Also used : Util.union(com.sri.ai.util.Util.union) Util.intersect(com.sri.ai.util.Util.intersect) Box(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.Box) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) Util.getFirstSatisfyingPredicateOrNull(com.sri.ai.util.Util.getFirstSatisfyingPredicateOrNull) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) CartesianProductIterator(com.sri.ai.util.collect.CartesianProductIterator) ArrayList(java.util.ArrayList) Util.in(com.sri.ai.util.Util.in) Util.getFirst(com.sri.ai.util.Util.getFirst) IDENTITY_FACTOR(com.sri.ai.praise.core.representation.interfacebased.factor.core.IdentityFactor.IDENTITY_FACTOR) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) NullaryFunction(com.sri.ai.util.base.NullaryFunction) Collection(java.util.Collection) Util.list(com.sri.ai.util.Util.list) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Util.mapIntoList(com.sri.ai.util.Util.mapIntoList) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Util.collect(com.sri.ai.util.Util.collect) Util.subtract(com.sri.ai.util.Util.subtract) List(java.util.List) Predicate(com.google.common.base.Predicate) Util.myAssert(com.sri.ai.util.Util.myAssert) TableBoxVariable(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable) 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) NullaryFunction(com.sri.ai.util.base.NullaryFunction) CartesianProductIterator(com.sri.ai.util.collect.CartesianProductIterator) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Util.mapIntoList(com.sri.ai.util.Util.mapIntoList) List(java.util.List) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Example 45 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 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;
}
Also used : AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Box(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.Box)

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