Search in sources :

Example 46 with TableVariable

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 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 47 with TableVariable

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable 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 48 with TableVariable

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.

the class RandomTableFactorMaker method makeRandomTableFactor.

public static TableFactor makeRandomTableFactor(SpecsForRandomTableFactorGeneration specs, Function<Integer, String> fromVariableIndexToName, Random random) {
    ArrayList<TableVariable> variables = makeVariables(specs.cardinalities, fromVariableIndexToName);
    ArrayList<Double> entries = makeUniformlyDistributedRandomEntries(specs, random);
    TableFactor tableFactor = new TableFactor(variables, entries);
    return tableFactor;
}
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 49 with TableVariable

use of com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable in project aic-praise by aic-sri-international.

the class TestCases method tableFactorIsingModel.

private static ArrayList<TableFactor> tableFactorIsingModel(int gridSize, BiFunction<Pair<Integer, Integer>, Pair<Integer, Integer>, ArrayList<Double>> pairwiseFactorentries, Function<Pair<Integer, Integer>, ArrayList<Double>> singleVariableFactorEntries) {
    ArrayList<ArrayList<TableVariable>> variables = new ArrayList<>();
    for (int i = 0; i < gridSize; i++) {
        ArrayList<TableVariable> col = new ArrayList<>();
        variables.add(col);
        for (int j = 0; j < gridSize; j++) {
            col.add(j, new TableVariable("A_" + i + "_" + j, 2));
        }
    }
    ArrayList<TableFactor> result = new ArrayList<>();
    for (int i = 0; i < gridSize - 1; i++) {
        for (int j = 0; j < gridSize; j++) {
            result.add(new TableFactor(arrayList(variables.get(i).get(j), variables.get(i + 1).get(j)), pairwiseFactorentries.apply(new Pair<>(i, j), new Pair<>(i + 1, j))));
        }
    }
    for (int i = 0; i < gridSize; i++) {
        for (int j = 0; j < gridSize - 1; j++) {
            result.add(new TableFactor(arrayList(variables.get(i).get(j), variables.get(i).get(j + 1)), pairwiseFactorentries.apply(new Pair<>(i, j), new Pair<>(i, j + 1))));
        }
    }
    if (!(singleVariableFactorEntries.apply(new Pair<>(0, 0)) == null)) {
        for (int i = 0; i < gridSize; i++) {
            for (int j = 0; j < gridSize; j++) {
                result.add(new TableFactor(arrayList(variables.get(i).get(j)), singleVariableFactorEntries.apply(new Pair<>(i, j))));
            }
        }
    }
    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) Pair(com.sri.ai.util.base.Pair)

Aggregations

TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)49 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)34 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)13 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)10 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)8 LinkedHashMap (java.util.LinkedHashMap)8 List (java.util.List)8 TableFactor.copyToSubTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor)7 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)6 Pair (com.sri.ai.util.base.Pair)6 Expression (com.sri.ai.expresso.api.Expression)4 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)3 DefaultDatapoint (com.sri.ai.praise.learning.parameterlearning.representation.dataset.DefaultDatapoint)3 DefaultDataset (com.sri.ai.praise.learning.parameterlearning.representation.dataset.DefaultDataset)3 TableBayesianNode (com.sri.ai.praise.learning.parameterlearning.representation.table.TableBayesianNode)3 Util (com.sri.ai.util.Util)3 Util.arrayList (com.sri.ai.util.Util.arrayList)3 File (java.io.File)3 LinkedList (java.util.LinkedList)3