use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Expressions method makeDefaultCountingFormulaExpressionFromLabelAndSubTrees.
private static Expression makeDefaultCountingFormulaExpressionFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
Expression indexExpressionsKleeneList = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet(ensureListFromKleeneList(indexExpressionsKleeneList));
Expression body = subTreeExpressions.get(1);
Expression result = new DefaultCountingFormula(indexExpressions, body);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Expressions method makeDefaultExistentiallyQuantifiedFormulaFromLabelAndSubTrees.
private static Expression makeDefaultExistentiallyQuantifiedFormulaFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
Expression indexExpressionsKleeneList = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet(ensureListFromKleeneList(indexExpressionsKleeneList));
Expression body = subTreeExpressions.get(1);
Expression result = new DefaultExistentiallyQuantifiedFormula(indexExpressions, body);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class Expressions method makeDefaultIntensionalUniSetFromLabelAndSubTrees.
private static Expression makeDefaultIntensionalUniSetFromLabelAndSubTrees(Object label, Object[] subTreeObjects) {
if (subTreeObjects.length == 1 && subTreeObjects[0] instanceof Collection) {
subTreeObjects = ((Collection) subTreeObjects[0]).toArray();
}
ArrayList<Expression> subTreeExpressions = Util.mapIntoArrayList(subTreeObjects, Expressions::makeFromObject);
if (subTreeExpressions.size() == 1) {
subTreeExpressions = new ArrayList<Expression>(Expressions.ensureListFromKleeneList(subTreeExpressions.get(0)));
}
Expression scopingExpression = subTreeExpressions.get(0);
IndexExpressionsSet indexExpressions = new ExtensionalIndexExpressionsSet((scopingExpression == null || scopingExpression.numberOfArguments() == 0) ? Util.list() : new ArrayList<Expression>(Expressions.ensureListFromKleeneList(scopingExpression.get(0))));
Expression conditioningSyntaxTree = subTreeExpressions.get(2);
Expression condition = conditioningSyntaxTree == null ? Expressions.TRUE : conditioningSyntaxTree.get(0);
Expression result = new DefaultIntensionalUniSet(indexExpressions, subTreeExpressions.get(1), condition);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class ModelGenerator method LVECalculation.
public static Expression LVECalculation(Collection<FactorNode> factorNodes, Expression query, Context context, Theory theory) {
Set<Expression> factorExpressions = new HashSet<>();
for (FactorNode f : factorNodes) {
factorExpressions.add(f.getValue());
}
Expression product = apply(TIMES, factorExpressions);
Set<Expression> freevariables = Expressions.freeVariables(product, context);
freevariables.remove(query);
ArrayList<Expression> varToSumOut = new ArrayList<>();
varToSumOut.addAll(freevariables);
Expression variablesToBeSummedOut = new DefaultExtensionalMultiSet(varToSumOut);
IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(variablesToBeSummedOut, context);
Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
product, // No Condition
makeSymbol(true));
Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
println("Evaluating " + sumOnPhi);
Expression evaluation = theory.evaluate(sumOnPhi, context);
println("Finished evaluating " + sumOnPhi);
Expression result = Bounds.normalizeSingleExpression(evaluation, theory, context);
return result;
}
use of com.sri.ai.expresso.api.IndexExpressionsSet in project aic-expresso by aic-sri-international.
the class ModelGenerator method LVECalculation.
public static Expression LVECalculation(Collection<FactorNode> factorNodes, Expression query, Context context, Theory theory) {
Set<Expression> factorExpressions = new HashSet<>();
for (FactorNode f : factorNodes) {
factorExpressions.add(f.getValue());
}
Expression product = apply(TIMES, factorExpressions);
Set<Expression> freevariables = Expressions.freeVariables(product, context);
freevariables.remove(query);
ArrayList<Expression> varToSumOut = new ArrayList<>();
varToSumOut.addAll(freevariables);
Expression variablesToBeSummedOut = new DefaultExtensionalMultiSet(varToSumOut);
IndexExpressionsSet indices = getIndexExpressionsOfFreeVariablesIn(variablesToBeSummedOut, context);
Expression setOfFactorInstantiations = IntensionalSet.makeMultiSet(indices, // head
product, // No Condition
makeSymbol(true));
Expression sumOnPhi = apply(SUM, setOfFactorInstantiations);
Expression evaluation = theory.evaluate(sumOnPhi, context);
Expression result = Bounds.normalizeSingleExpression(evaluation, theory, context);
return result;
}
Aggregations