Search in sources :

Example 1 with NullaryFunction

use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.

the class AssignmentsIterator method makeMapFromVariablesToIteratorMakersFrom.

private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakersFrom(IndexExpressionsSet indexExpressionsSet, Registry registry) {
    Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
    ExtensionalIndexExpressionsSet extensionalIndexExpressionsSet;
    try {
        extensionalIndexExpressionsSet = (ExtensionalIndexExpressionsSet) indexExpressionsSet;
    } catch (ClassCastException e) {
        throw new Error("AssignmentsIterator defined for extensional index expressions sets only.");
    }
    for (Expression indexExpression : extensionalIndexExpressionsSet.getList()) {
        Expression variable = IndexExpressions.getIndex(indexExpression);
        Expression typeDescription = IndexExpressions.getType(indexExpression);
        if (typeDescription == null) {
            typeDescription = GrinderUtil.getTypeExpression(variable, registry);
        }
        putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
    }
    return fromVariableToIteratorMaker;
}
Also used : ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) Expression(com.sri.ai.expresso.api.Expression) NullaryFunction(com.sri.ai.util.base.NullaryFunction)

Example 2 with NullaryFunction

use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.

the class Bounds method boundProduct.

/**
	 * Computes the product of each term of a list of bounds
	 * @param theory
	 * @param context
	 * @param listOfBounds
	 * @return bound resulting from the product of bounds
	 */
public static Expression boundProduct(Theory theory, Context context, Expression... listOfBounds) {
    ArrayList<NullaryFunction<Iterator<Expression>>> iteratorForBoundList = mapIntoArrayList(listOfBounds, bound -> () -> getElements(bound).iterator());
    Iterator<ArrayList<Expression>> cartesianProduct = new CartesianProductIterator<Expression>(iteratorForBoundList);
    ArrayList<Expression> resultList = new ArrayList<>();
    for (ArrayList<Expression> element : in(cartesianProduct)) {
        Expression product = apply("*", element);
        Expression evaluation = theory.evaluate(product, context);
        resultList.add(evaluation);
    }
    Expression result = new DefaultExtensionalUniSet(resultList);
    // Updating extreme points
    result = updateExtremes(result, theory, context);
    return result;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) NullaryFunction(com.sri.ai.util.base.NullaryFunction) CartesianProductIterator(com.sri.ai.util.collect.CartesianProductIterator) Util.mapIntoArrayList(com.sri.ai.util.Util.mapIntoArrayList) ArrayList(java.util.ArrayList) DefaultExtensionalUniSet(com.sri.ai.expresso.core.DefaultExtensionalUniSet)

Example 3 with NullaryFunction

use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.

the class AssignmentMapsIterator method makeMapFromVariablesToIteratorMakers.

private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakers(Collection<Expression> variables, Registry registry) {
    Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
    for (Expression variable : variables) {
        Expression typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
        putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
    }
    return fromVariableToIteratorMaker;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) NullaryFunction(com.sri.ai.util.base.NullaryFunction)

Example 4 with NullaryFunction

use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.

the class AssignmentMapsIterator method makeMapFromVariablesToIteratorMakers.

private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakers(Collection<? extends Expression> variables, Registry registry) {
    Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
    for (Expression variable : variables) {
        Expression typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
        putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
    }
    return fromVariableToIteratorMaker;
}
Also used : Expression(com.sri.ai.expresso.api.Expression) NullaryFunction(com.sri.ai.util.base.NullaryFunction)

Example 5 with NullaryFunction

use of com.sri.ai.util.base.NullaryFunction in project aic-expresso by aic-sri-international.

the class AssignmentMapsIterator method makeMapFromVariablesToIteratorMakersFrom.

private static Map<Expression, NullaryFunction<Iterator<Expression>>> makeMapFromVariablesToIteratorMakersFrom(IndexExpressionsSet indexExpressionsSet, Registry registry) {
    Map<Expression, NullaryFunction<Iterator<Expression>>> fromVariableToIteratorMaker = map();
    ExtensionalIndexExpressionsSet extensionalIndexExpressionsSet;
    try {
        extensionalIndexExpressionsSet = (ExtensionalIndexExpressionsSet) indexExpressionsSet;
    } catch (ClassCastException e) {
        throw new Error("AssignmentsIterator defined for extensional index expressions sets only.");
    }
    for (Expression indexExpression : extensionalIndexExpressionsSet.getList()) {
        Expression variable = IndexExpressions.getIndex(indexExpression);
        Expression typeDescription = IndexExpressions.getType(indexExpression);
        if (typeDescription == null) {
            typeDescription = GrinderUtil.getTypeExpressionOfExpression(variable, registry);
        }
        putVariableAndIteratorMakerIn(fromVariableToIteratorMaker, variable, typeDescription, registry);
    }
    return fromVariableToIteratorMaker;
}
Also used : ExtensionalIndexExpressionsSet(com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet) Expression(com.sri.ai.expresso.api.Expression) NullaryFunction(com.sri.ai.util.base.NullaryFunction)

Aggregations

NullaryFunction (com.sri.ai.util.base.NullaryFunction)19 Expression (com.sri.ai.expresso.api.Expression)18 Util.in (com.sri.ai.util.Util.in)12 Util.list (com.sri.ai.util.Util.list)12 Collection (java.util.Collection)12 Beta (com.google.common.annotations.Beta)11 QuantifiedExpression (com.sri.ai.expresso.api.QuantifiedExpression)11 Type (com.sri.ai.expresso.api.Type)11 TRUE (com.sri.ai.expresso.helper.Expressions.TRUE)11 ZERO (com.sri.ai.expresso.helper.Expressions.ZERO)11 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)11 Expressions.parse (com.sri.ai.expresso.helper.Expressions.parse)11 SubExpressionsDepthFirstIterator (com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator)11 GrinderUtil (com.sri.ai.grinder.helper.GrinderUtil)11 Util (com.sri.ai.util.Util)11 Util.join (com.sri.ai.util.Util.join)11 Util.pickKElementsWithoutReplacement (com.sri.ai.util.Util.pickKElementsWithoutReplacement)11 Util.removeFromSetNonDestructively (com.sri.ai.util.Util.removeFromSetNonDestructively)11 BinaryFunction (com.sri.ai.util.base.BinaryFunction)11 LinkedHashSet (java.util.LinkedHashSet)11