StudentTDistributionMaximumLikelihoodEstimator extends DistributionParameterEstimator<Double> { @Override public ProbabilityDistribution<Double> evaluate(final double[] x) { Validate.notNull(x, "x"); ArgumentChecker.notEmpty(x, "x"); final double[] standardized = getStandardizedData(x); final Function1D<Double, Double> f = new Function1D<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final Double nu) { double sum = 0; for (final double t : standardized) { sum += Math.log(_gamma.evaluate((nu + 1) / 2.) * Math.pow(1 + t * t / (nu - 2), -(nu + 1) / 2.) / Math.sqrt(Math.PI * (nu - 2)) / _gamma.evaluate(nu / 2.)); } return -sum; } }; return new StudentTDistribution(_minimizer.minimize(f, 0.0, 3., 10.)); }  @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(groups = TestGroup.UNIT_SLOW) public void test() { final int n = 500000; final double eps = 5e-2; final double nu = 5.4; final ProbabilityDistribution<Double> p1 = new StudentTDistribution(nu, new MersenneTwister64(MersenneTwister.DEFAULT_SEED)); final double[] x = new double[n]; for (int i = 0; i < n; i++) { x[i] = p1.nextRandom(); } final StudentTDistribution p2 = (StudentTDistribution) ESTIMATOR.evaluate(x); assertEquals(p2.getDegreesOfFreedom(), nu, eps); }