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);
}
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;
}
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;
}
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;
}
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
}
Aggregations