Search in sources :

Example 1 with HOGMProblemError

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError 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 2 with HOGMProblemError

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError 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 3 with HOGMProblemError

use of com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError 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)

Example 4 with HOGMProblemError

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

the class UtilTest method main.

/**
 * Test if conversion between String model and ExpressionBasedModel is working.
 */
public static void main(String[] args) {
    String modelString = "random earthquake: Boolean;\n" + "random burglary: Boolean;\n" + "random alarm: Boolean;\n" + "earthquake 0.01;\n" + "burglary 0.1;\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 hogModel = parseModelStringToHOGMModel(modelString, modelErrors);
    ExpressionBasedModel expressionBasedModel = parseHOGModelToExpressionBasedModel(hogModel);
    System.out.println(expressionBasedModel.toString() + "\n");
    ExpressionBasedModelToFeatureBasedModelTranslation translation = new ExpressionBasedModelToFeatureBasedModelTranslation(expressionBasedModel, new LinkedList<>());
    System.out.println("translation : " + translation.featureBasedModel.toString());
}
Also used : HOGMProblemError(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) 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) ExpressionBasedModelToFeatureBasedModelTranslation(com.sri.ai.praise.core.representation.classbased.featurebased.ExpressionBasedModelToFeatureBasedModelTranslation)

Example 5 with HOGMProblemError

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

the class ParameterEstimationForHOGModelTest method testHOGMBased.

// TODO: not matching original expected result put in by Sarah
// @Test
public void testHOGMBased() {
    String modelString = "random terrorAttacks : 0..20;\n" + "random newJobs : 0..100000;\n" + "random dow: 11000..18000;\n" + "random economyIsPoor : Boolean;\n" + "random economyIsGreat : Boolean;\n" + "random attackPerception: Boolean;\n" + "random likeIncumbent  : 0..100000000;\n" + "random likeChallenger : 0..100000000;\n" + "constant Alpha: Real;\n" + "economyIsPoor <=> dow < 13000 and newJobs < 30000;\n" + "economyIsGreat <=> dow > 16000 and newJobs > 70000;\n" + "attackPerception <=> terrorAttacks > 4;\n" + "if economyIsGreat\n" + "then if likeIncumbent > 70000000 then Alpha/30000000 else (1-Alpha)/(70000000 + 1)\n" + "else if economyIsPoor\n" + "then if likeIncumbent < 40000000 then 0.8/40000000 else 0.2/(60000000 + 1)\n" + "else if attackPerception\n" + "then if likeIncumbent < 60000000 then 0.9/60000000 else 0.1/(40000000 + 1);\n";
    List<HOGMProblemError> modelErrors = new ArrayList<>();
    List<Pair<Expression, Expression>> pairsQueryEvidence = new LinkedList<Pair<Expression, Expression>>();
    Pair<Expression, Expression> pair = new Pair<Expression, Expression>(parse("likeIncumbent > likeChallenger"), parse("null"));
    pairsQueryEvidence.add(pair);
    ParameterEstimationForHOGModel parameterEstimationForHOGModel = new ParameterEstimationForHOGModel(modelString, pairsQueryEvidence, modelErrors);
    HashMap<Expression, Double> expected = new HashMap<Expression, Double>();
    expected.put(parse("Alpha"), 1.0);
    HashMap<Expression, Double> mapResult = runTestHOGModelBased(expected, parameterEstimationForHOGModel, new double[] { 0 });
    HOGModel test = parameterEstimationForHOGModel.buildOptimizedHOGModel(mapResult);
    ExpressionBasedModel newModel = parseHOGModelToExpressionBasedModel(test);
    System.out.println(newModel.toString());
    assertEquals(expected, mapResult);
}
Also used : ParameterEstimationForHOGModel(com.sri.ai.praise.learning.symbolicparameterestimation.ParameterEstimationForHOGModel) HashMap(java.util.HashMap) 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) LinkedList(java.util.LinkedList) HOGMProblemError(com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError) ParameterEstimationForHOGModel(com.sri.ai.praise.learning.symbolicparameterestimation.ParameterEstimationForHOGModel) HOGModel(com.sri.ai.praise.core.representation.classbased.hogm.HOGModel) Expression(com.sri.ai.expresso.api.Expression) Pair(com.sri.ai.util.base.Pair)

Aggregations

HOGMProblemError (com.sri.ai.praise.core.inference.byinputrepresentation.classbased.hogm.parsing.HOGMProblemError)8 ArrayList (java.util.ArrayList)7 HOGModel (com.sri.ai.praise.core.representation.classbased.hogm.HOGModel)6 ExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.expressionbased.api.ExpressionBasedModel)5 UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel (com.sri.ai.praise.learning.symbolicparameterestimation.util.UsefulOperationsParameterEstimation.parseHOGModelToExpressionBasedModel)5 Expression (com.sri.ai.expresso.api.Expression)3 DefaultExpressionBasedModel (com.sri.ai.praise.core.representation.classbased.expressionbased.core.DefaultExpressionBasedModel)3 ParameterEstimationForHOGModel (com.sri.ai.praise.learning.symbolicparameterestimation.ParameterEstimationForHOGModel)2 Pair (com.sri.ai.util.base.Pair)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ExpressionBasedModelToFeatureBasedModelTranslation (com.sri.ai.praise.core.representation.classbased.featurebased.ExpressionBasedModelToFeatureBasedModelTranslation)1 HOGMCodeArea (com.sri.ai.praise.other.application.praise.app.editor.HOGMCodeArea)1 Node (javafx.scene.Node)1 ListView (javafx.scene.control.ListView)1 Tab (javafx.scene.control.Tab)1 TabPane (javafx.scene.control.TabPane)1 TitledPane (javafx.scene.control.TitledPane)1 Test (org.junit.Test)1