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);
}
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);
}
}
}
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;
}
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;
}
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;
}
Aggregations