ExponentialDistribution extends AbstractRealDistribution { public double density(double x) { final double logDensity = logDensity(x); return logDensity == Double.NEGATIVE_INFINITY ? 0 : FastMath.exp(logDensity); } ExponentialDistribution(double mean);  ExponentialDistribution(double mean, double inverseCumAccuracy);  ExponentialDistribution(RandomGenerator rng, double mean);  ExponentialDistribution(RandomGenerator rng,
                                   double mean,
                                   double inverseCumAccuracy); double getMean(); double density(double x); @Override double logDensity(double x); double cumulativeProbability(double x); @Override double inverseCumulativeProbability(double p); @Override double sample(); double getNumericalMean(); double getNumericalVariance(); double getSupportLowerBound(); double getSupportUpperBound(); boolean isSupportLowerBoundInclusive(); boolean isSupportUpperBoundInclusive(); boolean isSupportConnected(); static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY; }
@Test public void testDensity() { ExponentialDistribution d1 = new ExponentialDistribution(1); Assert.assertTrue(Precision.equals(0.0, d1.density(-1e-9), 1)); Assert.assertTrue(Precision.equals(1.0, d1.density(0.0), 1)); Assert.assertTrue(Precision.equals(0.0, d1.density(1000.0), 1)); Assert.assertTrue(Precision.equals(FastMath.exp(-1), d1.density(1.0), 1)); Assert.assertTrue(Precision.equals(FastMath.exp(-2), d1.density(2.0), 1)); ExponentialDistribution d2 = new ExponentialDistribution(3); Assert.assertTrue(Precision.equals(1/3.0, d2.density(0.0), 1)); Assert.assertEquals(0.2388437702, d2.density(1.0), 1e-8); Assert.assertEquals(0.1711390397, d2.density(2.0), 1e-8); }