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