Search in sources :

Example 1 with ExternalProcessSolverResult

use of com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult in project aic-praise by aic-sri-international.

the class SolverEvaluation method getResultsFromAllRuns.

private SolverEvaluationResult getResultsFromAllRuns(Problem problem) {
    SolverEvaluationResult solverEvaluationResult = new SolverEvaluationResult(solver, problem);
    for (int i = 0; i != configuration.getNumberOfRunsToAverageOver(); i++) {
        ExternalProcessSolverResult solverResult = solve(problem);
        solverEvaluationResult.aggregateSingleRunSolverResult(solverResult);
    }
    solverEvaluationResult.recordAverageTime(configuration.getNumberOfRunsToAverageOver());
    return solverEvaluationResult;
}
Also used : ExternalProcessSolverResult(com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult)

Example 2 with ExternalProcessSolverResult

use of com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult in project aic-praise by aic-sri-international.

the class VECSolver method solve.

@Override
public ExternalProcessSolverResult solve(String solveRequestId, ModelLanguage modelLanguage, String model, String evidenceQuery) throws Exception {
    if (modelLanguage != ModelLanguage.HOGMv1) {
        throw new UnsupportedOperationException(modelLanguage.name() + " is currently not supported by this solver.");
    }
    Translator inputToUAITranslator = TranslatorFactory.newTranslator(modelLanguage, ModelLanguage.UAI);
    // NOTE: This trick is dependent on the input model being HOGMv1
    String hogmv1Model = model + "\nrandom UAIQuery : Boolean;\nif " + evidenceQuery + " then UAIQuery else not UAIQuery;\n";
    VECCallResult partitionResult = callVECPR("Partition Function " + solveRequestId, inputToUAITranslator, hogmv1Model, new Reader[] { new StringReader(hogmv1Model) });
    VECCallResult evidenceResult = callVECPR("Evidence " + solveRequestId, inputToUAITranslator, hogmv1Model + "\nUAIQuery;", new Reader[] { new StringReader(hogmv1Model), new StringReader("UAIQuery") });
    Double probabilityResult = Math.pow(10, evidenceResult.resultLog10) / Math.pow(10, partitionResult.resultLog10);
    ExternalProcessSolverResult result = new ExternalProcessSolverResult(Math.max(partitionResult.translationTookMS, evidenceResult.translationTookMS), Math.max(partitionResult.vecProcessTookMS, evidenceResult.vecProcessTookMS), probabilityResult.isNaN() ? null : Expressions.makeSymbol(probabilityResult));
    return result;
}
Also used : Translator(com.sri.ai.praise.core.representation.translation.ciaranframework.api.Translator) StringReader(java.io.StringReader) ExternalProcessSolverResult(com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult)

Example 3 with ExternalProcessSolverResult

use of com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult in project aic-praise by aic-sri-international.

the class PRAiSESolver method solve.

@Override
public ExternalProcessSolverResult solve(String solveRequestId, ModelLanguage modelLanguage, String model, String evidenceQuery) throws Exception {
    if (modelLanguage != ModelLanguage.HOGMv1) {
        throw new UnsupportedOperationException(modelLanguage.name() + " is currently not supported by this solver.");
    }
    SGSolverCallResult prResult = prCallSGSolverCLI(model, evidenceQuery);
    Expression probabilityEvidence = null;
    if (prResult.resultExpression != null) {
        Expression queryExpr = Expressions.parse(evidenceQuery);
        Expression resultExpr = Expressions.parse(prResult.resultExpression);
        // Simplify if possible
        if (IfThenElse.isIfThenElse(resultExpr)) {
            Expression condition = IfThenElse.condition(resultExpr);
            if (condition.equals(queryExpr)) {
                probabilityEvidence = IfThenElse.thenBranch(resultExpr);
            } else if (Not.isNegation(condition) && condition.get(0).equals(queryExpr)) {
                probabilityEvidence = IfThenElse.elseBranch(resultExpr);
            }
        } else if (resultExpr.equals(queryExpr)) {
            probabilityEvidence = Expressions.ONE;
        } else if (Not.isNegation(resultExpr)) {
            if (resultExpr.get(0).equals(queryExpr)) {
                probabilityEvidence = Expressions.ZERO;
            }
        }
        // If unable to simplify just return the result as computed (i.e. likely symbolic).
        if (probabilityEvidence == null) {
            probabilityEvidence = resultExpr;
        }
    }
    ExternalProcessSolverResult result = new ExternalProcessSolverResult(0, prResult.sgSolverProcessTookMS, probabilityEvidence);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) ExternalProcessSolverResult(com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult)

Aggregations

ExternalProcessSolverResult (com.sri.ai.praise.core.inference.externalprocesssolver.core.ExternalProcessSolverResult)3 Expression (com.sri.ai.expresso.api.Expression)1 Translator (com.sri.ai.praise.core.representation.translation.ciaranframework.api.Translator)1 StringReader (java.io.StringReader)1