Search in sources :

Example 1 with HOGMMultiQueryProblemSolver

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver in project aic-praise by aic-sri-international.

the class HOGMMultiQueryProblemSolverTest method linearRealArithmeticBug2.

@Test
public void linearRealArithmeticBug2() {
    String model = "random x : [-10;10];";
    String query = "x > 5 and x < 7";
    Expression expected = parse("if x > 5 and x < 7 then 0.1 else 0.9");
    HOGMMultiQueryProblemSolver solver = new HOGMMultiQueryProblemSolver(model, list(query));
    List<HOGMProblemResult> results = solver.getResults();
    assertEquals(1, results.size());
    HOGMProblemResult result = getFirst(results);
    result.getErrors().stream().forEach(e -> println(e));
    Expression resultValue = result.getResult();
    println(resultValue);
    println(result.getExplanation());
    assertFalse(result.hasErrors());
    println("query: " + query);
    println("expected: " + expected);
    println("actual: " + result.getResult());
    assertEquals(expected, result.getResult());
}
Also used : HOGMMultiQueryProblemSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver) HOGMProblemResult(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult) Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 2 with HOGMMultiQueryProblemSolver

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver in project aic-praise by aic-sri-international.

the class HOGMMultiQueryProblemSolverTest method linearRealArithmeticBug.

// @Test // TODO: need to fix bug in which using theory mixing DifferenceArithmeticTheory and LinearRealArithmeticTheory cause errors recognizing literals.
public void linearRealArithmeticBug() {
    String model = "random x : Real;\n" + "random y : Real;\n" + "y > 2.99 and y < 3.01;\n" + "x > y - 0.4999999999 and x < y + 0.4999999999;\n" + "//x = y;";
    String query = "x < 3";
    HOGMMultiQueryProblemSolver solver = new HOGMMultiQueryProblemSolver(model, list(query));
    List<HOGMProblemResult> results = solver.getResults();
    assertEquals(1, results.size());
    HOGMProblemResult result = getFirst(results);
    result.getErrors().stream().forEach(e -> println(e));
    Expression resultValue = result.getResult();
    println(resultValue);
    assertFalse(result.hasErrors());
    println("query: " + query);
    println("expected: 0.5");
    println("actual: " + result.getResult());
    assertEquals(parse("0.5"), result.getResult());
}
Also used : HOGMMultiQueryProblemSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver) HOGMProblemResult(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult) Expression(com.sri.ai.expresso.api.Expression)

Example 3 with HOGMMultiQueryProblemSolver

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver in project aic-praise by aic-sri-international.

the class HOGMMultiQueryProblemSolverTest method softProceduralAttachment3.

@Test
public void softProceduralAttachment3() {
    ExpressoConfiguration.setDisplayNumericsExactlyForSymbols(false);
    ExpressoConfiguration.setDisplayNumericsMostDecimalPlacesInApproximateRepresentationOfNumericalSymbols(3);
    String model = "random x : [0;1000];" + "if x > 81.19 and x < 82.32 then 1 else 0;";
    String query = "x";
    Expression expected = parse("if x > 81.19 then if x < 82.32 then 0.885 else 0 else 0");
    HOGMMultiQueryProblemSolver solver = new HOGMMultiQueryProblemSolver(model, list(query));
    List<HOGMProblemResult> results = solver.getResults();
    assertEquals(1, results.size());
    HOGMProblemResult result = getFirst(results);
    result.getErrors().stream().forEach(e -> println(e));
    Expression resultValue = result.getResult();
    println(resultValue);
    assertFalse(result.hasErrors());
    println("query: " + query);
    println("expected: " + expected);
    println("actual: " + result.getResult());
    assertEquals(expected.toString(), result.getResult().toString());
}
Also used : HOGMMultiQueryProblemSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver) HOGMProblemResult(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult) Expression(com.sri.ai.expresso.api.Expression) Test(org.junit.Test)

Example 4 with HOGMMultiQueryProblemSolver

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver in project aic-praise by aic-sri-international.

the class PRAiSE method solveModel.

private void solveModel(ModelPage modelPage) {
    outputModel(modelPage);
    startSummationCounting();
    HOGMMultiQueryProblemSolver solver = new HOGMMultiQueryProblemSolver(modelPage.getModelString(), modelPage.getDefaultQueriesToRun());
    List<HOGMProblemResult> modelPageResults = solver.getResults();
    outputModelResults(solver, modelPageResults);
}
Also used : HOGMMultiQueryProblemSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver) HOGMProblemResult(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult)

Example 5 with HOGMMultiQueryProblemSolver

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver in project aic-praise by aic-sri-international.

the class HOGMMultiQueryProblemSolverTest method linearRealArithmeticSmall.

@Test
public void linearRealArithmeticSmall() {
    String explanationFileName = "explanation.txt";
    explanationBlockToFile(explanationFileName, "Going to solve small linear arithmetic problem", code(() -> {
        String model = "random external : 1..5;\n" + "random internal2 : 1..5;\n" + "\n" + "internal2 = external - 1;\n" + "external = 5;" + "";
        String query2 = "internal2";
        HOGMMultiQueryProblemSolver solver = new HOGMMultiQueryProblemSolver(model, list(query2));
        ProceduralAttachments proceduralAttachments = new DefaultProceduralAttachments();
        solver.setProceduralAttachments(proceduralAttachments);
        List<HOGMProblemResult> results = solver.getResults();
        assertEquals(1, results.size());
        HOGMProblemResult result = results.get(0);
        result.getErrors().stream().forEach(e -> println(e));
        Expression resultValue = result.getResult();
        println(resultValue);
        println("Explanation");
        println(result.getExplanation());
        assertFalse(result.hasErrors());
        assertEquals(parse("if internal2 = 4 then 1 else 0"), result.getResult());
    }));
}
Also used : HOGMMultiQueryProblemSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver) Procedure(com.sri.ai.praise.other.integration.proceduralattachment.api.Procedure) ThreadExplanationLogger.explanationBlockToFile(com.sri.ai.util.explanation.logging.api.ThreadExplanationLogger.explanationBlockToFile) Util.list(com.sri.ai.util.Util.list) Test(org.junit.Test) Expression(com.sri.ai.expresso.api.Expression) ProceduralAttachments(com.sri.ai.praise.other.integration.proceduralattachment.api.ProceduralAttachments) Util.map(com.sri.ai.util.Util.map) List(java.util.List) HOGMMultiQueryProblemSolver(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver) ExpressoConfiguration(com.sri.ai.expresso.ExpressoConfiguration) DefaultProceduralAttachments(com.sri.ai.praise.other.integration.proceduralattachment.core.DefaultProceduralAttachments) Assert.assertFalse(org.junit.Assert.assertFalse) Expressions.parse(com.sri.ai.expresso.helper.Expressions.parse) ThreadExplanationLogger.code(com.sri.ai.util.explanation.logging.api.ThreadExplanationLogger.code) Util.getFirst(com.sri.ai.util.Util.getFirst) HOGMProblemResult(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult) Util.println(com.sri.ai.util.Util.println) Assert.assertEquals(org.junit.Assert.assertEquals) HOGMProblemResult(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult) Expression(com.sri.ai.expresso.api.Expression) List(java.util.List) ProceduralAttachments(com.sri.ai.praise.other.integration.proceduralattachment.api.ProceduralAttachments) DefaultProceduralAttachments(com.sri.ai.praise.other.integration.proceduralattachment.core.DefaultProceduralAttachments) DefaultProceduralAttachments(com.sri.ai.praise.other.integration.proceduralattachment.core.DefaultProceduralAttachments) Test(org.junit.Test)

Aggregations

HOGMMultiQueryProblemSolver (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMMultiQueryProblemSolver)7 HOGMProblemResult (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.solver.HOGMProblemResult)7 Expression (com.sri.ai.expresso.api.Expression)6 Test (org.junit.Test)4 ProceduralAttachments (com.sri.ai.praise.other.integration.proceduralattachment.api.ProceduralAttachments)3 Procedure (com.sri.ai.praise.other.integration.proceduralattachment.api.Procedure)3 DefaultProceduralAttachments (com.sri.ai.praise.other.integration.proceduralattachment.core.DefaultProceduralAttachments)3 ExpressoConfiguration (com.sri.ai.expresso.ExpressoConfiguration)1 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)1 Util.getFirst (com.sri.ai.util.Util.getFirst)1 Util.list (com.sri.ai.util.Util.list)1 Util.map (com.sri.ai.util.Util.map)1 Util.println (com.sri.ai.util.Util.println)1 ThreadExplanationLogger.code (com.sri.ai.util.explanation.logging.api.ThreadExplanationLogger.code)1 ThreadExplanationLogger.explanationBlockToFile (com.sri.ai.util.explanation.logging.api.ThreadExplanationLogger.explanationBlockToFile)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1