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;
}
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;
}
Aggregations