/* (non-Javadoc)
@see net.finmath.stochastic.RandomVariable#getQuantileExpectation(double, double)
193278
@Override
	public double getQuantileExpectation(double quantileStart, double quantileEnd) {
		return ((RandomVariableDifferentiableAADStochasticNonOptimized) getValues()).getValues().getQuantileExpectation(quantileStart, quantileEnd);
	}
961942
@Override
  public double nextRandom() {
    double val = random.nextDouble();
    if(val < .5) {
      return FastMath.log(2 * val) / rate + location;
    }
    else {
      return -FastMath.log(2. - 2. * val) / rate + location;
    }
  }
969954
public Expression getExpectedParam(int index) {
        if (parameters.size() <= index) {
            throw new IllegalArgumentException("Parameter index out of bounds: " + index + ". Function call: " + this);
        }

        return parameters.get(index);
    }
1145187
private static double getX(Coordinate c) {
		double value = c.getX();
		if (value > 1000000) {
			value = 1000000;
		} else if (value < -1000000) {
			value = -1000000;
		}
		return value;
	}
664776
@Override
	public RandomVariable floor(double floor) {
		return apply(new DoubleUnaryOperator() {
			@Override
			public double applyAsDouble(double x) {
				return Math.max(x, floor);
			}
		});
	}
537002
@SuppressWarnings("unchecked")
  protected T getSpecial(int idx) {
    if(special == null) {
      special = new Object[] { supplier.make(), supplier.make(), supplier.make() };
    }
    return (T) special[idx];
  }
791419
static int getRandomValueFromInterval(
            double randomizationFactor, double random, int currentIntervalMillis) {
        double delta = randomizationFactor * currentIntervalMillis;
        double minInterval = currentIntervalMillis - delta;
        double maxInterval = currentIntervalMillis + delta;
        // Get a random value from the range [minInterval, maxInterval].
        // The formula used below has a +1 because if the minInterval is 1 and the maxInterval is 3 then
        // we want a 33% chance for selecting either 1, 2 or 3.
        int randomValue = (int) (minInterval + (random * (maxInterval - minInterval + 1)));
        return randomValue;
    }
1038485
@SuppressWarnings("all")
    public static synchronized <T> IExpectationSetters<T> expectPrivate(Object instance, String methodName,
                                                                        Class<?>[] parameterTypes, Object... arguments) throws Exception {

        if (arguments == null) {
            arguments = new Object[0];
        }

        if (instance == null) {
            throw new IllegalArgumentException("instance cannot be null.");
        } else if (arguments.length != parameterTypes.length) {
            throw new IllegalArgumentException(
                    "The length of the arguments must be equal to the number of parameter types.");
        }

        Method foundMethod = Whitebox.getMethod(instance.getClass(), methodName, parameterTypes);

        WhiteboxImpl.throwExceptionIfMethodWasNotFound(instance.getClass(), methodName, foundMethod, parameterTypes);

        return doExpectPrivate(instance, foundMethod, arguments);
    }
299963
public static synchronized <T> IExpectationSetters<T> expectPrivate(Class<?> clazz, Method method,
                                                                        Object... arguments) throws Exception {
        return doExpectPrivate(clazz, method, arguments);
    }
847693
@Override
	public double getQuantile(double quantile) {
		if(isDeterministic()) {
			return valueIfNonStochastic;
		}
		if(size() == 0) {
			return Double.NaN;
		}

		double[] realizationsSorted = realizations.clone();
		java.util.Arrays.sort(realizationsSorted);

		int indexOfQuantileValue = Math.min(Math.max((int)Math.round((size()+1) * quantile - 1), 0), size()-1);

		return realizationsSorted[indexOfQuantileValue];
	}
809591
public static double nextDouble()
  {
    Random random = getRandom();

    double value = random.nextDouble();

    if (! _isTest)
      _freeRandomList.free(random);

    return value;
  }
375271
public static DoubleBinding log1p(final ObservableDoubleValue x) {
        return createDoubleBinding(() -> Math.log1p(x.get()), x);
    }
711313
public double get(double x, double epsilon)
    {
        Point nearest = getNearest(x, epsilon);
        return nearest.getY();
    }
665878
@Override
	public double getVariance() {
		if(isDeterministic()) {
			return 0.0;
		}
		if(size() == 0) {
			return Double.NaN;
		}

		double sum			= 0.0;
		double sumOfSquared = 0.0;
		for (double realization : getRealizations()) {
			sum += realization;
			sumOfSquared += realization * realization;
		}
		return sumOfSquared/size() - sum/size() * sum/size();
	}
114419
@Override
	public RandomVariable pow(double exponent) {
		return apply(new DoubleUnaryOperator() {
			@Override
			public double applyAsDouble(double x) {
				return FastMath.pow(x, exponent);
			}
		});
	}
938885
public JBBPOut Double(final double... value) throws IOException {
    assertNotEnded();
    assertArrayNotNull(value);
    if (this.processCommands) {
      for (final double d : value) {
        _writeDouble(d);
      }
    }
    return this;
  }
533437
public static double toDouble(String x) throws NumberFormatException {
        if ("nan".equals(x)) {
            return Double.NaN;
        }
        if ("inf".equals(x)) {
            return Double.POSITIVE_INFINITY;
        }
        if ("-inf".equals(x)) {
            return Double.NEGATIVE_INFINITY;
        }

        return Double.parseDouble(x);
    }