Search in sources :

Example 1 with AEBPTestingDataFrame

use of com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest3 method solveGabrielWithBoxing.

public static AEBPTestingDataFrame solveGabrielWithBoxing(Variable query, EditableFactorNetwork factorNetwork, long maximunTimeInSeconds, String PGMName) {
    println("\nSolving with Gabriel's Anytime - boxing\n");
    Predicate<Polytope> criteria = p -> ((IntensionalConvexHullOfFactors) p).getIndices().size() > 10;
    AEBP aebp = new AEBP(factorNetwork, query, criteria, true);
    /*while(aebp.hasNext()) {
			Polytope p = aebp.next();
			println(p);
		}*/
    return AEBPSolver.solve(aebp, query, maximunTimeInSeconds, 0, PGMName, "Boxing");
}
Also used : Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) ExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP) Util.list(com.sri.ai.util.Util.list) TableFactor(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor) AEBPRPlotting(com.sri.ai.util.rplot.AEBPRPlotting) Factor(com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor) Polytope(com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope) File(java.io.File) AnytimeExactBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) TableVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable) ArrayList(java.util.ArrayList) TestCases(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.TestCases) List(java.util.List) TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) ExactBPNode(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.api.ExactBPNode) Predicate(com.google.common.base.Predicate) AEBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.AEBP) EditableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.api.EditableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) Util.println(com.sri.ai.util.Util.println) LinkedHashSet(java.util.LinkedHashSet) AssignmentsIterator(com.sri.ai.grinder.helper.AssignmentsIterator) IntensionalConvexHullOfFactors(com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors) AEBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.AEBP)

Example 2 with AEBPTestingDataFrame

use of com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest3 method solveGabrielWithoutBoxing.

private static AEBPTestingDataFrame solveGabrielWithoutBoxing(Variable query, EditableFactorNetwork factorNetwork, long maximunTimeInSeconds, String PGMName) {
    println("\nSolving with Gabriel's Anytime - no boxing\n");
    AEBP aebp = new AEBP(factorNetwork, query);
    AEBPTestingDataFrame df = AEBPSolver.solve(aebp, query, maximunTimeInSeconds, 1, PGMName, "noBoxing");
    return df;
}
Also used : AEBP(com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.AEBP) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)

Example 3 with AEBPTestingDataFrame

use of com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame in project aic-praise by aic-sri-international.

the class AEBPSolver method ExecuteSolverForACertainAmountOftime.

private static AEBPTestingDataFrame ExecuteSolverForACertainAmountOftime(long maximunTimeInSeconds, AEBPTaskSolver solver) {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<AEBPTestingDataFrame> future = executor.submit(solver);
    AEBPTestingDataFrame result = null;
    try {
        System.out.println("Started..");
        result = future.get(maximunTimeInSeconds, TimeUnit.SECONDS);
        System.out.println("Finished!");
    } catch (TimeoutException toe) {
        System.out.println("Timeout occurred, interrupting solver.");
        result = solver.interrupt();
        future.cancel(true);
        try {
            // Wait until the solver shuts down properly from the interrupt
            System.out.println("Waiting for interrupted result");
            result = future.get();
            System.out.println("Finished waiting for interrupted result");
        } catch (Throwable t) {
            System.out.println("Finished waiting for interrupted result : " + (t.getMessage() == null ? t.getClass().getName() : t.getMessage()));
        }
    } catch (Throwable t) {
        System.out.println("Terminated! : " + (t.getMessage() == null ? t.getClass().getName() : t.getMessage()));
        t.printStackTrace();
    }
    executor.shutdown();
    System.out.println("executor is shutdown:" + executor.isShutdown());
    return result;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with AEBPTestingDataFrame

use of com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest2 method solveWithBothMethods.

public static AEBPTestingDataFrame solveWithBothMethods(TableVariable query, TableFactorNetwork factorNetwork, double maximunTimeInSeconds, String PGMName) {
    // AEBPTestingDataFrame result = solveWithRodrigos(query, factorNetwork, maximunTimeInSeconds, PGMName);
    AEBPTestingDataFrame result = solveWithGabrielsNotIncremental(query, factorNetwork, maximunTimeInSeconds, PGMName);
    AEBPTestingDataFrame gabriels = solveWithGabriels(query, factorNetwork, maximunTimeInSeconds, PGMName);
    for (int i = 0; i < gabriels.getNumberOfRows(); i++) {
        result.addRow(gabriels.getRow(i));
    }
    return result;
}
Also used : AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)

Example 5 with AEBPTestingDataFrame

use of com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame in project aic-praise by aic-sri-international.

the class AnytimeExactBPTest3 method testing.

public static void testing(List<TableFactor> factors, int time, TableVariable query, String PGMname) {
    TableFactorNetwork network = new TableFactorNetwork(factors);
    // AEBPTestingDataFrame df  = solveGabrielWithBoxing(query, network, time,PGMname);
    AEBPTestingDataFrame df = solveGabrielWithoutBoxing(query, network, time, PGMname);
    // AEBPTestingDataFrame df3 = solveRodrigoWithoutBoxing(query, network, time, PGMname);
    // df.concatenate(df2);
    // df.concatenate(df3);
    AEBPRPlotting.plottingTheInterval(df, true, PGMname + ".pdf");
    AEBPRPlotting.plottingTheInterval(df, true, PGMname + ".pdf");
}
Also used : TableFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork) AEBPTestingDataFrame(com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)

Aggregations

AEBPTestingDataFrame (com.sri.ai.util.rplot.dataframe.AEBPTestingDataFrame)11 TableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactorNetwork)5 TableVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableVariable)3 AEBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.AEBP)2 Polytope (com.sri.ai.praise.core.representation.interfacebased.polytope.api.Polytope)2 Predicate (com.google.common.base.Predicate)1 AssignmentsIterator (com.sri.ai.grinder.helper.AssignmentsIterator)1 TestCases (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.gabriel.TestCases)1 AnytimeExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.anytime.rodrigo.AnytimeExactBP)1 ExactBPNode (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.api.ExactBPNode)1 ExactBP (com.sri.ai.praise.core.inference.byinputrepresentation.interfacebased.core.exactbp.fulltime.core.ExactBP)1 EditableFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.api.EditableFactorNetwork)1 Factor (com.sri.ai.praise.core.representation.interfacebased.factor.api.Factor)1 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)1 TableFactor (com.sri.ai.praise.core.representation.interfacebased.factor.core.table.TableFactor)1 IntensionalConvexHullOfFactors (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.IntensionalConvexHullOfFactors)1 ProductPolytope (com.sri.ai.praise.core.representation.interfacebased.polytope.core.byexpressiveness.convexhull.ProductPolytope)1 Util.list (com.sri.ai.util.Util.list)1 Util.println (com.sri.ai.util.Util.println)1 Pair (com.sri.ai.util.base.Pair)1