Search in sources :

Example 1 with HOGModel

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

the class AbstractHOGMv1_to_Target_Translator method translate.

// END-Translator
// 
@Override
protected void translate(String inputIdentifier, Reader[] inputModelReaders, PrintWriter[] translatedOutputs) throws Exception {
    // 
    // 1. Get the HOGM FactorNetwork Definition and Parse It
    String hogmv1Model = Util.readAll(inputModelReaders[0]);
    HOGMParserWrapper parser = new HOGMParserWrapper();
    HOGModel parsedModel = parser.parseModel(hogmv1Model);
    ExpressionBasedModel factorsAndTypes = new HOGMExpressionBasedModel(parsedModel);
    // Each additional input is treated as an evidence expression
    List<Expression> evidence = new ArrayList<>();
    if (inputModelReaders.length > 1) {
        for (int i = 1; i < inputModelReaders.length; i++) {
            evidence.add(Expressions.parse(Util.readAll(inputModelReaders[i])));
        }
    }
    translate(inputIdentifier, factorsAndTypes, evidence, translatedOutputs);
}
Also used : HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList) HOGMExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel) HOGMParserWrapper(com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper)

Example 2 with HOGModel

use of com.sri.ai.praise.core.representation.classbased.hogm.HOGModel 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 3 with HOGModel

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

the class ParameterEstimationForHOGModel method optimizeWhenModelIsString.

/**
 * Main method to optimize the parameters of the model given the queries and evidences when the model is String based.
 */
public HashMap<Expression, Double> optimizeWhenModelIsString(String modelString, GoalType goalType, double[] startPoint) {
    List<HOGMProblemError> modelErrors = new ArrayList<>();
    HOGModel hogmModel = parseModelStringToHOGMModel(modelString, modelErrors);
    HashMap<Expression, Double> result = optimizeWhenModelIsHOGModel(hogmModel, goalType, startPoint);
    return result;
}
Also used : HOGMProblemError(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) Expression(com.sri.ai.expresso.api.Expression) ArrayList(java.util.ArrayList)

Example 4 with HOGModel

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

the class ExpressionBasedModelExamples method buildModel5.

public static ExpressionBasedModel buildModel5() {
    String modelString = "random earthquake: Boolean;\n" + "random burglary: Boolean;\n" + "random alarm: Boolean;\n" + "constant Alpha: Real;\n" + "constant Beta: Real;\n" + "earthquake 0.01;\n" + "burglary 0.1;\n" + "if earthquake\n" + "then if burglary\n" + "then alarm Alpha\n" + "else alarm Beta\n" + "else if burglary\n" + "then alarm 0.9\n" + "else alarm 0.01;\n";
    List<HOGMProblemError> modelErrors = new ArrayList<>();
    HOGModel hogmModel = parseModelStringToHOGMModel(modelString, modelErrors);
    ExpressionBasedModel expressionBasedModel = parseHOGModelToExpressionBasedModel(hogmModel);
    return expressionBasedModel;
}
Also used : HOGMProblemError(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) DefaultExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel(com.sri.ai.praise.learning.symbolicparameterestimation.util.UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel) ArrayList(java.util.ArrayList)

Example 5 with HOGModel

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

the class ExpressionBasedModelExamples method buildModel3.

public static ExpressionBasedModel buildModel3() {
    String modelString = "random earthquake: Boolean;\n" + "random burglary: Boolean;\n" + "random alarm: Boolean;\n" + "constant Alpha: Real;\n" + "constant Beta: Real;\n" + "earthquake Alpha;\n" + "burglary Beta;\n" + "if earthquake\n" + "then if burglary\n" + "then alarm 0.95\n" + "else alarm 0.6\n" + "else if burglary\n" + "then alarm 0.9\n" + "else alarm 0.01;\n";
    List<HOGMProblemError> modelErrors = new ArrayList<>();
    HOGModel hogmModel = parseModelStringToHOGMModel(modelString, modelErrors);
    ExpressionBasedModel expressionBasedModel = parseHOGModelToExpressionBasedModel(hogmModel);
    return expressionBasedModel;
}
Also used : HOGMProblemError(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) DefaultExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedModel) ExpressionBasedModel(com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel) UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel(com.sri.ai.praise.learning.symbolicparameterestimation.util.UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel) ArrayList(java.util.ArrayList)

Aggregations

HOGModel (com.sri.ai.praise.core.representation.classbased.hogm.HOGModel)14 ArrayList (java.util.ArrayList)9 ExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel)8 HOGMProblemError (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError)6 Expression (com.sri.ai.expresso.api.Expression)5 UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel (com.sri.ai.praise.learning.symbolicparameterestimation.util.UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel)5 HOGMParserWrapper (com.sri.ai.praise.core.representation.classbased.hogm.parsing.HOGMParserWrapper)4 DefaultExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedModel)3 HOGMExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.hogm.components.HOGMExpressionBasedModel)3 Pair (com.sri.ai.util.base.Pair)2 HOGMModelParsing (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMModelParsing)1 ExpressionBasedModelToFeatureBasedModelTranslation (com.sri.ai.praise.core.representation.classbased.featurebased.ExpressionBasedModelToFeatureBasedModelTranslation)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 ParameterEstimationForHOGModel (com.sri.ai.praise.learning.symbolicparameterestimation.ParameterEstimationForHOGModel)1 Rational (com.sri.ai.util.math.Rational)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1