Search in sources :

Example 1 with ExpressionBasedProblem

use of com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem in project aic-praise by aic-sri-international.

the class ExpressionBasedProblemTest method runTest.

private void runTest(String modelString, String queryString, String expectedFactorExpressionsIncludingQueryDefinitionIfAnyString, String expectedQuerySymbolString, boolean expectedQueryIsCompound, String expectedSymbolsAndTypesString) {
    HOGMExpressionBasedModel model = new HOGMExpressionBasedModel(modelString);
    Expression queryExpression = parse(queryString);
    ExpressionBasedProblem problem = new DefaultExpressionBasedProblem(queryExpression, model);
    String actualFactorExpressionsIncludingQueryDefinitionIfAnyString = problem.getFactorExpressionsIncludingQueryDefinitionIfAny().toString();
    println(expectedFactorExpressionsIncludingQueryDefinitionIfAnyString);
    println(actualFactorExpressionsIncludingQueryDefinitionIfAnyString);
    assertEquals(expectedFactorExpressionsIncludingQueryDefinitionIfAnyString, actualFactorExpressionsIncludingQueryDefinitionIfAnyString);
    String actualQuerySymbol = problem.getQuerySymbol().toString();
    println("expected querySymbol: " + expectedQuerySymbolString);
    println("actual   querySymbol: " + actualQuerySymbol);
    assertEquals(expectedQuerySymbolString, actualQuerySymbol);
    boolean actualQueryIsCompound = problem.getQueryIsCompound();
    println("expected queryIsCompound: " + expectedQueryIsCompound);
    println("actual   queryIsCompound: " + actualQueryIsCompound);
    assertEquals(expectedQueryIsCompound, actualQueryIsCompound);
    String actualSymbolsAndTypesString = problem.getContext().getSymbolsAndTypes().toString();
    println("expected context string: " + expectedSymbolsAndTypesString);
    println("actual   context string: " + actualSymbolsAndTypesString);
    assertEquals(expectedSymbolsAndTypesString, actualSymbolsAndTypesString);
}
Also used : Expression(com.sri.ai.expresso.api.Expression) DefaultExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem) ExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) DefaultExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem)

Example 2 with ExpressionBasedProblem

use of com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem in project aic-praise by aic-sri-international.

the class ExpressionBasedProblemToInterfaceBasedProblemConversion method translate.

public static Problem translate(ExpressionBasedProblem expressionBasedProblem) {
    ExpressionVariable queryVariable = new DefaultExpressionVariable(expressionBasedProblem.getQuerySymbol());
    ExpressionFactorNetwork factorNetwork = makeFactorNetwork(expressionBasedProblem);
    Predicate<Expression> isExpressionParameterPredicate = expressionBasedProblem.getIsParameterPredicate();
    Predicate<Variable> isParameterPredicate = makeIsParameterPredicate(isExpressionParameterPredicate);
    Problem problem = new DefaultVariableMarginalQuery(queryVariable, factorNetwork, isParameterPredicate);
    return problem;
}
Also used : ExpressionFactorNetwork(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionFactorNetwork) DefaultExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable) ExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable) Variable(com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable) DefaultExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable) Expression(com.sri.ai.expresso.api.Expression) DefaultVariableMarginalQuery(com.sri.ai.praise.core.representation.interfacebased.factor.core.DefaultVariableMarginalQuery) DefaultExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable) ExpressionVariable(com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable) ExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem) Problem(com.sri.ai.praise.core.representation.interfacebased.factor.api.Problem)

Example 3 with ExpressionBasedProblem

use of com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem in project aic-praise by aic-sri-international.

the class ExpressionBasedSolver method solve.

default Expression solve(Expression queryExpression, ExpressionBasedModel expressionBasedModel) {
    ExpressionBasedProblem problem = new DefaultExpressionBasedProblem(queryExpression, expressionBasedModel);
    Expression result = solve(problem);
    return result;
}
Also used : DefaultExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem) ExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem) Expression(com.sri.ai.expresso.api.Expression) DefaultExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem)

Example 4 with ExpressionBasedProblem

use of com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem in project aic-praise by aic-sri-international.

the class ExpressionBasedSolverTest method runTest.

private void runTest(Expression queryExpression, ExpressionBasedModel model, Expression expected, boolean useFactorization) throws AssertionError {
    ExpressionBasedProblem problem = new DefaultExpressionBasedProblem(queryExpression, model);
    ExpressionBasedSolver[] solvers = new ExpressionBasedSolver[] { // new EvaluationExpressionBasedSolver(useFactorization),
    new ExactBPExpressionBasedSolver() };
    for (ExpressionBasedSolver solver : solvers) {
        Expression marginal = solver.solve(problem);
        checkResult(problem, expected, marginal, solver);
    }
}
Also used : ExpressionBasedSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.api.ExpressionBasedSolver) EvaluationExpressionBasedSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.core.byalgorithm.evaluation.EvaluationExpressionBasedSolver) ExactBPExpressionBasedSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.core.byalgorithm.exactbp.ExactBPExpressionBasedSolver) ExactBPExpressionBasedSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.core.byalgorithm.exactbp.ExactBPExpressionBasedSolver) ExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem) DefaultExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem) Expression(com.sri.ai.expresso.api.Expression) DefaultExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem)

Example 5 with ExpressionBasedProblem

use of com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem in project aic-praise by aic-sri-international.

the class SolverToExpressionBasedSolverAdapter method solveForQuerySymbolDefinedByExpressionBasedProblem.

@Override
protected Expression solveForQuerySymbolDefinedByExpressionBasedProblem(ExpressionBasedProblem expressionBasedProblem) {
    Problem problem = ExpressionBasedProblemToInterfaceBasedProblemConversion.translate(expressionBasedProblem);
    Expression result = getSolver().solve(problem);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ExpressionBasedProblem(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem) Problem(com.sri.ai.praise.core.representation.interfacebased.factor.api.Problem)

Aggregations

Expression (com.sri.ai.expresso.api.Expression)5 ExpressionBasedProblem (com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem)5 DefaultExpressionBasedProblem (com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem)3 Problem (com.sri.ai.praise.core.representation.interfacebased.factor.api.Problem)2 ExpressionBasedSolver (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.api.ExpressionBasedSolver)1 EvaluationExpressionBasedSolver (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.core.byalgorithm.evaluation.EvaluationExpressionBasedSolver)1 ExactBPExpressionBasedSolver (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.expressionbased.core.byalgorithm.exactbp.ExactBPExpressionBasedSolver)1 HOGMExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel)1 Variable (com.sri.ai.praise.core.representation.interfacebased.factor.api.Variable)1 DefaultVariableMarginalQuery (com.sri.ai.praise.core.representation.interfacebased.factor.core.DefaultVariableMarginalQuery)1 ExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable)1 DefaultExpressionVariable (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.DefaultExpressionVariable)1 ExpressionFactorNetwork (com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.core.ExpressionFactorNetwork)1