Search in sources :

Example 16 with Variable

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

the class PerformanceTest method sumOutLastVariable.

private static Factor sumOutLastVariable(Factor factor) {
    List<? extends Variable> factorVariables = factor.getVariables();
    int indexOfLastVariable = factorVariables.size() - 1;
    List<Variable> variablesToSumOut = new ArrayList<>();
    if (factorVariables.size() > 0) {
        variablesToSumOut.add(factorVariables.get(indexOfLastVariable));
    }
    Factor result = factor.sumOut(variablesToSumOut);
    return result;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) RandomTableFactorMaker.makeRandomTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor) ArrayList(java.util.ArrayList) Util.print(com.sri.ai.util.Util.print)

Example 17 with Variable

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

the class PerformanceTest method sumOutFirstVariable.

private static Factor sumOutFirstVariable(Factor factor) {
    List<? extends Variable> factorVariables = factor.getVariables();
    int indexOfFirstVariable = 0;
    List<Variable> variablesToSumOut = new ArrayList<>();
    if (factorVariables.size() > 0) {
        variablesToSumOut.add(factorVariables.get(indexOfFirstVariable));
    }
    Factor result = factor.sumOut(variablesToSumOut);
    return result;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) ExpressionFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) RandomTableFactorMaker.makeRandomTableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor) ArrayList(java.util.ArrayList) Util.print(com.sri.ai.util.Util.print)

Example 18 with Variable

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

the class BenchmarkingIsingModel method testEBPP.

private static void testEBPP(AEBPTestingDataFrame df, int nRepetitions, List<TableFactor> network, TableVariable query, String netName) {
    TableFactorNetwork factorNetwork = new TableFactorNetwork(network);
    ExactBPNode<Variable, Factor> exactBP = new ExactBP(query, factorNetwork);
    for (int i = 0; i < nRepetitions; i++) {
        println("solveWithExactBP : " + netName);
        Pair<Double, Factor> p = solveAndPrint(exactBP);
        df.addRow(// run number
        i, // iteration
        -1, // minPTrue
        ((TableFactor) p.second).getEntries().get(0), // MaxPTrue
        ((TableFactor) p.second).getEntries().get(0), // iteration time
        p.first, // total time
        p.first, // InferenceMethodUsed
        "ExactBP", // GraphicalModelName
        netName + "; query: " + query.toString());
    }
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) ExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)

Example 19 with Variable

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

the class TableFactorBoxBuilder method makeTableBox.

public static Box makeTableBox(IntensionalConvexHullOfFactors bound) {
    ArrayList<TableVariable> notFreeVariables = new ArrayList<>(bound.getIndices().size());
    for (Variable v : bound.getIndices()) {
        notFreeVariables.add((TableVariable) v);
    }
    TableFactor factor = buildBoxFactor((TableFactor) bound.getFactor(), notFreeVariables);
    Box result = new Box(TABLE_BOX_VARIABLE, factor);
    return result;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) 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)

Example 20 with Variable

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

the class Polytopes method getEquivalentAtomicPolytopeOn.

/**
 * Takes a polytope in which the only free variable is a given query variable,
 * and returns a single equivalent {@link AtomicPolytope}.
 *
 * @return
 */
public static AtomicPolytope getEquivalentAtomicPolytopeOn(Variable query, Polytope polytope) {
    myAssert(polytope.getFreeVariables().size() == 1 && polytope.getFreeVariables().contains(query), () -> "getEquivalentIntensionalConvexHullOfFactorsOn must receive polytope whose only free variable is " + query + ", but instead got <" + polytope + "> with free variables " + polytope.getFreeVariables());
    AtomicPolytope result;
    final List<? extends AtomicPolytope> nonIdentityAtomicPolytopes = getNonIdentityAtomicPolytopes(list(polytope));
    Simplex simplexOnVariableIfAny = (Simplex) getFirstSatisfyingPredicateOrNull(nonIdentityAtomicPolytopes, p -> isSimplexOn(p, query));
    boolean thereIsSimplexOnQuerySoItDominates = simplexOnVariableIfAny != null;
    if (thereIsSimplexOnQuerySoItDominates) {
        result = simplexOnVariableIfAny;
    } else {
        // all nonIdentityAtomicPolytopes are intensional convex hulls, or otherwise we would have simplexes on non-query variables and the query would not be the only free variable
        result = mergeIntensionalConvexHulls(nonIdentityAtomicPolytopes);
    }
    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) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Aggregations

Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)23 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)11 ArrayList (java.util.ArrayList)10 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)9 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)9 ExpressionFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionFactor)4 AtomicPolytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)4 Polytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)4 Util.mapIntoArrayList (com.sri.ai.util.Util.mapIntoArrayList)4 List (java.util.List)4 Expression (com.sri.ai.expresso.api.Expression)3 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)3 TableBoxVariable (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable)3 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)3 Predicate (com.google.common.base.Predicate)2 AnytimeExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP)2 ExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP)2 ExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable)2 ExpressionExactBP (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionExactBP)2 RandomTableFactorMaker.makeRandomTableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.helper.RandomTableFactorMaker.makeRandomTableFactor)2