List of usage examples for org.apache.commons.math3.distribution BinomialDistribution probability
public double probability(int x)
From source file:com.cloudera.oryx.app.speed.rdf.RDFSpeedIT.java
private static void checkProbability(int majorityCount, int count, BinomialDistribution dist) { double expected = 0.9 * count; double probAsExtreme = majorityCount <= expected ? dist.cumulativeProbability(majorityCount) : (1.0 - dist.cumulativeProbability(majorityCount)) + dist.probability(majorityCount); assertTrue(majorityCount + " should be about " + expected + " (~90% of " + count + ")", probAsExtreme >= 0.001);//from w w w .j a v a 2s . c o m }
From source file:me.datamining.cluster.STING.java
/** * /* w w w.j a v a 2 s . c om*/ * @param value * @param number * @param probabilty * @return */ public static double binomialPDF(int value, double number, double probabilty) { BinomialDistribution bdf = new BinomialDistribution((int) value, probabilty); return bdf.probability(value); }
From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMClusters.java
private void addToPlot(int n, double p, String title, Plot2 plot, Color color) { double[] x = new double[n + 1]; double[] y = new double[n + 1]; BinomialDistribution dist = new BinomialDistribution(n, p); int startIndex = 1; // Normalise optionally excluding the x=0 point double total = 1; if (startIndex > 0) total -= dist.probability(0); double cumul = 0; for (int i = startIndex; i <= n; i++) { cumul += dist.probability(i) / total; x[i] = i;// w w w . java 2 s . co m y[i] = cumul; } plot.setColor(color); plot.addPoints(x, y, Plot2.LINE); //plot.addPoints(x, y, Plot2.CIRCLE); Utils.display(title, plot); }
From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMClusters.java
public void run(String arg) { if (!showDialog()) return;/*from w w w . jav a 2s .c o m*/ PCPALMMolecules.logSpacer(); Utils.log(TITLE); PCPALMMolecules.logSpacer(); long start = System.currentTimeMillis(); HistogramData histogramData; if (fileInput) { histogramData = loadHistogram(histogramFile); } else { histogramData = doClustering(); } if (histogramData == null) return; float[][] hist = histogramData.histogram; // Create a histogram of the cluster sizes String title = TITLE + " Molecules/cluster"; String xTitle = "Molecules/cluster"; String yTitle = "Frequency"; // Create the data required for fitting and plotting float[] xValues = Utils.createHistogramAxis(hist[0]); float[] yValues = Utils.createHistogramValues(hist[1]); // Plot the histogram float yMax = Maths.max(yValues); Plot2 plot = new Plot2(title, xTitle, yTitle, xValues, yValues); if (xValues.length > 0) { double xPadding = 0.05 * (xValues[xValues.length - 1] - xValues[0]); plot.setLimits(xValues[0] - xPadding, xValues[xValues.length - 1] + xPadding, 0, yMax * 1.05); } Utils.display(title, plot); HistogramData noiseData = loadNoiseHistogram(histogramData); if (noiseData != null) { if (subtractNoise(histogramData, noiseData)) { // Update the histogram title += " (noise subtracted)"; xValues = Utils.createHistogramAxis(hist[0]); yValues = Utils.createHistogramValues(hist[1]); yMax = Maths.max(yValues); plot = new Plot2(title, xTitle, yTitle, xValues, yValues); if (xValues.length > 0) { double xPadding = 0.05 * (xValues[xValues.length - 1] - xValues[0]); plot.setLimits(xValues[0] - xPadding, xValues[xValues.length - 1] + xPadding, 0, yMax * 1.05); } Utils.display(title, plot); // Automatically save if (autoSave) { String newFilename = Utils.replaceExtension(histogramData.filename, ".noise.tsv"); if (saveHistogram(histogramData, newFilename)) { Utils.log("Saved noise-subtracted histogram to " + newFilename); } } } } // Fit the histogram double[] fitParameters = fitBinomial(histogramData); if (fitParameters != null) { // Add the binomial to the histogram int n = (int) fitParameters[0]; double p = fitParameters[1]; Utils.log("Optimal fit : N=%d, p=%s", n, Utils.rounded(p)); BinomialDistribution dist = new BinomialDistribution(n, p); // A zero-truncated binomial was fitted. // pi is the adjustment factor for the probability density. double pi = 1 / (1 - dist.probability(0)); if (!fileInput) { // Calculate the estimated number of clusters from the observed molecules: // Actual = (Observed / p-value) / N final double actual = (nMolecules / p) / n; Utils.log("Estimated number of clusters : (%d / %s) / %d = %s", nMolecules, Utils.rounded(p), n, Utils.rounded(actual)); } double[] x = new double[n + 2]; double[] y = new double[n + 2]; // Scale the values to match those on the histogram final double normalisingFactor = count * pi; for (int i = 0; i <= n; i++) { x[i] = i + 0.5; y[i] = dist.probability(i) * normalisingFactor; } x[n + 1] = n + 1.5; y[n + 1] = 0; // Redraw the plot since the limits may have changed plot = new Plot2(title, xTitle, yTitle, xValues, yValues); double xPadding = 0.05 * (xValues[xValues.length - 1] - xValues[0]); plot.setLimits(xValues[0] - xPadding, xValues[xValues.length - 1] + xPadding, 0, Maths.maxDefault(yMax, y) * 1.05); plot.setColor(Color.magenta); plot.addPoints(x, y, Plot2.LINE); plot.addPoints(x, y, Plot2.CIRCLE); plot.setColor(Color.black); Utils.display(title, plot); } double seconds = (System.currentTimeMillis() - start) / 1000.0; String msg = TITLE + " complete : " + seconds + "s"; IJ.showStatus(msg); Utils.log(msg); return; }
From source file:org.deidentifier.arx.criteria.EDDifferentialPrivacy.java
/** * Adds summands of the binomial distribution with probability beta * @param from/*from w w w. j a v a 2s .c om*/ * @param to * @param beta * @return */ private double calculateBinomialSum(int from, int to, double beta) { BinomialDistribution binomialDistribution = new BinomialDistribution(to, beta); double sum = 0.0d; for (int j = from; j <= to; ++j) { sum += binomialDistribution.probability(j); } return sum; }