@Test public void testBetaDistribution() { System.out.println("BetaDistribution"); MathEx.setSeed(19650218); BetaDistribution instance = new BetaDistribution(3, 2.1); double[] data = instance.rand(1000); BetaDistribution est = BetaDistribution.fit(data); assertEquals(3.31, est.getAlpha(), 1E-2); assertEquals(2.31, est.getBeta(), 1E-2); }
public BetaDistribution(double alpha, double beta) { if (alpha <= 0) { throw new IllegalArgumentException("Invalid alpha: " + alpha); } if (beta <= 0) { throw new IllegalArgumentException("Invalid beta: " + beta); } this.alpha = alpha; this.beta = beta; mean = alpha / (alpha + beta); variance = alpha * beta / ((alpha + beta) * (alpha + beta) * (alpha + beta + 1)); entropy = Math.log(Beta.beta(alpha, beta)) - (alpha - 1) * Gamma.digamma(alpha) - (beta - 1) * Gamma.digamma(beta) + (alpha + beta - 2) * Gamma.digamma(alpha + beta); }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { public BetaDistribution(double alpha, double beta) { if (alpha <= 0) { throw new IllegalArgumentException("Invalid alpha: " + alpha); } if (beta <= 0) { throw new IllegalArgumentException("Invalid beta: " + beta); } this.alpha = alpha; this.beta = beta; mean = alpha / (alpha + beta); variance = alpha * beta / ((alpha + beta) * (alpha + beta) * (alpha + beta + 1)); entropy = Math.log(Beta.beta(alpha, beta)) - (alpha - 1) * Gamma.digamma(alpha) - (beta - 1) * Gamma.digamma(beta) + (alpha + beta - 2) * Gamma.digamma(alpha + beta); } }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { public BetaDistribution(double alpha, double beta) { if (alpha <= 0) { throw new IllegalArgumentException("Invalid alpha: " + alpha); } if (beta <= 0) { throw new IllegalArgumentException("Invalid beta: " + beta); } this.alpha = alpha; this.beta = beta; mean = alpha / (alpha + beta); variance = alpha * beta / ((alpha + beta) * (alpha + beta) * (alpha + beta + 1)); entropy = Math.log(Beta.beta(alpha, beta)) - (alpha - 1) * Gamma.digamma(alpha) - (beta - 1) * Gamma.digamma(beta) + (alpha + beta - 2) * Gamma.digamma(alpha + beta); } BetaDistribution(double alpha, double beta); }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { public BetaDistribution(double alpha, double beta) { if (alpha <= 0) { throw new IllegalArgumentException("Invalid alpha: " + alpha); } if (beta <= 0) { throw new IllegalArgumentException("Invalid beta: " + beta); } this.alpha = alpha; this.beta = beta; mean = alpha / (alpha + beta); variance = alpha * beta / ((alpha + beta) * (alpha + beta) * (alpha + beta + 1)); entropy = Math.log(Beta.beta(alpha, beta)) - (alpha - 1) * Gamma.digamma(alpha) - (beta - 1) * Gamma.digamma(beta) + (alpha + beta - 2) * Gamma.digamma(alpha + beta); } BetaDistribution(double alpha, double beta); static BetaDistribution fit(double[] data); double getAlpha(); double getBeta(); @Override int length(); @Override double mean(); @Override double variance(); @Override double entropy(); @Override String toString(); @Override double p(double x); @Override double logp(double x); @Override double cdf(double x); @Override double quantile(double p); @Override Mixture.Component M(double[] x, double[] posteriori); @Override double rand(); }
BetaDistribution extends AbstractDistribution implements ExponentialFamily { public BetaDistribution(double alpha, double beta) { if (alpha <= 0) { throw new IllegalArgumentException("Invalid alpha: " + alpha); } if (beta <= 0) { throw new IllegalArgumentException("Invalid beta: " + beta); } this.alpha = alpha; this.beta = beta; mean = alpha / (alpha + beta); variance = alpha * beta / ((alpha + beta) * (alpha + beta) * (alpha + beta + 1)); entropy = Math.log(Beta.beta(alpha, beta)) - (alpha - 1) * Gamma.digamma(alpha) - (beta - 1) * Gamma.digamma(beta) + (alpha + beta - 2) * Gamma.digamma(alpha + beta); } BetaDistribution(double alpha, double beta); static BetaDistribution fit(double[] data); double getAlpha(); double getBeta(); @Override int length(); @Override double mean(); @Override double variance(); @Override double entropy(); @Override String toString(); @Override double p(double x); @Override double logp(double x); @Override double cdf(double x); @Override double quantile(double p); @Override Mixture.Component M(double[] x, double[] posteriori); @Override double rand(); final double alpha; final double beta; }