List of usage examples for org.apache.commons.math.distribution PoissonDistributionImpl PoissonDistributionImpl
public PoissonDistributionImpl(double p)
From source file:de.tud.kom.p2psim.impl.util.stat.distributions.PoissonDistribution.java
/** * returns a random value Poisson distributed with lamda = _lamda. * @param _lamda/*from w ww.j av a 2 s . co m*/ * @return as double */ public static double returnValue(double _lamda) { try { PoissonDistributionImpl d = new PoissonDistributionImpl(_lamda); return d.inverseCumulativeProbability(Simulator.getRandom().nextDouble()); } catch (MathException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } }
From source file:de.tud.kom.p2psim.impl.util.stat.distributions.PoissonDistribution.java
@XMLConfigurableConstructor({ "lambda" })
public PoissonDistribution(double lambda) {
this.lambda = lambda;
this.poisson = new PoissonDistributionImpl(lambda);
}
From source file:juicebox.tools.utils.common.ArrayTools.java
/** * poisson.pdf(k) = exp(-mu) * mu**k / k! * * @param index/* www . j a v a 2s.c o m*/ * @param width * @return */ public static double[] generatePoissonPMF(int index, int width) { double mu = Math.pow(2.0, (index + 1.0) / 3.0); double[] poissonPMF = new double[width]; PoissonDistributionImpl poissonDistribution = new PoissonDistributionImpl(mu); // use dynamic programming to grow poisson PMF for (int k = 0; k < width; k++) { poissonPMF[k] = poissonDistribution.probability(k); // the total is for scaling } return poissonPMF; }
From source file:dr.math.distributions.PoissonDistribution.java
public static double pdf(double x, double mean) { PoissonDistributionImpl dist = new PoissonDistributionImpl(mean); return dist.probability(x); }
From source file:dr.math.distributions.PoissonDistribution.java
public static double logPdf(double x, double mean) { PoissonDistributionImpl dist = new PoissonDistributionImpl(mean); double pdf = dist.probability(x); if (pdf == 0 || Double.isNaN(pdf)) { // bad estimate return x * Math.log(mean) - Poisson.gammln(x + 1) - mean; }/* ww w .j a v a 2 s. co m*/ return Math.log(pdf); }
From source file:dr.math.distributions.PoissonDistribution.java
public static double cdf(double x, double mean) { try {/* w w w . j ava2s .c o m*/ PoissonDistributionImpl dist = new PoissonDistributionImpl(mean); return dist.cumulativeProbability(x); } catch (MathException e) { throw new RuntimeException(e); } }
From source file:dr.math.distributions.PoissonDistribution.java
public static double quantile(double y, double mean) { try {//from ww w. j a v a2s .c om PoissonDistributionImpl dist = new PoissonDistributionImpl(mean); return dist.inverseCumulativeProbability(y); } catch (MathException e) { throw new RuntimeException(e); } }
From source file:desmoj.core.dist.DiscreteDistPoisson.java
/** * Abstract method to map a double <code>p</code> from 0...1 to the * distribution's domain by determining the value x that satisfies * <code>P(X < x) = p</code>. * //from w w w. ja va 2s. c om * @param p double: A value between 0 and 1 * * @return Long : The value x that satisfies <code>P(X < x) = p</code> */ public Long getInverseOfCumulativeProbabilityFunction(double p) { if (p == 1.0) return Long.MAX_VALUE; // should be infinity, can't get closer PoissonDistributionImpl poi = new PoissonDistributionImpl(this.getMean()); Long x = 0l; double cummulative_prob = 0; do { cummulative_prob += poi.probability(x); if (cummulative_prob >= p) return x; x++; } while (x < 10000); return Long.MAX_VALUE; // wrong, just an approximation }
From source file:bacter.model.ACGCoalescent.java
@Override public double calculateLogP() { // Check whether conversion count exceeds bounds. if (acg.getTotalConvCount() < lowerCCBoundInput.get() || acg.getTotalConvCount() > upperCCBoundInput.get()) return Double.NEGATIVE_INFINITY; logP = calculateClonalFrameLogP();/*from ww w .j a va 2 s .com*/ double poissonMean = rhoInput.get().getValue() * acg.getClonalFrameLength() * (acg.getTotalConvertibleSequenceLength() + acg.getConvertibleLoci().size() * (deltaInput.get().getValue() - 1.0)); // Probability of conversion count: if (poissonMean > 0.0) { logP += -poissonMean + acg.getTotalConvCount() * Math.log(poissonMean); // - GammaFunction.lnGamma(acg.getConvCount()+1); } else { if (acg.getTotalConvCount() > 0) logP = Double.NEGATIVE_INFINITY; } for (Locus locus : acg.getConvertibleLoci()) for (Conversion conv : acg.getConversions(locus)) logP += calculateConversionLogP(conv); // This N! takes into account the permutation invariance of // the individual conversions, and cancels with the N! in the // denominator of the Poissonian above. // logP += GammaFunction.lnGamma(acg.getConvCount() + 1); if (lowerCCBoundInput.get() > 0 || upperCCBoundInput.get() < Integer.MAX_VALUE) { try { logP -= new PoissonDistributionImpl(poissonMean).cumulativeProbability(lowerCCBoundInput.get(), upperCCBoundInput.get()); } catch (MathException e) { throw new RuntimeException("Error computing modification to ARG " + "prior density required by conversion number constraint."); } } return logP; }
From source file:edu.utexas.cs.tactex.servercustomers.factoredcustomer.ProbabilityDistribution.java
ProbabilityDistribution(FactoredCustomerService service, Element xml) {
if (null == randomSeedRepo)
randomSeedRepo = (RandomSeedRepo) SpringApplicationContext.getBean("randomSeedRepo");
type = Enum.valueOf(DistType.class, xml.getAttribute("distribution"));
switch (type) {
case POINTMASS:
case DEGENERATE:
param1 = Double.parseDouble(xml.getAttribute("value"));
sampler = new DegenerateSampler(param1);
break;/*from w w w. j av a 2 s .co m*/
case UNIFORM:
param1 = Double.parseDouble(xml.getAttribute("low"));
param2 = Double.parseDouble(xml.getAttribute("high"));
sampler = new UniformSampler(param1, param2);
break;
case INTERVAL:
param1 = Double.parseDouble(xml.getAttribute("mean"));
param2 = Double.parseDouble(xml.getAttribute("stdDev"));
param3 = Double.parseDouble(xml.getAttribute("low"));
param4 = Double.parseDouble(xml.getAttribute("high"));
sampler = new IntervalSampler(param1, param2, param3, param4);
break;
case NORMAL:
case GAUSSIAN:
param1 = Double.parseDouble(xml.getAttribute("mean"));
param2 = Double.parseDouble(xml.getAttribute("stdDev"));
sampler = new ContinuousSampler(new NormalDistributionImpl(param1, param2));
break;
case STDNORMAL:
param1 = 0;
param2 = 1;
sampler = new ContinuousSampler(new NormalDistributionImpl(param1, param2));
break;
case LOGNORMAL:
param1 = Double.parseDouble(xml.getAttribute("expMean"));
param2 = Double.parseDouble(xml.getAttribute("expStdDev"));
sampler = new LogNormalSampler(param1, param2);
break;
case CAUCHY:
param1 = Double.parseDouble(xml.getAttribute("median"));
param2 = Double.parseDouble(xml.getAttribute("scale"));
sampler = new ContinuousSampler(new CauchyDistributionImpl(param1, param2));
break;
case BETA:
param1 = Double.parseDouble(xml.getAttribute("alpha"));
param2 = Double.parseDouble(xml.getAttribute("beta"));
sampler = new ContinuousSampler(new BetaDistributionImpl(param1, param2));
break;
case BINOMIAL:
param1 = Double.parseDouble(xml.getAttribute("trials"));
param2 = Double.parseDouble(xml.getAttribute("success"));
sampler = new DiscreteSampler(new BinomialDistributionImpl((int) param1, param2));
break;
case POISSON:
param1 = Double.parseDouble(xml.getAttribute("lambda"));
sampler = new DiscreteSampler(new PoissonDistributionImpl(param1));
break;
case CHISQUARED:
param1 = Double.parseDouble(xml.getAttribute("dof"));
sampler = new ContinuousSampler(new ChiSquaredDistributionImpl(param1));
break;
case EXPONENTIAL:
param1 = Double.parseDouble(xml.getAttribute("mean"));
sampler = new ContinuousSampler(new ExponentialDistributionImpl(param1));
break;
case GAMMA:
param1 = Double.parseDouble(xml.getAttribute("alpha"));
param2 = Double.parseDouble(xml.getAttribute("beta"));
sampler = new ContinuousSampler(new GammaDistributionImpl(param1, param2));
break;
case WEIBULL:
param1 = Double.parseDouble(xml.getAttribute("alpha"));
param2 = Double.parseDouble(xml.getAttribute("beta"));
sampler = new ContinuousSampler(new WeibullDistributionImpl(param1, param2));
break;
case STUDENT:
param1 = Double.parseDouble(xml.getAttribute("dof"));
sampler = new ContinuousSampler(new TDistributionImpl(param1));
break;
case SNEDECOR:
param1 = Double.parseDouble(xml.getAttribute("d1"));
param2 = Double.parseDouble(xml.getAttribute("d2"));
sampler = new ContinuousSampler(new FDistributionImpl(param1, param2));
break;
default:
throw new Error("Invalid probability distribution type!");
}
sampler.reseedRandomGenerator(service.getRandomSeedRepo()
.getRandomSeed("factoredcustomer.ProbabilityDistribution", SeedIdGenerator.getId(), "Sampler")
.getValue());
}