List of usage examples for org.apache.commons.math3.distribution GammaDistribution GammaDistribution
public GammaDistribution(double shape, double scale, double inverseCumAccuracy) throws NotStrictlyPositiveException
From source file:math.test.TestDimpleRandom.java
/** * Measures speed of Apache vs Colt generators *///from w w w.j a va 2 s. c om public static void main(String[] args) { RandomGenerator apacheGenerator = new MersenneTwister(42); cern.jet.random.engine.RandomEngine cernGenerator = new cern.jet.random.engine.MersenneTwister(); final int N = 100000; long start, end; start = System.nanoTime(); for (int i = N; --i >= 0;) { apacheGenerator.nextDouble(); } end = System.nanoTime(); long apacheTime = end - start; start = System.nanoTime(); for (int i = N; --i >= 0;) { cernGenerator.nextDouble(); } end = System.nanoTime(); long cernTime = end - start; System.out.format("MersenneTwister.nextDouble() x %d apache/cern %f\n", N, (double) apacheTime / cernTime); start = System.nanoTime(); for (int i = N; --i >= 0;) { BetaDistribution apacheBeta = new BetaDistribution(apacheGenerator, 1.0, 1.0); apacheBeta.sample(); } end = System.nanoTime(); apacheTime = end - start; cern.jet.random.Beta cernBeta = new cern.jet.random.Beta(1, 1, cernGenerator); start = System.nanoTime(); for (int i = N; --i >= 0;) { cernBeta.nextDouble(); } end = System.nanoTime(); apacheTime = end - start; System.out.format("Beta x %d apache/cern %f\n", N, (double) apacheTime / cernTime); start = System.nanoTime(); for (int i = N; --i >= 0;) { GammaDistribution apacheGamma = new GammaDistribution(apacheGenerator, 1.0, 1.0); apacheGamma.sample(); } end = System.nanoTime(); apacheTime = end - start; cern.jet.random.Gamma cernGamma = new cern.jet.random.Gamma(1, 1, cernGenerator); start = System.nanoTime(); for (int i = N; --i >= 0;) { cernGamma.nextDouble(); } end = System.nanoTime(); apacheTime = end - start; System.out.format("Gamma x %d apache/cern %f\n", N, (double) apacheTime / cernTime); start = System.nanoTime(); for (int i = N; --i >= 0;) { BinomialDistribution apacheBinomial = new BinomialDistribution(apacheGenerator, 1, .5); apacheBinomial.sample(); } end = System.nanoTime(); apacheTime = end - start; cern.jet.random.Binomial cernBinomial = new cern.jet.random.Binomial(1, .5, cernGenerator); start = System.nanoTime(); for (int i = N; --i >= 0;) { cernBinomial.nextInt(); } end = System.nanoTime(); apacheTime = end - start; System.out.format("Binomial x %d apache/cern %f\n", N, (double) apacheTime / cernTime); }
From source file:adams.data.distribution.Gamma.java
/** * Returns the configured distribution.//ww w .j a va 2 s . com * * @return the distribution */ @Override public RealDistribution getRealDistribution() { return new GammaDistribution(m_Shape, m_Scale, m_InverseCumAccuracy); }
From source file:edu.cmu.tetrad.util.RandomUtil.java
/** * Returns the next random number drawn from the Gamma distribution with the given alpha and lambda. * * @param shape The shape parameter./* w ww.j a va 2s. c o m*/ * @param scale The scale parameter. * @return Ibid. */ public double nextGamma(double shape, double scale) { return new GammaDistribution(randomGenerator, shape, scale).sample(); }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getGamma(final RandomNumberStream rng, final Number shape, final Number scale) { final RealDistribution dist = new GammaDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), shape.doubleValue(), scale.doubleValue()); return new RandomNumberDistribution<Double>() { @Override// w w w . j a va 2 s. com public Double draw() { return dist.sample(); } }; }