Search in sources :

Example 21 with Polytope

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

the class AnytimeExactBP method function.

@Override
public Approximation<Factor> function(List<Approximation<Factor>> subsApproximations) {
    Polytope product = getProductOfAllIncomingPolytopesAndFactorAtRoot(subsApproximations);
    Collection<? extends Variable> freeVariables = product.getFreeVariables();
    List<? extends Variable> variablesSummedOut = getBase().determinedVariablesToBeSummedOut(freeVariables);
    Approximation<Factor> result = sumOut(variablesSummedOut, product);
    return result;
}
Also used : Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) Polytopes.identityPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)

Example 22 with Polytope

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

the class GradientAnytimeExactBP method createNormalizedMinFactorWithoutOneSub.

private Factor createNormalizedMinFactorWithoutOneSub(Anytime<Factor> sub, Collection<? extends Variable> rootIndices) {
    Polytope rootPolytopeWithoutOneSub = productWithoutOneSub(sub);
    IntensionalConvexHullOfFactors rootConvexHullWithoutOneSub = (IntensionalConvexHullOfFactors) rootPolytopeWithoutOneSub;
    Factor rootFactorWithoutOneSub = rootConvexHullWithoutOneSub.getFactor();
    Factor minRootFactorWithoutOneSub = rootFactorWithoutOneSub.min(rootIndices);
    Factor normalizedMinFactorWithoutOneSub = minRootFactorWithoutOneSub.normalize();
    return normalizedMinFactorWithoutOneSub;
}
Also used : Polytopes.identityPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)

Example 23 with Polytope

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

the class GradientAnytimeExactBP method createNormalizedMaxFactorWithoutOneSub.

private Factor createNormalizedMaxFactorWithoutOneSub(Anytime<Factor> sub, Collection<? extends Variable> rootIndices) {
    Polytope rootPolytopeWithoutOneSub = productWithoutOneSub(sub);
    IntensionalConvexHullOfFactors rootConvexHullWithoutOneSub = (IntensionalConvexHullOfFactors) rootPolytopeWithoutOneSub;
    Factor rootFactorWithoutOneSub = rootConvexHullWithoutOneSub.getFactor();
    Factor maxRootFactorWithoutOneSub = rootFactorWithoutOneSub.max(rootIndices);
    Factor normalizedMaxFactorWithoutOneSub = maxRootFactorWithoutOneSub.normalize();
    return normalizedMaxFactorWithoutOneSub;
}
Also used : Polytopes.identityPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)

Example 24 with Polytope

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

the class GradientAnytimeExactBP method getAllPolytopesButOneWithFactor.

private List<Polytope> getAllPolytopesButOneWithFactor(Polytope subApproximationToRemove, List<Approximation<Factor>> subsApproximations) {
    List<Polytope> polytopesToMultiply = mapIntoList(subsApproximations, a -> (Polytope) a);
    for (Polytope subPolytope : polytopesToMultiply) {
        if (subPolytope.equals(subApproximationToRemove)) {
            polytopesToMultiply.remove(subPolytope);
        }
    }
    ;
    addFactorAtRootPolytope(polytopesToMultiply);
    return polytopesToMultiply;
}
Also used : Polytopes.identityPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)

Example 25 with Polytope

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

the class GradientAnytimeExactBP method transformApproximationToAtomicPolytopeOrThrowsErrorIfNotPossible.

private static AtomicPolytope transformApproximationToAtomicPolytopeOrThrowsErrorIfNotPossible(Approximation<Factor> approximation) {
    if (!(approximation instanceof Polytope)) {
        throw new Error("Gradient descent AEBP works only with polytopes for now");
    }
    Polytope polytope = (Polytope) approximation;
    AtomicPolytope atomicPolytope = collapse(polytope);
    return atomicPolytope;
}
Also used : Polytopes.identityPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.Polytopes.identityPolytope) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

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