@Test public void testBernoulliDistribution() { System.out.println("BernoulliDistribution"); MathEx.setSeed(19650218); BernoulliDistribution instance = new BernoulliDistribution(0.4); int[] data = instance.randi(1000); BernoulliDistribution est = BernoulliDistribution.fit(data); assertEquals(0.4, est.p, 1E-2); }
public BernoulliDistribution(double p) { if (p < 0 || p > 1) { throw new IllegalArgumentException("Invalid p: " + p); } this.p = p; q = 1 - p; entropy = -p * MathEx.log2(p) - q * MathEx.log2(q); }
BernoulliDistribution extends DiscreteDistribution { public BernoulliDistribution(double p) { if (p < 0 || p > 1) { throw new IllegalArgumentException("Invalid p: " + p); } this.p = p; q = 1 - p; entropy = -p * MathEx.log2(p) - q * MathEx.log2(q); } }
BernoulliDistribution extends DiscreteDistribution { public BernoulliDistribution(double p) { if (p < 0 || p > 1) { throw new IllegalArgumentException("Invalid p: " + p); } this.p = p; q = 1 - p; entropy = -p * MathEx.log2(p) - q * MathEx.log2(q); } BernoulliDistribution(double p);  BernoulliDistribution(boolean[] data); }
BernoulliDistribution extends DiscreteDistribution { public BernoulliDistribution(double p) { if (p < 0 || p > 1) { throw new IllegalArgumentException("Invalid p: " + p); } this.p = p; q = 1 - p; entropy = -p * MathEx.log2(p) - q * MathEx.log2(q); } BernoulliDistribution(double p);  BernoulliDistribution(boolean[] data); static BernoulliDistribution fit(int[] data); @Override int length(); @Override double mean(); @Override double variance(); @Override double entropy(); @Override String toString(); @Override double rand(); @Override double p(int k); @Override double logp(int k); @Override double cdf(double k); @Override double quantile(double p); }
BernoulliDistribution extends DiscreteDistribution { public BernoulliDistribution(double p) { if (p < 0 || p > 1) { throw new IllegalArgumentException("Invalid p: " + p); } this.p = p; q = 1 - p; entropy = -p * MathEx.log2(p) - q * MathEx.log2(q); } BernoulliDistribution(double p);  BernoulliDistribution(boolean[] data); static BernoulliDistribution fit(int[] data); @Override int length(); @Override double mean(); @Override double variance(); @Override double entropy(); @Override String toString(); @Override double rand(); @Override double p(int k); @Override double logp(int k); @Override double cdf(double k); @Override double quantile(double p); final double p; final double q; }