Search in sources :

Example 1 with TABLE_BOX_VARIABLE

use of com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable.TABLE_BOX_VARIABLE 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));
}
Also used : Iterator(java.util.Iterator) BiFunction(java.util.function.BiFunction) TableFactor.getCartesianProduct(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.getCartesianProduct) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Util.in(com.sri.ai.util.Util.in) List(java.util.List) TableFactor.numEntries(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.numEntries) Util.arrayListFilledWith(com.sri.ai.util.Util.arrayListFilledWith) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) TABLE_BOX_VARIABLE(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable.TABLE_BOX_VARIABLE) Util(com.sri.ai.util.Util) Util.println(com.sri.ai.util.Util.println) TableFactor.copyToSubTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor) Util.arrayList(com.sri.ai.util.Util.arrayList) LinkedHashSet(java.util.LinkedHashSet) Pair(com.sri.ai.util.base.Pair) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableFactor.copyToSubTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with TABLE_BOX_VARIABLE

use of com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable.TABLE_BOX_VARIABLE in project aic-praise by aic-sri-international.

the class TableFactorBoxBuilder method buildBoxFactorIfSetIsNotEmpty.

private static TableFactor buildBoxFactorIfSetIsNotEmpty(TableFactor factor, ArrayList<TableVariable> notFreeVariables) {
    LinkedHashSet<TableVariable> setOfFreeVariables = new LinkedHashSet<TableVariable>(factor.getVariables());
    setOfFreeVariables.removeAll(notFreeVariables);
    boolean initialFactorIsABox = setOfFreeVariables.contains(TABLE_BOX_VARIABLE);
    if (initialFactorIsABox) {
        setOfFreeVariables.remove(TABLE_BOX_VARIABLE);
    }
    // ArrayList<TableVariable> listOfFreeVariables = Util.arrayList(TABLE_BOX_VARIABLE);
    // listOfFreeVariables.addAll(newFactorSetOfVariables);
    ArrayList<TableVariable> listOfFreeVariables = new ArrayList<>(setOfFreeVariables);
    TableFactor newFactorLowHalf;
    TableFactor newFactorHighHalf;
    if (initialFactorIsABox) {
        Pair<TableFactor, TableFactor> factorHalves = divideABoxFactorIntoTwoHalves(factor);
        TableFactor factorLowHalf = factorHalves.first;
        TableFactor factorHighHalf = factorHalves.second;
        newFactorLowHalf = maxOrMinOut(factorLowHalf, listOfFreeVariables, notFreeVariables, (newValue, oldValue) -> newValue < oldValue);
        newFactorHighHalf = maxOrMinOut(factorHighHalf, listOfFreeVariables, notFreeVariables, (newValue, oldValue) -> (newValue > oldValue));
    } else {
        newFactorLowHalf = maxOrMinOut(factor, listOfFreeVariables, notFreeVariables, (newValue, oldValue) -> (newValue < oldValue));
        newFactorHighHalf = maxOrMinOut(factor, listOfFreeVariables, notFreeVariables, (newValue, oldValue) -> (newValue > oldValue));
    }
    TableFactor result = makeABoxFactorHavingTheBoxesExtremes(newFactorLowHalf, newFactorHighHalf);
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Iterator(java.util.Iterator) BiFunction(java.util.function.BiFunction) TableFactor.getCartesianProduct(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.getCartesianProduct) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Util.in(com.sri.ai.util.Util.in) List(java.util.List) TableFactor.numEntries(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.numEntries) Util.arrayListFilledWith(com.sri.ai.util.Util.arrayListFilledWith) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) TABLE_BOX_VARIABLE(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable.TABLE_BOX_VARIABLE) Util(com.sri.ai.util.Util) Util.println(com.sri.ai.util.Util.println) TableFactor.copyToSubTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor) Util.arrayList(com.sri.ai.util.Util.arrayList) LinkedHashSet(java.util.LinkedHashSet) Pair(com.sri.ai.util.base.Pair) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) TableFactor.copyToSubTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor) ArrayList(java.util.ArrayList) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)

Aggregations

Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)2 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)2 TableFactor.copyToSubTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.copyToSubTableFactor)2 TableFactor.getCartesianProduct (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.getCartesianProduct)2 TableFactor.numEntries (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor.numEntries)2 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)2 TABLE_BOX_VARIABLE (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable.TABLE_BOX_VARIABLE)2 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)2 Util (com.sri.ai.util.Util)2 Util.arrayList (com.sri.ai.util.Util.arrayList)2 Util.arrayListFilledWith (com.sri.ai.util.Util.arrayListFilledWith)2 Util.in (com.sri.ai.util.Util.in)2 Util.println (com.sri.ai.util.Util.println)2 Pair (com.sri.ai.util.base.Pair)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 BiFunction (java.util.function.BiFunction)2