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);
    }
@Test
    public void testBetaDistribution() {
        System.out.println("BetaDistribution");
        MathEx.setSeed(19650218); // to get repeatable results.
        BetaDistribution instance = new BetaDistribution(3, 2.1);
        double[] data = instance.rand(1000);
        BetaDistribution est = BetaDistribution.fit(data);
        assertEquals(3.31, est.alpha(), 1E-2);
        assertEquals(2.31, est.beta(), 1E-2);
    }