Search in sources :

Example 6 with AtomicPolytope

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

the class GradientAnytimeExactBP method getAbsoluteVolumeVariationWithRespectTo.

@Override
public Double getAbsoluteVolumeVariationWithRespectTo(Anytime<Factor> sub) {
    if (sub.equals(null)) {
        throw new Error("Sub does not exist, can't compute volume variation");
    }
    Approximation<Factor> subApproximation = sub.getCurrentApproximation();
    AtomicPolytope subAtomicPolytope = transformApproximationToAtomicPolytopeOrThrowsErrorIfNotPossible(subApproximation);
    Set<? extends Variable> subAtomicPolytopeIndices = getIndices(subAtomicPolytope);
    if (evenOneSubWithTotalIgnoranceRendersApproximationEqualToTotalIgnorance()) {
        // root is a variable
        return getAbsoluteVolumeVariationFromFactorToVariableWithRespectTo(sub, subAtomicPolytopeIndices);
    }
    return getAbsoluteVolumeVariationFromVariableToFactorWithRespectTo(sub, subAtomicPolytopeIndices);
}
Also used : ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 7 with AtomicPolytope

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

the class GradientAnytimeExactBP method getAbsoluteVolumeVariationFromVariableToFactorWithRespectTo.

// implementation based on logVolume
private Double getAbsoluteVolumeVariationFromVariableToFactorWithRespectTo(Anytime<Factor> sub, Collection<? extends Variable> subAtomicPolytopeIndices) {
    // root is a factor
    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);
    Factor normalizedMaxFactorWithoutOneSub = createNormalizedMaxFactorWithoutOneSub(sub, rootIndices);
    Factor normalizedMinFactorWithoutOneSub = createNormalizedMinFactorWithoutOneSub(sub, rootIndices);
    Factor minusNormalizedMinFactorWithoutOneSub = normalizedMinFactorWithoutOneSub.multiply(new ConstantFactor(1.));
    Factor MaxMinusMinFactorWithoutOneSub = normalizedMaxFactorWithoutOneSub.add(minusNormalizedMinFactorWithoutOneSub);
    Factor firstTermProduct = invertedMaxMinusMinFactor.multiply(MaxMinusMinFactorWithoutOneSub);
    Factor firstTerm = firstTermProduct.sumOut(new ArrayList<>(rootConvexHull.getFreeVariables()));
    return null;
}
Also used : 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) ConstantFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.ConstantFactor) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 8 with AtomicPolytope

use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope 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)

Example 9 with AtomicPolytope

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

the class GradientAnytimeExactBP method collapse.

private static AtomicPolytope collapse(Polytope subPolytope) {
    Variable freeVariable = getFreeVariable(subPolytope);
    AtomicPolytope subAtomicPolytope = Polytopes.getEquivalentAtomicPolytopeOn(freeVariable, subPolytope);
    return subAtomicPolytope;
}
Also used : Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 10 with AtomicPolytope

use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope 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)

Aggregations

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