use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope in project aic-praise by aic-sri-international.
the class GradientAnytimeExactBP method transformApproximationToConvexHullOrThrowsErrorIfNotPossible.
private static IntensionalConvexHullOfFactors transformApproximationToConvexHullOrThrowsErrorIfNotPossible(Approximation<Factor> approximation) {
AtomicPolytope atomicPolytope = transformApproximationToAtomicPolytopeOrThrowsErrorIfNotPossible(approximation);
if (!(approximation instanceof IntensionalConvexHullOfFactors)) {
// can't be simplex because sub is not null
throw new Error("Unfit type of approximation for gradient descent");
}
IntensionalConvexHullOfFactors convexHull = (IntensionalConvexHullOfFactors) atomicPolytope;
return convexHull;
}
use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope in project aic-praise by aic-sri-international.
the class IntensionalConvexHullOfFactors method multiplyByConvexHull.
private AtomicPolytope multiplyByConvexHull(AtomicPolytope another) {
AtomicPolytope result;
IntensionalConvexHullOfFactors anotherConvexHull = (IntensionalConvexHullOfFactors) another;
if (indices.equals(anotherConvexHull.getIndices())) {
Factor productFactor = factor.multiply(anotherConvexHull.getFactor());
result = new IntensionalConvexHullOfFactors(indices, productFactor);
} else {
result = null;
}
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope in project aic-praise by aic-sri-international.
the class AbstractAtomicPolytope method multiplyByAnotherAtomicPolytope.
private Polytope multiplyByAnotherAtomicPolytope(Polytope another) {
Polytope result;
AtomicPolytope attempt = this.getProductIfItIsANonIdentityAtomicPolytopeOrNullOtherwise((AtomicPolytope) another);
if (attempt == null) {
result = new ProductPolytope(list(this, (AtomicPolytope) another));
} else {
result = attempt;
}
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope in project aic-praise by aic-sri-international.
the class Polytopes method getEquivalentAtomicPolytopeOn.
/**
* Takes a polytope in which the only free variable is a given query variable,
* and returns a single equivalent {@link AtomicPolytope}.
*
* @return
*/
public static AtomicPolytope getEquivalentAtomicPolytopeOn(Variable query, Polytope polytope) {
myAssert(polytope.getFreeVariables().size() == 1 && polytope.getFreeVariables().contains(query), () -> "getEquivalentIntensionalConvexHullOfFactorsOn must receive polytope whose only free variable is " + query + ", but instead got <" + polytope + "> with free variables " + polytope.getFreeVariables());
AtomicPolytope result;
final List<? extends AtomicPolytope> nonIdentityAtomicPolytopes = getNonIdentityAtomicPolytopes(list(polytope));
Simplex simplexOnVariableIfAny = (Simplex) getFirstSatisfyingPredicateOrNull(nonIdentityAtomicPolytopes, p -> isSimplexOn(p, query));
boolean thereIsSimplexOnQuerySoItDominates = simplexOnVariableIfAny != null;
if (thereIsSimplexOnQuerySoItDominates) {
result = simplexOnVariableIfAny;
} else {
// all nonIdentityAtomicPolytopes are intensional convex hulls, or otherwise we would have simplexes on non-query variables and the query would not be the only free variable
result = mergeIntensionalConvexHulls(nonIdentityAtomicPolytopes);
}
return result;
}
use of com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope in project aic-praise by aic-sri-international.
the class Polytopes method multiplyListOfAlreadyMultipledNonIdentityAtomicPolytopesWithANewOne.
public static Polytope multiplyListOfAlreadyMultipledNonIdentityAtomicPolytopesWithANewOne(Collection<? extends AtomicPolytope> nonIdentityAtomicPolytopes, AtomicPolytope nonIdentityAtomicAnother) {
List<AtomicPolytope> resultNonIdentityAtomicPolytopes = list();
boolean anotherAlreadyIncorporated = false;
for (AtomicPolytope nonIdentityAtomicPolytope : nonIdentityAtomicPolytopes) {
anotherAlreadyIncorporated = takeNextPolytopeInList(nonIdentityAtomicPolytope, nonIdentityAtomicAnother, resultNonIdentityAtomicPolytopes, anotherAlreadyIncorporated);
}
includeAnotherByItselfIfMultiplicationsFailed(nonIdentityAtomicAnother, anotherAlreadyIncorporated, resultNonIdentityAtomicPolytopes);
Polytope result = makePolytopeFromListOfNonIdentityAtomicPolytopes(resultNonIdentityAtomicPolytopes);
return result;
}
Aggregations