Search in sources :

Example 71 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class RealInterval method sampleUniquelyNamedConstant.

@Override
public Expression sampleUniquelyNamedConstant(Random random) {
    myAssert(() -> boundsAreConstants(), () -> "Cannot sample uniquely named constant from real interval that is infinite and/or defined by variables: " + getName());
    // We split the interval into NUMBER_OF_SAMPLING_POINTS contiguous sub-intervals, delimited by (NUMBER_OF_SAMPLING_POINTS + 1) points.
    // We then pick one of these points, but exclude the extreme ones depending on whether bounds are open or closed.
    int sampledPoint = (lowerBoundIsOpen ? 1 : 0) + random.nextInt(getNumberOfAllowedSamplingPoints());
    // We compute the sampled element of the interval
    Rational intervalFraction = new Rational(sampledPoint, SAMPLING_RESOLUTION);
    Rational sampledElement = lowerBound.rationalValue().add(intervalFraction.multiply(getLength()));
    Symbol result = makeSymbol(sampledElement);
    return result;
}
Also used : Rational(com.sri.ai.util.math.Rational) Symbol(com.sri.ai.expresso.api.Symbol) Expressions.makeSymbol(com.sri.ai.expresso.helper.Expressions.makeSymbol)

Example 72 with Rational

use of com.sri.ai.util.math.Rational in project aic-expresso by aic-sri-international.

the class InversionPerformanceEvaluationTest method computeSize.

private Rational computeSize(Expression functionOnIntensionalSet) {
    Rational result = new Rational(1);
    result = computeSize(functionOnIntensionalSet, result, context);
    return result;
}
Also used : Rational(com.sri.ai.util.math.Rational)

Aggregations

Rational (com.sri.ai.util.math.Rational)72 Expression (com.sri.ai.expresso.api.Expression)33 Test (org.junit.Test)26 Monomial (com.sri.ai.grinder.polynomial.api.Monomial)11 ArrayList (java.util.ArrayList)10 Type (com.sri.ai.expresso.api.Type)9 IntensionalSet (com.sri.ai.expresso.api.IntensionalSet)8 IndexExpressionsSet (com.sri.ai.expresso.api.IndexExpressionsSet)7 RealExpressoType (com.sri.ai.expresso.type.RealExpressoType)6 RealInterval (com.sri.ai.expresso.type.RealInterval)6 List (java.util.List)6 ExtensionalIndexExpressionsSet (com.sri.ai.expresso.core.ExtensionalIndexExpressionsSet)5 Symbol (com.sri.ai.expresso.api.Symbol)4 Expressions.makeSymbol (com.sri.ai.expresso.helper.Expressions.makeSymbol)4 Categorical (com.sri.ai.expresso.type.Categorical)4 FunctionType (com.sri.ai.expresso.type.FunctionType)4 TupleType (com.sri.ai.expresso.type.TupleType)4 Polynomial (com.sri.ai.grinder.polynomial.api.Polynomial)4 LambdaExpression (com.sri.ai.expresso.api.LambdaExpression)3 HashMap (java.util.HashMap)3