LaplaceDistributionMaximumLikelihoodEstimator extends DistributionParameterEstimator<Double> { @Override public ProbabilityDistribution<Double> evaluate(final double[] x) { Validate.notNull(x, "x"); ArgumentChecker.notEmpty(x, "x"); final double median = _median.evaluate(x); final int n = x.length; double b = 0; for (int i = 0; i < n; i++) { b += Math.abs(x[i] - median); } return new LaplaceDistribution(median, b / n); }  @Override ProbabilityDistribution<Double> evaluate(final double[] x);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNull() { ESTIMATOR.evaluate((double[]) null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmpty() { ESTIMATOR.evaluate(new double[0]); }
@Test public void test() { final double mu = 0.367; final double b = 1.4; final ProbabilityDistribution<Double> distribution = new LaplaceDistribution(mu, b, new MersenneTwister64(MersenneTwister.DEFAULT_SEED)); final int n = 500000; final double[] x = new double[n]; for (int i = 0; i < n; i++) { x[i] = distribution.nextRandom(); } final LaplaceDistribution result = (LaplaceDistribution) ESTIMATOR.evaluate(x); final double eps = 1e-2; assertEquals(1, result.getB() / b, eps); assertEquals(1, result.getMu() / mu, eps); }