List of usage examples for org.apache.commons.math.distribution PoissonDistributionImpl PoissonDistributionImpl
public PoissonDistributionImpl(double p)
From source file:geogebra.kernel.statistics.AlgoDistribution.java
PoissonDistribution getPoissonDistribution(double param) { if (poisson == null) poisson = new PoissonDistributionImpl(param); else {/*from w w w . j a v a2 s. c om*/ poisson.setMean(param); } return poisson; }
From source file:geogebra.common.kernel.statistics.AlgoDistribution.java
/** * @param param//from www . j a v a 2 s. c om * mean * @return Poisson distribution */ protected PoissonDistribution getPoissonDistribution(double param) { if (poisson == null || poisson.getMean() != param) poisson = new PoissonDistributionImpl(param); return poisson; }
From source file:geogebra.common.kernel.algos.AlgoBarChart.java
/** * Prepares list1 and list2 for use with probability distribution bar charts *///from www . j av a 2 s . c o m private boolean prepareDistributionLists() { IntegerDistribution dist = null; int first = 0, last = 0; try { // get the distribution and the first, last list values for given // distribution type switch (type) { case TYPE_BARCHART_BINOMIAL: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; int n = (int) Math.round(p1.getDouble()); double p = p2.getDouble(); dist = new BinomialDistributionImpl(n, p); first = 0; last = n; break; case TYPE_BARCHART_PASCAL: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; n = (int) Math.round(p1.getDouble()); p = p2.getDouble(); dist = new PascalDistributionImpl(n, p); first = 0; last = (int) Math.max(1, (kernel).getXmax() + 1); break; case TYPE_BARCHART_ZIPF: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; n = (int) Math.round(p1.getDouble()); p = p2.getDouble(); dist = new ZipfDistributionImpl(n, p); first = 0; last = n; break; case TYPE_BARCHART_POISSON: if (!p1geo.isDefined()) return false; double lambda = p1.getDouble(); dist = new PoissonDistributionImpl(lambda); first = 0; last = (int) Math.max(1, kernel.getXmax() + 1); break; case TYPE_BARCHART_HYPERGEOMETRIC: if (!(p1geo.isDefined() && p2geo.isDefined() && p3geo.isDefined())) return false; int pop = (int) p1.getDouble(); int successes = (int) p2.getDouble(); int sample = (int) p3.getDouble(); dist = new HypergeometricDistributionImpl(pop, successes, sample); first = Math.max(0, successes + sample - pop); last = Math.min(successes, sample); break; } // load class list and probability list loadDistributionLists(first, last, dist); } catch (Exception e) { App.debug(e.getMessage()); return false; } return true; }
From source file:geogebra.kernel.AlgoFunctionAreaSums.java
/** * Prepares list1 and list2 for use with probability distribution bar charts *//*from w w w . j av a2 s . c o m*/ private boolean prepareDistributionLists() { IntegerDistribution dist = null; int first = 0, last = 0; try { // get the distribution and the first, last list values for given distribution type switch (type) { case TYPE_BARCHART_BINOMIAL: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; int n = (int) Math.round(p1.getDouble()); double p = p2.getDouble(); dist = new BinomialDistributionImpl(n, p); first = 0; last = n; break; case TYPE_BARCHART_PASCAL: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; n = (int) Math.round(p1.getDouble()); p = p2.getDouble(); dist = new PascalDistributionImpl(n, p); first = 0; last = (int) Math.max(1, kernel.getXmax() + 1); break; case TYPE_BARCHART_ZIPF: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; n = (int) Math.round(p1.getDouble()); p = p2.getDouble(); dist = new ZipfDistributionImpl(n, p); first = 0; last = n; break; case TYPE_BARCHART_POISSON: if (!p1geo.isDefined()) return false; double lambda = p1.getDouble(); dist = new PoissonDistributionImpl(lambda); first = 0; last = (int) Math.max(1, kernel.getXmax() + 1); break; case TYPE_BARCHART_HYPERGEOMETRIC: if (!(p1geo.isDefined() && p2geo.isDefined() && p3geo.isDefined())) return false; int pop = (int) p1.getDouble(); int successes = (int) p2.getDouble(); int sample = (int) p3.getDouble(); dist = new HypergeometricDistributionImpl(pop, successes, sample); first = Math.max(0, successes + sample - pop); last = Math.min(successes, sample); break; } // load class list and probability list loadDistributionLists(first, last, dist); } catch (Exception e) { Application.debug(e.getMessage()); return false; } return true; }
From source file:geogebra.common.kernel.algos.AlgoFunctionAreaSums.java
/** * Prepares list1 and list2 for use with probability distribution bar charts *//*from w w w . j av a 2 s . c o m*/ private boolean prepareDistributionLists() { IntegerDistribution dist = null; int first = 0, last = 0; try { // get the distribution and the first, last list values for given // distribution type switch (type) { case BARCHART_BINOMIAL: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; int n = (int) Math.round(p1.getDouble()); double p = p2.getDouble(); dist = new BinomialDistributionImpl(n, p); first = 0; last = n; break; case BARCHART_PASCAL: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; n = (int) Math.round(p1.getDouble()); p = p2.getDouble(); dist = new PascalDistributionImpl(n, p); first = 0; last = (int) Math.max(1, (kernel).getXmax() + 1); break; case BARCHART_ZIPF: if (!(p1geo.isDefined() && p2geo.isDefined())) return false; n = (int) Math.round(p1.getDouble()); p = p2.getDouble(); dist = new ZipfDistributionImpl(n, p); first = 0; last = n; break; case BARCHART_POISSON: if (!p1geo.isDefined()) return false; double lambda = p1.getDouble(); dist = new PoissonDistributionImpl(lambda); first = 0; last = (int) Math.max(1, kernel.getXmax() + 1); break; case BARCHART_HYPERGEOMETRIC: if (!(p1geo.isDefined() && p2geo.isDefined() && p3geo.isDefined())) return false; int pop = (int) p1.getDouble(); int successes = (int) p2.getDouble(); int sample = (int) p3.getDouble(); dist = new HypergeometricDistributionImpl(pop, successes, sample); first = Math.max(0, successes + sample - pop); last = Math.min(successes, sample); break; } // load class list and probability list loadDistributionLists(first, last, dist); } catch (Exception e) { App.debug(e.getMessage()); return false; } return true; }
From source file:org.apache.mahout.clustering.lda.TestLDAInference.java
/** * Generate random document vector//from w w w. j a v a 2 s.c o m * * @param numWords * int number of words in the vocabulary * @param numWords * E[count] for each word */ private Vector generateRandomDoc(int numWords, double sparsity) throws MathException { Vector v = new DenseVector(numWords); IntegerDistribution dist = new PoissonDistributionImpl(sparsity); for (int i = 0; i < numWords; i++) { // random integer v.setQuick(i, dist.inverseCumulativeProbability(random.nextDouble()) + 1); } return v; }
From source file:org.apache.mahout.clustering.lda.TestMapReduce.java
/** * Generate random document vector/*from w ww.ja va2 s . co m*/ * @param numWords int number of words in the vocabulary * @param numWords E[count] for each word */ private RandomAccessSparseVector generateRandomDoc(int numWords, double sparsity) throws MathException { RandomAccessSparseVector v = new RandomAccessSparseVector(numWords, (int) (numWords * sparsity)); IntegerDistribution dist = new PoissonDistributionImpl(sparsity); for (int i = 0; i < numWords; i++) { // random integer v.set(i, dist.inverseCumulativeProbability(random.nextDouble()) + 1); } return v; }
From source file:org.apache.mahout.knn.generate.PoissonSampler.java
public PoissonSampler(double lambda) { gen = RandomUtils.getRandom(); pd = new PoissonDistributionImpl(lambda); }
From source file:org.apache.mahout.knn.generate.PoissonSamplerTest.java
private void checkDistribution(PoissonSampler pd, double alpha) { int[] count = new int[(int) Math.max(10, 5 * alpha)]; for (int i = 0; i < 10000; i++) { count[pd.sample().intValue()]++; }// w w w . java 2 s .c om PoissonDistribution ref = new PoissonDistributionImpl(alpha); for (int i = 0; i < count.length; i++) { assertEquals(ref.probability(i), count[i] / 10000.0, 2e-2); } }
From source file:org.renjin.Distributions.java
public static double dpois(final double x, final double lambda, boolean log) { return d(new PoissonDistributionImpl(lambda), x, log); }