List of usage examples for org.apache.commons.math.distribution GammaDistribution inverseCumulativeProbability
double inverseCumulativeProbability(double p) throws MathException;
From source file:geogebra.kernel.statistics.AlgoInverseGamma.java
protected final void compute() { if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined()) { double param = a.getDouble(); double param2 = b.getDouble(); double val = c.getDouble(); try {//from ww w . ja va2 s. co m GammaDistribution dist = getGammaDistribution(param, param2); num.setValue(dist.inverseCumulativeProbability(val)); // P(T <= val) } catch (Exception e) { num.setUndefined(); } } else num.setUndefined(); }
From source file:geogebra.common.kernel.statistics.AlgoInverseGamma.java
@Override public final void compute() { if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined()) { double param = a.getDouble(); double param2 = b.getDouble(); double val = c.getDouble(); try {// w w w . j a va 2s. c om GammaDistribution dist = getGammaDistribution(param, param2); num.setValue(dist.inverseCumulativeProbability(val)); // P(T <= // val) } catch (Exception e) { num.setUndefined(); } } else num.setUndefined(); }
From source file:desmoj.core.dist.ContDistErlang.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 2 s . c om*/ * @param p double: A value between 0 and 1 * * @return Double : The value x that satisfies <code>P(X < x) = p</code> */ public Double getInverseOfCumulativeProbabilityFunction(final double p) { double newSample = StatisticObject.UNDEFINED; // org.apache.commons.math.distribution.GammaDistribution gammadist = new org.apache.commons.math.distribution.GammaDistributionImpl( k, this.mean); // special case try { newSample = gammadist.inverseCumulativeProbability(p); } catch (MathException e) { } return newSample; }
From source file:desmoj.core.dist.ContDistGamma.java
/** * Returns the next sample from this distribution. The value depends upon * the seed, the number of values taken from the stream by using this method * before and the alpha and beta parameters specified for this distribution. * /* w ww .j a v a2 s . c o m*/ * @return Double : The next gamma distributed sample from this * distribution. */ public Double sample() { double newSample = -1; // double randomNumber = randomGenerator.nextDouble(); org.apache.commons.math.distribution.GammaDistribution gammadist = new org.apache.commons.math.distribution.GammaDistributionImpl( alpha, beta); incrementObservations(); // increase count of samples if (isAntithetic()) { try { newSample = gammadist.inverseCumulativeProbability(1 - randomNumber); } catch (MathException e) { } } else { try { newSample = gammadist.inverseCumulativeProbability(randomNumber); } catch (MathException e) { } } if (this.currentlySendTraceNotes()) this.traceLastSample(Double.toString(newSample)); return newSample; }
From source file:desmoj.core.dist.ContDistBeta.java
/** * Returns the next sample from this distribution. The value depends upon * the seed, the number of values taken from the stream by using this method * before and the alpha and beta parameters specified for this distribution. * //w ww . j a v a 2s. co m * @return Double : The next Beta distributed sample from this distribution. */ public Double sample() { double newSample = -1; // double randomNumber1 = randomGenerator.nextDouble(); double randomNumber2 = randomGenerator.nextDouble(); org.apache.commons.math.distribution.GammaDistribution gammadist1 = new org.apache.commons.math.distribution.GammaDistributionImpl( alpha, 1); org.apache.commons.math.distribution.GammaDistribution gammadist2 = new org.apache.commons.math.distribution.GammaDistributionImpl( beta, 1); incrementObservations(); // increase count of samples if (isAntithetic()) { try { double gammaval1 = gammadist1.inverseCumulativeProbability(1 - randomNumber1); double gammaval2 = gammadist2.inverseCumulativeProbability(1 - randomNumber2); newSample = gammaval1 / (gammaval1 + gammaval2); } catch (MathException e) { } } else { try { double gammaval1 = gammadist1.inverseCumulativeProbability(randomNumber1); double gammaval2 = gammadist2.inverseCumulativeProbability(randomNumber2); newSample = gammaval1 / (gammaval1 + gammaval2); } catch (MathException e) { } } if (this.currentlySendTraceNotes()) this.traceLastSample(Double.toString(newSample)); return newSample; }
From source file:beast.evolution.sitemodel.SiteModel.java
/** * discretisation of gamma distribution with equal proportions in each * category/* w w w . j a va2 s .c o m*/ * @param node */ protected void calculateCategoryRates(final Node node) { double propVariable = 1.0; int cat = 0; if (/*invarParameter != null && */invarParameter.getValue() > 0) { if (hasPropInvariantCategory) { categoryRates[0] = 0.0; categoryProportions[0] = invarParameter.getValue(); } propVariable = 1.0 - invarParameter.getValue(); if (hasPropInvariantCategory) { cat = 1; } } if (shapeParameter != null) { final double a = shapeParameter.getValue(); double mean = 0.0; final int gammaCatCount = categoryCount - cat; final GammaDistribution g = new GammaDistributionImpl(a, 1.0 / a); for (int i = 0; i < gammaCatCount; i++) { try { // RRB: alternative implementation that seems equally good in // the first 5 significant digits, but uses a standard distribution object if (useBeast1StyleGamma) { categoryRates[i + cat] = GammaDistributionQuantile((2.0 * i + 1.0) / (2.0 * gammaCatCount), a, 1.0 / a); } else { categoryRates[i + cat] = g .inverseCumulativeProbability((2.0 * i + 1.0) / (2.0 * gammaCatCount)); } } catch (Exception e) { e.printStackTrace(); Log.err.println("Something went wrong with the gamma distribution calculation"); System.exit(-1); } mean += categoryRates[i + cat]; categoryProportions[i + cat] = propVariable / gammaCatCount; } mean = (propVariable * mean) / gammaCatCount; for (int i = 0; i < gammaCatCount; i++) { categoryRates[i + cat] /= mean; } } else { categoryRates[cat] = 1.0 / propVariable; categoryProportions[cat] = propVariable; } ratesKnown = true; }
From source file:yabby.evolution.sitemodel.SiteModel.java
/** * discretisation of gamma distribution with equal proportions in each * category/*from w w w. j a v a2 s . c o m*/ * @param node */ protected void calculateCategoryRates(final Node node) { double propVariable = 1.0; int cat = 0; if (/*invarParameter != null && */invarParameter.getValue() > 0) { if (hasPropInvariantCategory) { categoryRates[0] = 0.0; categoryProportions[0] = invarParameter.getValue(); } propVariable = 1.0 - invarParameter.getValue(); if (hasPropInvariantCategory) { cat = 1; } } if (shapeParameter != null) { final double a = shapeParameter.getValue(); double mean = 0.0; final int gammaCatCount = categoryCount - cat; final GammaDistribution g = new GammaDistributionImpl(a, 1.0 / a); for (int i = 0; i < gammaCatCount; i++) { try { // RRB: alternative implementation that seems equally good in // the first 5 significant digits, but uses a standard distribution object if (useBeast1StyleGamma) { categoryRates[i + cat] = GammaDistributionQuantile((2.0 * i + 1.0) / (2.0 * gammaCatCount), a, 1.0 / a); } else { categoryRates[i + cat] = g .inverseCumulativeProbability((2.0 * i + 1.0) / (2.0 * gammaCatCount)); } } catch (Exception e) { e.printStackTrace(); System.err.println("Something went wrong with the gamma distribution calculation"); System.exit(-1); } mean += categoryRates[i + cat]; categoryProportions[i + cat] = propVariable / gammaCatCount; } mean = (propVariable * mean) / gammaCatCount; for (int i = 0; i < gammaCatCount; i++) { categoryRates[i + cat] /= mean; } } else { categoryRates[cat] = 1.0 / propVariable; categoryProportions[cat] = propVariable; } ratesKnown = true; }