use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable in project aic-praise by aic-sri-international.
the class ProceduralAttachmentExpressionFactor method getVariableType.
private Type getVariableType(Variable variable, Context context) {
myAssert(variable instanceof ExpressionVariable, () -> getClass() + " must be defined for " + ExpressionVariable.class + ", but one of them has been defined for " + proceduralAttachment.getVariable() + " of type " + variable.getClass());
ExpressionVariable expressionVariable = (ExpressionVariable) variable;
myAssert(context.containsSymbol(expressionVariable), () -> "There is a procedural attachment for variable " + expressionVariable + " but it is not registered in the context");
Type type = context.getTypeOfRegisteredSymbol(expressionVariable);
myAssert(type != null, () -> "There is a procedural attachment for variable " + expressionVariable + " but its type is unknown");
return type;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable in project aic-praise by aic-sri-international.
the class ExpressionFactorTest method testSumOut.
@Test
public void testSumOut() {
Context context = new TrueContext(new CommonTheory()).extendWithSymbolsAndTypes("U", "Boolean", "V", "Boolean");
ExpressionVariable u = new DefaultExpressionVariable(parse("U"));
List<ExpressionVariable> variablesToSumOut = new ArrayList<>();
variablesToSumOut.add(u);
ExpressionFactor factorUV = new DefaultExpressionFactor(parse("if U and V then 2 else 3"), context);
Factor summedOutFactor = factorUV.sumOut(variablesToSumOut);
assertEquals("if V then 5 else 6", summedOutFactor.toString());
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable in project aic-praise by aic-sri-international.
the class ExpressionBasedProblemToInterfaceBasedProblemConversion method translate.
public static Problem translate(ExpressionBasedProblem expressionBasedProblem) {
ExpressionVariable queryVariable = new DefaultExpressionVariable(expressionBasedProblem.getQuerySymbol());
ExpressionFactorNetwork factorNetwork = makeFactorNetwork(expressionBasedProblem);
Predicate<Expression> isExpressionParameterPredicate = expressionBasedProblem.getIsParameterPredicate();
Predicate<Variable> isParameterPredicate = makeIsParameterPredicate(isExpressionParameterPredicate);
Problem problem = new DefaultVariableMarginalQuery(queryVariable, factorNetwork, isParameterPredicate);
return problem;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable in project aic-praise by aic-sri-international.
the class ExpressionBayesianModelTest method generateDatasetForChildParentModel.
/**
* Auxiliar function to generate a dataset for the childParent model based on standard datapoints (designed to test all the different subcases for the model)
*
* Order of variables for the datapoints: (Child, Parent)
* @param numberOfDatapoints1 - (1, 2)
* @param numberOfDatapoints2 - (5, 1)
* @param numberOfDatapoints3 - (4, 3)
* @param numberOfDatapoints4 - (1, 5)
* @return the dataset with the specified number of datapoints
*/
private static DefaultDataset generateDatasetForChildParentModel(int numberOfDatapoints1, int numberOfDatapoints2, int numberOfDatapoints3, int numberOfDatapoints4) {
List<ExpressionVariable> variables = list(childVariable, parentVariable);
DefaultDatapoint datapoint1 = new DefaultDatapoint(variables, list(parse("1"), parse("2")));
DefaultDatapoint datapoint2 = new DefaultDatapoint(variables, list(parse("5"), parse("1")));
DefaultDatapoint datapoint3 = new DefaultDatapoint(variables, list(parse("4"), parse("3")));
DefaultDatapoint datapoint4 = new DefaultDatapoint(variables, list(parse("1"), parse("5")));
List<DefaultDatapoint> datapoints = list();
for (int i = 1; i <= numberOfDatapoints1; i++) datapoints.add(datapoint1);
for (int i = 1; i <= numberOfDatapoints2; i++) datapoints.add(datapoint2);
for (int i = 1; i <= numberOfDatapoints3; i++) datapoints.add(datapoint3);
for (int i = 1; i <= numberOfDatapoints4; i++) datapoints.add(datapoint4);
DefaultDataset dataset = new DefaultDataset(datapoints);
return dataset;
}
use of com.sri.ai.praise.core.representation.interfacebased.factor.core.expression.api.ExpressionVariable in project aic-praise by aic-sri-international.
the class ExpressionBayesianModelTest method generateDatasetForEarthquakeBurglaryAlarmModel.
/**
* Auxiliar function to generate a dataset for the Earthquake/Burglary/Alarm model based on some standard datapoints
*
* Order of variables for the datapoints: (Alarm, Earthquake, Burglary)
* @param numberOfDatapoints1 - (1, 0, 1)
* @param numberOfDatapoints2 - (1, 1, 1)
* @return
*/
private static DefaultDataset generateDatasetForEarthquakeBurglaryAlarmModel(int numberOfDatapoints1, int numberOfDatapoints2) {
List<ExpressionVariable> variables = list(alarm, earthquake, burglary);
DefaultDatapoint datapoint1 = new DefaultDatapoint(variables, list(parse("1"), parse("0"), parse("1")));
DefaultDatapoint datapoint2 = new DefaultDatapoint(variables, list(parse("1"), parse("1"), parse("1")));
List<DefaultDatapoint> datapoints = list();
for (int i = 1; i <= numberOfDatapoints1; i++) datapoints.add(datapoint1);
for (int i = 1; i <= numberOfDatapoints2; i++) datapoints.add(datapoint2);
DefaultDataset dataset = new DefaultDataset(datapoints);
return dataset;
}
Aggregations