Search in sources :

Example 6 with HOGMExpressionBasedModel

use of com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel in project aic-praise by aic-sri-international.

the class PRAiSEController method importUAIModel.

private void importUAIModel(ActionEvent ae) {
    File uaiModelFile = uaiFileChooser.showOpenDialog(mainStage);
    if (uaiModelFile != null) {
        File uaiEvidenceFile = new File(uaiModelFile.getParent(), uaiModelFile.getName() + ".evid");
        StringWriter hogmWriter = new StringWriter();
        try (BufferedReader uaiModelReader = new BufferedReader(new FileReader(uaiModelFile));
            BufferedReader uaiEvidenceReader = new BufferedReader(new FileReader(uaiEvidenceFile));
            PrintWriter hogmPrintWriter = new PrintWriter(hogmWriter)) {
            UAI_to_HOGMv1_Using_Equalities_Translator translator = new UAI_to_HOGMv1_Using_Equalities_Translator();
            translator.translate(uaiModelFile.getName(), new Reader[] { uaiModelReader, uaiEvidenceReader }, new PrintWriter[] { hogmPrintWriter }, new TranslatorOptions());
            String hogmModel = hogmWriter.toString();
            // For convenience, pull out all possible queries
            HOGMParserWrapper parser = new HOGMParserWrapper();
            HOGModel parsedModel = parser.parseModel(hogmModel);
            ExpressionBasedModel factorsAndTypes = new HOGMExpressionBasedModel(parsedModel);
            List<String> queries = new ArrayList<>(factorsAndTypes.getMapFromRandomVariableNameToTypeName().keySet());
            newModel(hogmModel, queries);
        } catch (Throwable th) {
            FXUtil.exception(th);
        }
    }
}
Also used : HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) ArrayList(java.util.ArrayList) TranslatorOptions(com.sri.ai.praise.core.representation.translation.ciaranframework.api.TranslatorOptions) HOGMParserWrapper(com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) StringWriter(java.io.StringWriter) BufferedReader(java.io.BufferedReader) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) FileReader(java.io.FileReader) File(java.io.File) PrintWriter(java.io.PrintWriter) UAI_to_HOGMv1_Using_Equalities_Translator(com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.UAI_to_HOGMv1_Using_Equalities_Translator)

Example 7 with HOGMExpressionBasedModel

use of com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel in project aic-praise by aic-sri-international.

the class HOGModelGroundingTest method test.

/**
 * @throws AssertionError
 */
@Test
public void test() throws AssertionError {
    long start = System.currentTimeMillis();
    StringJoiner sj = new StringJoiner("\n");
    sj.add("sort People : 10, Putin;");
    sj.add("sort Countries : 10, USA, Russia;");
    sj.add("random country : Countries;");
    sj.add("random president : People;");
    sj.add("random communism : Boolean;");
    sj.add("random democracy : Boolean;");
    sj.add("random votePutin : 1..15;");
    sj.add("if country = Russia then if president = Putin then communism else not communism else if democracy then not communism else communism;");
    sj.add("if country = Russia then if votePutin > 5 then president = Putin else not president = Putin;");
    HOGMParserWrapper parser = new HOGMParserWrapper();
    HOGModel parsedModel = parser.parseModel(sj.toString());
    ExpressionBasedModel factorsAndTypes = new HOGMExpressionBasedModel(parsedModel);
    List<Expression> evidence = new ArrayList<>();
    evidence.add(Expressions.parse("communism"));
    StringJoiner outputBuffer = new StringJoiner("");
    HOGModelGrounding.ground(factorsAndTypes, evidence, new // NOTE: an example listener that outputs in the UAI format
    HOGModelGrounding.Listener() {

        int numberVariables;

        StringJoiner preamble = new StringJoiner("");

        StringJoiner functionTables = new StringJoiner("");

        List<Pair<Integer, Integer>> evidence = new ArrayList<>();

        @Override
        public void numberGroundVariables(int number) {
            this.numberVariables = number;
            preamble.add("MARKOV\n");
            preamble.add("" + number + "\n");
        }

        @Override
        public void groundVariableCardinality(int variableIndex, int cardinality) {
            preamble.add("" + cardinality);
            if (variableIndex == (numberVariables - 1)) {
                preamble.add("\n");
            } else {
                preamble.add(" ");
            }
        }

        @Override
        public void numberFactors(int number) {
            preamble.add("" + number + "\n");
        }

        @Override
        public void factorParticipants(int factorIndex, int[] variableIndexes) {
            preamble.add("" + variableIndexes.length);
            for (int i = 0; i < variableIndexes.length; i++) {
                preamble.add(" " + variableIndexes[i]);
            }
            preamble.add("\n");
        }

        @Override
        public void factorValue(int numberFactorValues, boolean isFirstValue, boolean isLastValue, Rational value) {
            if (isFirstValue) {
                functionTables.add("\n" + numberFactorValues + "\n");
            } else {
                functionTables.add(" ");
            }
            functionTables.add("" + value.doubleValue());
            if (isLastValue) {
                functionTables.add("\n");
            }
        }

        @Override
        public void evidence(int variableIndex, int valueIndex) {
            evidence.add(new Pair<>(variableIndex, valueIndex));
        }

        @Override
        public void groundingComplete() {
            long end = System.currentTimeMillis() - start;
            outputBuffer.add("--- MODEL ---\n");
            outputBuffer.add(preamble.toString());
            outputBuffer.add(functionTables.toString());
            outputBuffer.add("--- EVIDENCE ---\n");
            outputBuffer.add("" + evidence.size());
            for (Pair<Integer, Integer> evidenceAssignment : evidence) {
                outputBuffer.add(" ");
                outputBuffer.add(evidenceAssignment.first.toString());
                outputBuffer.add(" ");
                outputBuffer.add(evidenceAssignment.second.toString());
            }
            System.out.println(outputBuffer.toString());
            System.out.println("\nTime taken for grounding (not printing): " + end + " ms.");
        }
    });
    String expected = "--- MODEL ---\n" + "MARKOV\n" + "5\n" + "10 10 2 2 15\n" + "2\n" + "4 0 1 2 3\n" + "3 0 4 1\n" + "\n" + "400\n" + "0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0 0.0 0.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5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5\n" + "--- EVIDENCE ---\n" + "1 2 1";
    assertEquals(expected, outputBuffer.toString());
}
Also used : Rational(com.sri.ai.util.math.Rational) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) ArrayList(java.util.ArrayList) HOGMParserWrapper(com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper) HOGModelGrounding(com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.HOGModelGrounding) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) Expression(com.sri.ai.expresso.api.Expression) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) StringJoiner(java.util.StringJoiner) Pair(com.sri.ai.util.base.Pair) Test(org.junit.Test)

Example 8 with HOGMExpressionBasedModel

use of com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel in project aic-praise by aic-sri-international.

the class HOGModelGrounding method makeGroundedExpressionBasedModel.

private static ExpressionBasedModel makeGroundedExpressionBasedModel(ExpressionBasedModel factorsAndTypes, Map<String, String> newUniqueConstantToTypeMap) {
    boolean isBayesianNetwork = false;
    ExpressionBasedModel groundedFactorsAndTypesInformation = new HOGMExpressionBasedModel(// factors
    Collections.emptyList(), factorsAndTypes.getMapFromRandomVariableNameToTypeName(), factorsAndTypes.getMapFromNonUniquelyNamedConstantNameToTypeName(), newUniqueConstantToTypeMap, factorsAndTypes.getMapFromCategoricalTypeNameToSizeString(), // additional types
    list(), isBayesianNetwork);
    return groundedFactorsAndTypesInformation;
}
Also used : HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel)

Example 9 with HOGMExpressionBasedModel

use of com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel in project aic-praise by aic-sri-international.

the class HOGMMultiQueryProblemSolver method initializeModel.

private void initializeModel(String modelString) {
    HOGMModelParsing parsingWithErrorCollecting = new HOGMModelParsing(modelString, modelErrors);
    this.hogmModel = parsingWithErrorCollecting.getModel();
    this.expressionBasedModel = hogmModel == null ? null : new HOGMExpressionBasedModel(hogmModel);
    if (this.expressionBasedModel != null) {
        this.expressionBasedModel.setProceduralAttachments(proceduralAttachments);
    }
}
Also used : HOGMModelParsing(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMModelParsing) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel)

Aggregations

HOGMExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel)9 ExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel)5 Expression (com.sri.ai.expresso.api.Expression)4 HOGModel (com.sri.ai.praise.core.representation.classbased.hogm.HOGModel)3 HOGMParserWrapper (com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper)3 ArrayList (java.util.ArrayList)3 DefaultExpressionBasedProblem (com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedProblem)2 Test (org.junit.Test)2 Type (com.sri.ai.expresso.api.Type)1 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 HOGMModelParsing (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMModelParsing)1 ExpressionBasedProblem (com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedProblem)1 TranslatorOptions (com.sri.ai.praise.core.representation.translation.ciaranframework.api.TranslatorOptions)1 HOGModelGrounding (com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.HOGModelGrounding)1 UAI_to_HOGMv1_Using_Equalities_Translator (com.sri.ai.praise.core.representation.translation.ciaranframework.core.uai.UAI_to_HOGMv1_Using_Equalities_Translator)1 Pair (com.sri.ai.util.base.Pair)1 Rational (com.sri.ai.util.math.Rational)1 BufferedReader (java.io.BufferedReader)1