List of usage examples for org.apache.commons.math3.distribution BetaDistribution BetaDistribution
public BetaDistribution(double alpha, double beta, double inverseCumAccuracy)
From source file:math.test.TestDimpleRandom.java
/** * Measures speed of Apache vs Colt generators *//*from w w w . java 2s . co m*/ 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:com.analog.lyric.math.DimpleRandom.java
/** * Construct using specified underlying random generator and seed. * <p>//w w w .j a v a 2s. com * @since 0.08 */ public DimpleRandom(RandomGenerator randomGenerator, long seed) { super(randomGenerator); _randGenerator = randomGenerator; _seed = seed; _randEngine = new cern.jet.random.engine.MersenneTwister((int) seed); _randGamma = new cern.jet.random.Gamma(1, 1, _randEngine); _randBeta = new BetaDistribution(_randGenerator, 1, 1); _randBinomial = new BinomialDistribution(_randGenerator, 1, 0.5); }
From source file:adams.data.distribution.Beta.java
/** * Returns the configured distribution./*from ww w.ja v a 2s . c o m*/ * * @return the distribution */ @Override public RealDistribution getRealDistribution() { return new BetaDistribution(m_Alpha, m_Beta, m_InverseCumAccuracy); }
From source file:fr.amap.lidar.amapvox.commons.LeafAngleDistribution.java
private void setupBetaDistribution(double param1, double param2) { /*double alphamean = Math.toRadians(param1); double tvar = param2;/*from www. j a v a2 s . c om*/ double tmean = 2 * (alphamean / Math.PI); double sigma0 = tmean * (1 - tmean); double v = tmean * ((sigma0 / tvar) - 1); double m = (1 - tmean) * ((sigma0 / tvar) - 1); distribution = new BetaDistribution(null, m, v);*/ distribution = new BetaDistribution(null, param1, param2); }
From source file:com.analog.lyric.math.DimpleRandom.java
/** * Returns sample from beta distribution with specified alpha and beta parameters. * @since 0.08//from w ww . j av a2 s. c om */ public double nextBeta(double alpha, double beta) { BetaDistribution randBeta = _randBeta; if (randBeta.getAlpha() != alpha || randBeta.getBeta() != beta) { randBeta = new BetaDistribution(_randGenerator, alpha, beta); _randBeta = randBeta; } return randBeta.sample(); }
From source file:edu.byu.nlp.crowdsourcing.AnnotatorAccuracySetting.java
public void generateConfusionMatrices(RandomGenerator rnd, boolean varyAnnotatorRates, int numLabels, String filename) {//from w ww . j ava 2 s . co m if (confusionMatrices == null) { switch (this) { // read annotator confusion matrices from file case FILE: try { List<SimulatedAnnotator> annotators = SimulatedAnnotators .deserialize(Files2.toString(filename, Charsets.UTF_8)); annotatorRates = SimulatedAnnotators.annotationRatesOf(annotators); confusionMatrices = SimulatedAnnotators.confusionsOf(annotators); } catch (IOException e) { throw new IllegalArgumentException("could not parse annotator file: " + filename); } // ensure that the simulated annotators we are reading in have the same number of classes as the dataset we are labeling Preconditions.checkState(confusionMatrices[0].length == numLabels, "mismatch between the number of label classes " + "in the simulated annotator file " + confusionMatrices[0].length + " and the number in the dataset " + numLabels); break; // annotators are drawn from independent dirichlets case INDEPENDENT: annotatorRates = uniformAnnotatorRates(accuracies.length); confusionMatrices = new double[accuracies.length][numLabels][numLabels]; // a matrix where all rows are sampled from a dirichlet for (int a = 0; a < accuracies.length; a++) { for (int i = 0; i < numLabels; i++) { confusionMatrices[a][i] = DirichletDistribution.sampleSymmetric(symmetricDirichletParam, numLabels, rnd); } } break; // annotator accuracies drawn from Beta(shape1,shape2) parameters MLE-fit to CFGroups data case CFBETA: annotatorRates = uniformAnnotatorRates(accuracies.length); BetaDistribution accGen = new BetaDistribution(rnd, 3.6, 5.1); accuracies = accGen.sample(accuracies.length); // sample accuracies logger.info("sampled " + accuracies.length + " simulated annotator accuracies from a Beta(3.6,5.1). min=" + DoubleArrays.min(accuracies) + " max=" + DoubleArrays.max(accuracies) + " mean=" + DoubleArrays.mean(accuracies)); confusionMatrices = confusionMatricesFromAccuracyAndDirichlet(accuracies, numLabels, symmetricDirichletParam, rnd); break; // predetermined annotator accuracies default: annotatorRates = uniformAnnotatorRates(accuracies.length); confusionMatrices = confusionMatricesFromAccuracyAndDirichlet(accuracies, numLabels, symmetricDirichletParam, rnd); break; } if (varyAnnotatorRates && this != FILE) { throw new IllegalStateException( "Varying annotator rates are ONLY implemented for FILE annotators. Not " + this); } // force uniform annotator rates if (!varyAnnotatorRates) { annotatorRates = uniformAnnotatorRates(confusionMatrices.length); } } }
From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java
@Override public RandomNumberDistribution<Double> getBeta(final RandomNumberStream rng, final Number alpha, final Number beta) { final RealDistribution dist = new BetaDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng), alpha.doubleValue(), beta.doubleValue()); return new RandomNumberDistribution<Double>() { @Override//from ww w . j a v a 2 s .c om public Double draw() { return dist.sample(); } }; }