List of usage examples for org.apache.commons.math3.distribution BetaDistribution inverseCumulativeProbability
public double inverseCumulativeProbability(final double p) throws OutOfRangeException
From source file:gedi.lfc.gui.LfcMapper.java
@Override public PixelBlockToValuesMap map(ReferenceSequence reference, GenomicRegion region, PixelLocationMapping pixelMapping, PixelBlockToValuesMap data) { double[] counts = new double[2]; PixelBlockToValuesMap re = new PixelBlockToValuesMap(data.getBlocks(), 2, NumericArrayType.Double); for (int i = 0; i < pixelMapping.size(); i++) { NumericArray in = data.getValues(i); Arrays.fill(counts, 0);/*from www . ja v a 2s .co m*/ for (int c = 0; c < in.length(); c++) { int cond = contrast == null ? (c * 2) / in.length() : contrast.getMappedIndex(c); if (cond != -1) counts[cond] += in.getDouble(c); } NumericArray out = re.getValues(i); if (ArrayUtils.max(counts) > 0) { // out.set(0, Math.log(counts[0]/counts[1])/Math.log(2)); BetaDistribution dist = new BetaDistribution(counts[0] + 1, counts[1] + 1); out.set(0, pToLfc(dist.inverseCumulativeProbability(lower))); out.set(1, pToLfc(dist.inverseCumulativeProbability(upper))); } else { out.setDouble(0, Double.NaN); out.setDouble(1, Double.NaN); } } return re; }
From source file:fi.smaa.jsmaa.model.BetaMeasurement.java
@Override public Interval getRange() { BetaDistribution dist = new BetaDistribution(alpha, beta); double lowEnd = convertToRange(dist.inverseCumulativeProbability(0.025)); double highEnd = convertToRange(dist.inverseCumulativeProbability(0.975)); return new Interval(lowEnd, highEnd); }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("inverse of Beta cdf given a, b parameters and probability") @ScalarFunction//from ww w. j a v a 2 s.co m @SqlType(StandardTypes.DOUBLE) public static double inverseBetaCdf(@SqlType(StandardTypes.DOUBLE) double a, @SqlType(StandardTypes.DOUBLE) double b, @SqlType(StandardTypes.DOUBLE) double p) { checkCondition(p >= 0 && p <= 1, INVALID_FUNCTION_ARGUMENT, "p must be 0 >= p >= 1"); checkCondition(a > 0 && b > 0, INVALID_FUNCTION_ARGUMENT, "a, b must be > 0"); BetaDistribution distribution = new BetaDistribution(null, a, b, BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY); return distribution.inverseCumulativeProbability(p); }
From source file:edu.upf.bioevo.manhattanPlotter.QQPlot.java
void setExperiment(Experiment experiment) { this.experiment = experiment; // Creates ordered array with log10 observed values orderedLog10ObservedValues = new double[experiment.tests.length]; for (int i = 0; i < experiment.tests.length; i++) { orderedLog10ObservedValues[i] = experiment.tests[i].logPValue; }// ww w . ja v a 2 s. c o m Arrays.sort(orderedLog10ObservedValues); maxObservedLogValue = orderedLog10ObservedValues[orderedLog10ObservedValues.length - 1]; // Creates ordered array with log10 exepected values orderedLog10ExpectedValues = new double[experiment.tests.length]; for (int i = experiment.tests.length; i > 0; i--) { orderedLog10ExpectedValues[experiment.tests.length - i] = -Math .log10((double) i / (experiment.tests.length + 1)); } maxExpectedLogValue = orderedLog10ExpectedValues[orderedLog10ExpectedValues.length - 1]; // Creates CI95 upper and lower values if (ic95Option) { lowerCI = new double[experiment.tests.length]; upperCI = new double[experiment.tests.length]; for (int i = experiment.tests.length - 1; i >= 0; i--) { BetaDistribution beta = new BetaDistribution(i + 1, experiment.tests.length - i); lowerCI[i] = -Math.log10(beta.inverseCumulativeProbability(0.025)); upperCI[i] = -Math.log10(beta.inverseCumulativeProbability(0.975)); } Arrays.sort(lowerCI); Arrays.sort(upperCI); } }
From source file:gedi.lfc.LfcAlignedReadsProcessor.java
@Override public void endRegion(MutableReferenceGenomicRegion<?> region, ProcessorContext context) throws IOException { if (allreads) { } else if (multimode()) { out.writef("%s", region.getData()); for (int i = 0; i < total.length; i++) out.writef("\t%.1f", total[i]); out.writeLine();/* w w w .j ava 2s . c o m*/ } else { BetaDistribution beta = new BetaDistribution(total[0] + 1, total[1] + 1); out.writef("%s\t%.1f\t%.1f\t%.4f\t%.4f\t%.4f\n", region.getData(), total[0] + 1, total[1] + 1, pToLog2Fc(beta.inverseCumulativeProbability(0.5 * credi)), pToLog2Fc((beta.getAlpha() - 1) / (beta.getAlpha() + beta.getBeta() - 2)), pToLog2Fc(beta.inverseCumulativeProbability(1 - 0.5 * credi))); } }
From source file:gedi.lfc.LfcComputer.java
public void compute(LineOrientedFile out, GenomicRegionStorage<AlignedReadsData> reads, ReferenceSequenceConversion readConversion, GenomicRegionStorage<Transcript> transcripts, ContrastMapping contrast, Downsampling downsampling, Set<String> restrictToGenes) { if (contrast.getNumMergedConditions() != 2) throw new RuntimeException("Must be binary contrast!"); // mapping to genes HashMap<String, MutableReferenceGenomicRegion<String>> genesToRegon = new HashMap<String, MutableReferenceGenomicRegion<String>>(); transcripts.iterateReferenceGenomicRegions().forEachRemaining(rgr -> { if (restrictToGenes != null && !restrictToGenes.contains(rgr.getData().getGeneId())) return; MutableReferenceGenomicRegion<String> r = genesToRegon.get(rgr.getData().getGeneId()); if (r == null) genesToRegon.put(rgr.getData().getGeneId(), new MutableReferenceGenomicRegion<String>().setReference(rgr.getReference()) .setRegion(rgr.getRegion()).setData(rgr.getData().getGeneId())); else {/*w w w. j a v a2s . com*/ if (!r.getReference().equals(rgr.getReference())) throw new RuntimeException(rgr.getData().getGeneId() + " is located on multiple chromosomes: " + r.getReference() + ", " + rgr.getReference()); r.setRegion(r.getRegion().union(rgr.getRegion())); } }); // MemoryIntervalTreeStorage<String> genes = new MemoryIntervalTreeStorage<String>(); // for (MutableReferenceGenomicRegion<String> rgr : genesToRegon.values()) // genes.add(rgr.getReference(), rgr.getRegion(), rgr.getData()); double credi = 0.05; try { out.startWriting(); out.writef("Gene\talpha\tbeta\t%.3g credibility\tlog2 fold change\t%.3g credibility\n", 0.5 * credi, 1 - 0.5 * credi); for (MutableReferenceGenomicRegion<String> gene : genesToRegon.values()) { double[] total = new double[contrast.getNumMergedConditions()]; double[] buff = new double[contrast.getNumMergedConditions()]; reads.iterateIntersectingMutableReferenceGenomicRegions(readConversion.apply(gene.getReference()), gene.getRegion().getStart(), gene.getRegion().getEnd()).forEachRemaining(rgr -> { // check if there is a matching transcript if (gene.getRegion().contains(rgr.getRegion())) { // compute downsampled and add downsampling.getDownsampled(rgr.getData(), contrast, buff); ArrayUtils.add(total, buff); // System.out.println(Arrays.toString(buff)+"\t"+rgr.getReference()+":"+rgr.getRegion()+"\t"+rgr.getData()); } }); // System.err.println(gene); BetaDistribution beta = new BetaDistribution(total[0] + 1, total[1] + 1); out.writef("%s\t%.1f\t%.1f\t%.4f\t%.4f\t%.4f\n", gene.getData(), total[0] + 1, total[1] + 1, pToLog2Fc(beta.inverseCumulativeProbability(0.5 * credi)), pToLog2Fc((beta.getAlpha() - 1) / (beta.getAlpha() + beta.getBeta() - 2)), pToLog2Fc(beta.inverseCumulativeProbability(1 - 0.5 * credi))); } out.finishWriting(); } catch (IOException e) { } }