Search in sources :

Example 1 with Polytope

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

the class Polytopes method sumOut.

public static Polytope sumOut(List<? extends Variable> variablesToBeSummedOut, Collection<? extends Polytope> polytopes) {
    List<Polytope> independentOfVariablesToBeSummedOut = list();
    List<Polytope> dependentOfVariablesToBeSummedOut = list();
    collect(getNonIdentityAtomicPolytopes(polytopes), isIndependentOf(variablesToBeSummedOut), independentOfVariablesToBeSummedOut, dependentOfVariablesToBeSummedOut);
    Polytope projectedPolytope = makeProjectedPolytopeOfIntensionalConvexHull(variablesToBeSummedOut, dependentOfVariablesToBeSummedOut);
    Polytope result = makeProductOfPolytopes(independentOfVariablesToBeSummedOut, projectedPolytope);
    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)

Example 2 with Polytope

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

the class Polytopes method makeProjectedPolytopeOfIntensionalConvexHull.

private static Polytope makeProjectedPolytopeOfIntensionalConvexHull(List<? extends Variable> variablesToBeSummedOut, List<Polytope> dependentOfVariablesToBeSummedOut) {
    List<Variable> simplexVariables = collectSimplexVariables(dependentOfVariablesToBeSummedOut);
    List<Variable> indicesFromConvexHulls = collectIndicesFromIntensionalPolytopes(dependentOfVariablesToBeSummedOut);
    List<Factor> factors = collectFactorsFromIntensionalPolytopes(dependentOfVariablesToBeSummedOut);
    Factor productOfFactors = Factor.multiply(factors);
    List<? extends Variable> variablesToBeSummedOutOnceSimplexesAreDealtWith = subtract(variablesToBeSummedOut, simplexVariables);
    Factor projectedFactor = productOfFactors.sumOut(variablesToBeSummedOutOnceSimplexesAreDealtWith);
    List<Variable> finalIndices = union(indicesFromConvexHulls, simplexVariables);
    Polytope projectedPolytope = new IntensionalConvexHullOfFactors(finalIndices, projectedFactor);
    return projectedPolytope;
}
Also used : AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) TableBoxVariable(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)

Example 3 with Polytope

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

the class Polytopes method BoxAPolytope.

public static Polytope BoxAPolytope(Polytope polytope, Predicate<Polytope> criteria) {
    List<Polytope> toBeBoxed = list();
    List<Polytope> notToBeBoxed = list();
    collect(getNonIdentityAtomicPolytopes(list(polytope)), p -> p instanceof IntensionalConvexHullOfFactors && criteria.apply(p), toBeBoxed, notToBeBoxed);
    Polytope boxedPolytopes = boxPolytopes(toBeBoxed);
    Polytope result = makeProductOfPolytopes(notToBeBoxed, 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)

Example 4 with Polytope

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

the class AnytimeExactBPTest3 method solveGabrielWithBoxing.

public static AEBPTestingDataFrame solveGabrielWithBoxing(Variable query, EditableFactorNetwork factorNetwork, long maximunTimeInSeconds, String PGMName) {
    println("\nSolving with Gabriel's Anytime - boxing\n");
    Predicate<Polytope> criteria = p -> ((IntensionalConvexHullOfFactors) p).getIndices().size() > 10;
    AEBP aebp = new AEBP(factorNetwork, query, criteria, true);
    /*while(aebp.hasNext()) {
			Polytope p = aebp.next();
			println(p);
		}*/
    return AEBPSolver.solve(aebp, query, maximunTimeInSeconds, 0, PGMName, "Boxing");
}
Also used : Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) ExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP) Util.list(com.sri.ai.util.Util.list) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) AEBPRPlotting(com.sri.ai.util.rplot.AEBPRPlotting) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) File(java.io.File) AnytimeExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP) 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) TestCases(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.TestCases) List(java.util.List) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) ExactBPNode(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.api.ExactBPNode) Predicate(com.google.common.base.Predicate) AEBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.AEBP) EditableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.api.EditableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) Util.println(com.sri.ai.util.Util.println) LinkedHashSet(java.util.LinkedHashSet) AssignmentsIterator(com.sri.ai.grinder.helper.AssignmentsIterator) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) AEBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.AEBP)

Example 5 with Polytope

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

the class AEBPQueryTreeNode method messageSent.

@Override
public Polytope messageSent(Predicate<Polytope> boxIt) {
    Polytope message = super.messageSent(boxIt);
    Polytope result = Polytopes.getEquivalentAtomicPolytopeOn(this.root, message);
    return result;
}
Also used : Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)

Aggregations

Polytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)28 AtomicPolytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)20 Polytopes.identityPolytope (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope)15 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)9 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)5 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)5 ArrayList (java.util.ArrayList)5 ConstantFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor)4 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)4 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)4 Predicate (com.google.common.base.Predicate)3 Box (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.Box)3 TableBoxVariable (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable)3 Util.list (com.sri.ai.util.Util.list)3 List (java.util.List)3 IDENTITY_FACTOR (com.sri.ai.praise.core.representation.interfacebased.factor.core.IdentityFactor.IDENTITY_FACTOR)2 Util.collect (com.sri.ai.util.Util.collect)2 Util.getFirst (com.sri.ai.util.Util.getFirst)2 Util.getFirstSatisfyingPredicateOrNull (com.sri.ai.util.Util.getFirstSatisfyingPredicateOrNull)2 Util.in (com.sri.ai.util.Util.in)2