Search in sources :

Example 1 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 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;
}
Also used : IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 2 with AtomicPolytope

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;
}
Also used : Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 3 with AtomicPolytope

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;
}
Also used : 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 4 with AtomicPolytope

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;
}
Also used : Util.union(com.sri.ai.util.Util.union) Util.intersect(com.sri.ai.util.Util.intersect) Box(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.Box) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) Util.getFirstSatisfyingPredicateOrNull(com.sri.ai.util.Util.getFirstSatisfyingPredicateOrNull) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) CartesianProductIterator(com.sri.ai.util.collect.CartesianProductIterator) ArrayList(java.util.ArrayList) Util.in(com.sri.ai.util.Util.in) Util.getFirst(com.sri.ai.util.Util.getFirst) IDENTITY_FACTOR(com.sri.ai.praise.core.representation.interfacebased.factor.core.IdentityFactor.IDENTITY_FACTOR) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) NullaryFunction(com.sri.ai.util.base.NullaryFunction) Collection(java.util.Collection) Util.list(com.sri.ai.util.Util.list) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope) Util.mapIntoList(com.sri.ai.util.Util.mapIntoList) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) Util.collect(com.sri.ai.util.Util.collect) Util.subtract(com.sri.ai.util.Util.subtract) List(java.util.List) Predicate(com.google.common.base.Predicate) Util.myAssert(com.sri.ai.util.Util.myAssert) TableBoxVariable(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.box.TableBoxVariable) AtomicPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.AtomicPolytope)

Example 5 with AtomicPolytope

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;
}
Also used : 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)

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