Search in sources :

Example 26 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 productWithoutOneSub.

private Polytope productWithoutOneSub(Anytime<Factor> sub) {
    List<Approximation<Factor>> subsApproximations = getSubsApproximation();
    Polytope product = getProductOfAllIncomingPolytopesButOne(sub, subsApproximations);
    return product;
}
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) Approximation(com.sri.ai.util.computation.anytime.api.Approximation)

Example 27 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 getAbsoluteVolumeVariationFromFactorToVariableWithRespectTo.

private Double getAbsoluteVolumeVariationFromFactorToVariableWithRespectTo(Anytime<Factor> sub, Collection<? extends Variable> subAtomicPolytopeIndices) {
    // root is a variable
    Approximation<Factor> subApproximation = sub.getCurrentApproximation();
    AtomicPolytope subAtomicPolytope = transformApproximationToAtomicPolytopeOrThrowsErrorIfNotPossible(subApproximation);
    Approximation<Factor> rootApproximation = getCurrentApproximation();
    IntensionalConvexHullOfFactors rootConvexHull = transformApproximationToConvexHullOrThrowsErrorIfNotPossible(rootApproximation);
    Collection<? extends Variable> rootIndices = rootConvexHull.getIndices();
    Factor rootFactor = rootConvexHull.getFactor();
    Factor normalizedMaxFactor = createNormalizedMaxFactor(rootIndices);
    Factor normalizedMinFactor = createNormalizedMinFactor(rootIndices);
    Factor invertedMaxMinusMinFactor = computeInvertedMaxMinusMinFactor(rootFactor, subAtomicPolytopeIndices);
    List<Variable> rootFreeVariables = new ArrayList<>(rootConvexHull.getFreeVariables());
    Factor maxFactor = rootFactor.max(rootIndices);
    Factor maxNormalizationConstant = maxFactor.sumOut(rootFreeVariables);
    Factor invertedMaxNormalizationConstant = maxNormalizationConstant.invert();
    Factor maxProduct = invertedMaxMinusMinFactor.multiply(invertedMaxNormalizationConstant);
    Factor minFactor = rootFactor.min(rootIndices);
    Factor minNormalizationConstant = minFactor.sumOut(rootFreeVariables);
    Factor invertedMinNormalizationConstant = minNormalizationConstant.invert();
    Factor minProduct = invertedMaxMinusMinFactor.multiply(invertedMinNormalizationConstant);
    Polytope summedOutPolytopeWithoutOneSub = sumOutWithoutOneSub(sub);
    IntensionalConvexHullOfFactors rootConvexHullWithoutOneSub = (IntensionalConvexHullOfFactors) summedOutPolytopeWithoutOneSub;
    Factor rootFactorWithoutOneSub = rootConvexHullWithoutOneSub.getFactor();
    Factor summedOutRootFactorWithoutOneSub = rootFactorWithoutOneSub.sumOut(rootFreeVariables);
    return null;
// TODO
}
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) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) 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) ArrayList(java.util.ArrayList) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 28 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 getProductOfAllIncomingPolytopesAndFactorAtRoot.

private Polytope getProductOfAllIncomingPolytopesAndFactorAtRoot(List<Approximation<Factor>> subsApproximations) {
    List<Polytope> polytopesToMultiply = getAllPolytopes(subsApproximations);
    Polytope result = accumulate(polytopesToMultiply, Polytope::multiply, identityPolytope());
    return result;
}
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)

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