@Override public int sample() { double randomVal = realDist.sample(); long longVal = Math.round(randomVal); return (int) longVal; } }
double lowerBound = getSupportLowerBound(); if (p == 0.0) { return lowerBound; double upperBound = getSupportUpperBound(); if (p == 1.0) { return upperBound; final double mu = getNumericalMean(); final double sig = FastMath.sqrt(getNumericalVariance()); final boolean chebyshevApplies; chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { lowerBound *= 2.0; } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { upperBound *= 2.0; lowerBound, upperBound, getSolverAbsoluteAccuracy()); if (!isSupportConnected()) {
/** * {@inheritDoc} * * The default implementation uses the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> * inversion method. * </a> */ public double sample() { return inverseCumulativeProbability(random.nextDouble()); }
/** {@inheritDoc} */ public double value(final double x) { return cumulativeProbability(x) - p; } };
/** * {@inheritDoc} * * The default implementation uses the identity * <p>{@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}</p> * * @deprecated As of 3.1 (to be removed in 4.0). Please use * {@link #probability(double,double)} instead. */ @Deprecated public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException { return probability(x0, x1); }
/** * Returns the natural logarithm of the probability density function (PDF) of this distribution * evaluated at the specified point {@code x}. In general, the PDF is the derivative of the * {@link #cumulativeProbability(double) CDF}. If the derivative does not exist at {@code x}, * then an appropriate replacement should be returned, e.g. {@code Double.POSITIVE_INFINITY}, * {@code Double.NaN}, or the limit inferior or limit superior of the difference quotient. Note * that due to the floating point precision and under/overflow issues, this method will for some * distributions be more precise and faster than computing the logarithm of * {@link #density(double)}. The default implementation simply computes the logarithm of * {@code density(x)}. * * @param x the point at which the PDF is evaluated * @return the logarithm of the value of the probability density function at point {@code x} */ public double logDensity(double x) { return FastMath.log(density(x)); } }
/** * For a random variable {@code X} whose values are distributed according * to this distribution, this method returns {@code P(x0 < X <= x1)}. * * @param x0 Lower bound (excluded). * @param x1 Upper bound (included). * @return the probability that a random variable with this distribution * takes a value between {@code x0} and {@code x1}, excluding the lower * and including the upper endpoint. * @throws NumberIsTooLargeException if {@code x0 > x1}. * * The default implementation uses the identity * {@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)} * * @since 3.1 */ public double probability(double x0, double x1) { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } return cumulativeProbability(x1) - cumulativeProbability(x0); }
/** {@inheritDoc} */ @Override public double probability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } if (x0 <= 0 || x1 <= 0) { return super.probability(x0, x1); } final double denom = shape * SQRT2; final double v0 = (FastMath.log(x0) - scale) / denom; final double v1 = (FastMath.log(x1) - scale) / denom; return 0.5 * Erf.erf(v0, v1); }
/** * Returns the natural logarithm of the probability density function (PDF) of this distribution * evaluated at the specified point {@code x}. In general, the PDF is the derivative of the * {@link #cumulativeProbability(double) CDF}. If the derivative does not exist at {@code x}, * then an appropriate replacement should be returned, e.g. {@code Double.POSITIVE_INFINITY}, * {@code Double.NaN}, or the limit inferior or limit superior of the difference quotient. Note * that due to the floating point precision and under/overflow issues, this method will for some * distributions be more precise and faster than computing the logarithm of * {@link #density(double)}. The default implementation simply computes the logarithm of * {@code density(x)}. * * @param x the point at which the PDF is evaluated * @return the logarithm of the value of the probability density function at point {@code x} */ public double logDensity(double x) { return Math.log(density(x)); } }
double lowerBound = getSupportLowerBound(); if (p == 0.0) { return lowerBound; double upperBound = getSupportUpperBound(); if (p == 1.0) { return upperBound; final double mu = getNumericalMean(); final double sig = Math.sqrt(getNumericalVariance()); final boolean chebyshevApplies; chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { lowerBound *= 2.0; } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { upperBound *= 2.0; lowerBound, upperBound, getSolverAbsoluteAccuracy()); if (!isSupportConnected()) {
/** * {@inheritDoc} * * The default implementation generates the sample by calling * {@link #sample()} in a loop. */ public double[] sample(int sampleSize) { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } double[] out = new double[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
/** {@inheritDoc} */ public double value(final double x) { return cumulativeProbability(x) - p; } };
/** * {@inheritDoc} * * The default implementation uses the identity * <p>{@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}</p> * * @deprecated As of 3.1 (to be removed in 4.0). Please use * {@link #probability(double,double)} instead. */ @Deprecated public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException { return probability(x0, x1); }
@Override public long inverseCumProb(double cumProb) { return bound(min, max, delegate.inverseCumulativeProbability(cumProb)); }
/** * Returns the natural logarithm of the probability density function (PDF) of this distribution * evaluated at the specified point {@code x}. In general, the PDF is the derivative of the * {@link #cumulativeProbability(double) CDF}. If the derivative does not exist at {@code x}, * then an appropriate replacement should be returned, e.g. {@code Double.POSITIVE_INFINITY}, * {@code Double.NaN}, or the limit inferior or limit superior of the difference quotient. Note * that due to the floating point precision and under/overflow issues, this method will for some * distributions be more precise and faster than computing the logarithm of * {@link #density(double)}. The default implementation simply computes the logarithm of * {@code density(x)}. * * @param x the point at which the PDF is evaluated * @return the logarithm of the value of the probability density function at point {@code x} */ public double logDensity(double x) { return FastMath.log(density(x)); } }
double lowerBound = getSupportLowerBound(); if (p == 0.0) { return lowerBound; double upperBound = getSupportUpperBound(); if (p == 1.0) { return upperBound; final double mu = getNumericalMean(); final double sig = FastMath.sqrt(getNumericalVariance()); final boolean chebyshevApplies; chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) || } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { lowerBound *= 2.0; } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { upperBound *= 2.0; lowerBound, upperBound, getSolverAbsoluteAccuracy()); if (!isSupportConnected()) {
private Object generateSingleRowValue() { Object ret = null; ValueType type = schema.getType(); if (distribution instanceof AbstractIntegerDistribution) { ret = ((AbstractIntegerDistribution) distribution).sample(); } else if (distribution instanceof AbstractRealDistribution) { ret = ((AbstractRealDistribution) distribution).sample(); } else if (distribution instanceof EnumeratedDistribution) { ret = ((EnumeratedDistribution) distribution).sample(); } ret = convertType(ret, type); return ret; }
/** {@inheritDoc} */ public double value(final double x) { return cumulativeProbability(x) - p; } };
/** * {@inheritDoc} * * The default implementation uses the identity * <p>{@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}</p> * * @deprecated As of 3.1 (to be removed in 4.0). Please use * {@link #probability(double,double)} instead. */ @Deprecated public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException { return probability(x0, x1); }
@Override public long inverseCumProb(double cumProb) { return offset(min, delta, delegate.inverseCumulativeProbability(cumProb)); }