public double getBetaRandom() { try { return new BetaDistributionImpl(1 + sum, 1 + total - sum).sample(); } catch (final MathException e) { e.printStackTrace(); return -1; } }
/** {@inheritDoc} */ @Override public double cumulativeProbability(double x0, double x1) throws MathException { return cumulativeProbability(x1) - cumulativeProbability(x0); }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @deprecated */ public double density(Double x) { return density(x.doubleValue()); }
/** * Generates a random value from the {@link BetaDistributionImpl Beta Distribution}. * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion} * to generate random values. * * @param alpha first distribution shape parameter * @param beta second distribution shape parameter * @return random value sampled from the beta(alpha, beta) distribution * @throws MathException if an error occurs generating the random value * @since 2.2 */ public double nextBeta(double alpha, double beta) throws MathException { return nextInversionDeviate(new BetaDistributionImpl(alpha, beta)); }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @since 2.1 */ public double density(double x) { recomputeZ(); if (x < 0 || x > 1) { return 0; } else if (x == 0) { if (alpha < 1) { throw MathRuntimeException.createIllegalArgumentException( "Cannot compute beta density at 0 when alpha = {0,number}", alpha); } return 0; } else if (x == 1) { if (beta < 1) { throw MathRuntimeException.createIllegalArgumentException( "Cannot compute beta density at 1 when beta = %.3g", beta); } return 0; } else { double logX = Math.log(x); double log1mX = Math.log1p(-x); return Math.exp((alpha - 1) * logX + (beta - 1) * log1mX - z); } }
public ContaminationData(GenomeLoc site, long basesMatching, long basesMismatching, double[] bins) { this.site = site; this.basesMatching = basesMatching; this.basesMismatching = basesMismatching; this.bins = bins; long totalBases = this.basesMatching + this.basesMismatching; if (totalBases != 0) { this.mismatchFraction = (double)this.basesMismatching / (double) totalBases; } int a = (int) this.getBasesMismatching() + 1; int b = (int) this.getBasesMatching() + 1; BetaDistribution dist = new BetaDistributionImpl(a,b); try { this.p = 1.0d - dist.cumulativeProbability(0.5d); } catch (MathException me) { throw new RuntimeException("Error! - " + me.toString()); } }
/** * Returns the variance. * * For first shape parameter <code>s1</code> and * second shape parameter <code>s2</code>, * the variance is * <code>[ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ]</code> * * @return the variance * @since 2.2 */ public double getNumericalVariance() { final double a = getAlpha(); final double b = getBeta(); final double alphabetasum = a + b; return (a * b) / ((alphabetasum * alphabetasum) * (alphabetasum + 1)); }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @since 2.1 */ @Override public double density(double x) { recomputeZ(); if (x < 0 || x > 1) { return 0; } else if (x == 0) { if (alpha < 1) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha); } return 0; } else if (x == 1) { if (beta < 1) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta); } return 0; } else { double logX = FastMath.log(x); double log1mX = FastMath.log1p(-x); return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z); } }
/** * Return the probability density for a particular point. * * @param x The point at which the density should be computed. * @return The pdf at point x. * @deprecated */ @Deprecated public double density(Double x) { return density(x.doubleValue()); }
/** {@inheritDoc} */ @Override public double cumulativeProbability(double x0, double x1) throws MathException { return cumulativeProbability(x1) - cumulativeProbability(x0); }