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) || Double.isInfinite(sig) || Double.isNaN(sig)); } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { lowerBound *= 2.0; } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { upperBound *= 2.0; double x = UnivariateSolverUtils.solve(toSolve, lowerBound, upperBound, getSolverAbsoluteAccuracy()); if (!isSupportConnected()) { final double dx = getSolverAbsoluteAccuracy(); if (x - dx >= getSupportLowerBound()) {
/** * {@inheritDoc} * <p/> * The default implementation uses the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> * inversion method. * </a> */ @Override public double sample() { return inverseCumulativeProbability(random.nextDouble()); }
@Override public INDArray sample(long[] shape) { INDArray ret = Nd4j.create(shape); return sample(ret); }
public double value(final double x) { return cumulativeProbability(x) - p; } };
/** * 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 org.apache.commons.math3.exception.NumberIsTooLargeException if {@code x0 > x1}. * <p/> * 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); }
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) || Double.isInfinite(sig) || Double.isNaN(sig)); } else { lowerBound = -1.0; while (cumulativeProbability(lowerBound) >= p) { lowerBound *= 2.0; } else { upperBound = 1.0; while (cumulativeProbability(upperBound) < p) { upperBound *= 2.0; double x = UnivariateSolverUtils.solve(toSolve, lowerBound, upperBound, getSolverAbsoluteAccuracy()); if (!isSupportConnected()) { final double dx = getSolverAbsoluteAccuracy(); if (x - dx >= getSupportLowerBound()) {
@Override public INDArray sample(int[] shape) { INDArray ret = Nd4j.create(shape); return sample(ret); }
public double value(final double x) { return cumulativeProbability(x) - p; } };
/** * {@inheritDoc} * <p/> * The default implementation uses the * <a href="http://en.wikipedia.org/wiki/Inverse_transform_sampling"> * inversion method. * </a> */ @Override public double sample() { return inverseCumulativeProbability(random.nextDouble()); }
/** * {@inheritDoc} * <p/> * The default implementation generates the sample by calling * {@link #sample()} in a loop. */ @Override public double[] sample(long sampleSize) { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } // FIXME: int cast double[] out = new double[(int) sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
/** * 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 org.apache.commons.math3.exception.NumberIsTooLargeException if {@code x0 > x1}. * <p/> * 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); }
@Override public INDArray sample(INDArray target) { Iterator<long[]> idxIter = new NdIndexIterator(target.shape()); //For consistent values irrespective of c vs. fortran ordering long len = target.length(); for (long i = 0; i < len; i++) { target.putScalar(idxIter.next(), sample()); } return target; } }
/** * {@inheritDoc} * <p/> * The default implementation generates the sample by calling * {@link #sample()} in a loop. */ @Override 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; }
@Override public INDArray sample(int[] shape) { INDArray ret = Nd4j.create(shape); Iterator<int[]> idxIter = new NdIndexIterator(shape); //For consistent values irrespective of c vs. fortran ordering int len = ret.length(); for (int i = 0; i < len; i++) { ret.putScalar(idxIter.next(), sample()); } return ret; } }