Search in sources :

Example 11 with Polytope

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

the class GradientAnytimeExactBP method getProductOfAllIncomingPolytopesButOneAndFactorAtRoot.

private Polytope getProductOfAllIncomingPolytopesButOneAndFactorAtRoot(Anytime<Factor> sub, List<Approximation<Factor>> subsApproximations) {
    Polytope subApproximationToRemove = (Polytope) sub.getCurrentApproximation();
    List<Polytope> polytopesToMultiply = getAllPolytopesButOneWithFactor(subApproximationToRemove, subsApproximations);
    Polytope result = accumulate(polytopesToMultiply, Polytope::multiply, identityPolytope());
    return result;
}
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)

Example 12 with Polytope

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

the class AEBP method calculateNext.

@Override
protected Polytope calculateNext() {
    if (!getNextNodeToPutOnTheTree.hasNext()) {
        return null;
    }
    expand();
    Polytope result = computeInference();
    return result;
}
Also used : Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)

Example 13 with Polytope

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

the class AnytimeExactBPTest2 method solveAndStoreInDataFrame.

private static AEBPTestingDataFrame solveAndStoreInDataFrame(Iterator<? extends Approximation<Factor>> anytimeEBPIterator, TableVariable query, double maximunTimeInSeconds, int runNumber, String PGMName, String methodName) {
    AEBPTestingDataFrame df = new AEBPTestingDataFrame();
    int i = 0;
    Double currentTotalTime = .0;
    // long startTime = System.currentTimeMillis();
    while (currentTotalTime < maximunTimeInSeconds) {
        println(++i);
        Long currentTime = System.currentTimeMillis();
        if (!anytimeEBPIterator.hasNext()) {
            break;
        }
        Polytope result = (Polytope) anytimeEBPIterator.next();
        Pair<? extends List<Double>, ? extends List<Double>> maxAndMin = printPolytopeAndMaxAndMin(query, result);
        Double currentPartialTime = .001 * (System.currentTimeMillis() - currentTime);
        // currentTotalTime = .001*(System.currentTimeMillis() - startTime);
        currentTotalTime += currentPartialTime;
        println("time: " + currentTotalTime);
        df.addRow(runNumber, i, maxAndMin.second.get(0), maxAndMin.first.get(0), currentPartialTime, currentTotalTime, methodName, PGMName);
        println("...");
    }
    println("-----Done-----");
    return df;
}
Also used : Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) ProductPolytope(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.ProductPolytope) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)

Example 14 with Polytope

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

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

the class Polytopes method makeProductOfPolytopes.

private static Polytope makeProductOfPolytopes(List<Polytope> independentOfVariablesToBeSummedOut, Polytope projectedPolytope) {
    List<Polytope> resultingPolytopes = independentOfVariablesToBeSummedOut;
    resultingPolytopes.add(projectedPolytope);
    Polytope result = Polytope.multiply(resultingPolytopes);
    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)

Aggregations

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