Search in sources :

Example 11 with BinomialDistribution

use of org.apache.commons.math3.distribution.BinomialDistribution in project blog by BayesianLogic.

the class Multinomial method sample_value_use_binomial.

/** Sample value from Multinomial Distribution using Binomial Distribution */
/*
   * Authored by yiwu on Oct.8.2014
   * reference:
   * chapter 2.2 of
   * http://www.sciencedirect.com/science/article/pii/016794739390115A
   */
private ArrayList<Integer> sample_value_use_binomial() {
    BinomialDistribution binom = null;
    int cur = 0;
    double cdf = 0;
    ArrayList<Integer> result = new ArrayList<Integer>(k);
    for (int i = 0; i < k - 1; i++) {
        if (n == cur) {
            result.add(0);
            continue;
        }
        binom = new BinomialDistribution(n - cur, p[i] / (1.0 - cdf));
        int x = binom.sample();
        cur += x;
        cdf += p[i];
        result.add(x);
    }
    result.add(n - cur);
    return result;
}
Also used : ArrayList(java.util.ArrayList) BinomialDistribution(org.apache.commons.math3.distribution.BinomialDistribution)

Example 12 with BinomialDistribution

use of org.apache.commons.math3.distribution.BinomialDistribution in project GDSC-SMLM by aherbert.

the class PulseActivationAnalysis method simulateActivations.

private int simulateActivations(RandomDataGenerator rdg, BinomialDistribution bd, float[][] molecules, MemoryPeakResults results, int t, double precision, int id) {
    if (bd == null)
        return 0;
    int n = molecules.length;
    int k = bd.sample();
    // Sample
    RandomGenerator rand = rdg.getRandomGenerator();
    int[] sample = Random.sample(k, n, rand);
    while (k-- > 0) {
        float[] xy = molecules[sample[k]];
        float x, y;
        do {
            x = (float) (xy[0] + rand.nextGaussian() * precision);
        } while (outOfBounds(x));
        do {
            y = (float) (xy[1] + rand.nextGaussian() * precision);
        } while (outOfBounds(y));
        results.add(createResult(t, x, y));
    }
    return sample.length;
}
Also used : RandomGenerator(org.apache.commons.math3.random.RandomGenerator)

Example 13 with BinomialDistribution

use of org.apache.commons.math3.distribution.BinomialDistribution in project GDSC-SMLM by aherbert.

the class PCPALMClusters method addToPlot.

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;
        y[i] = cumul;
    }
    plot.setColor(color);
    plot.addPoints(x, y, Plot2.LINE);
    //plot.addPoints(x, y, Plot2.CIRCLE);
    Utils.display(title, plot);
}
Also used : BinomialDistribution(org.apache.commons.math3.distribution.BinomialDistribution) ClusterPoint(gdsc.core.clustering.ClusterPoint)

Example 14 with BinomialDistribution

use of org.apache.commons.math3.distribution.BinomialDistribution in project gatk-protected by broadinstitute.

the class AlleleFractionSegmenterUnitTest method generateAllelicCount.

protected static AllelicCount generateAllelicCount(final double minorFraction, final SimpleInterval position, final RandomGenerator rng, final GammaDistribution biasGenerator, final double outlierProbability) {
    final int numReads = 100;
    final double bias = biasGenerator.sample();
    //flip a coin to decide alt minor (alt fraction = minor fraction) or ref minor (alt fraction = 1 - minor fraction)
    final double altFraction = rng.nextDouble() < 0.5 ? minorFraction : 1 - minorFraction;
    //the probability of an alt read is the alt fraction modified by the bias or, in the case of an outlier, random
    final double pAlt = rng.nextDouble() < outlierProbability ? rng.nextDouble() : altFraction / (altFraction + (1 - altFraction) * bias);
    final int numAltReads = new BinomialDistribution(rng, numReads, pAlt).sample();
    final int numRefReads = numReads - numAltReads;
    return new AllelicCount(position, numAltReads, numRefReads);
}
Also used : BinomialDistribution(org.apache.commons.math3.distribution.BinomialDistribution) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)

Aggregations

BinomialDistribution (org.apache.commons.math3.distribution.BinomialDistribution)13 Test (org.testng.annotations.Test)3 ClusterPoint (gdsc.core.clustering.ClusterPoint)2 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)2 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)2 MockQueryExecution (com.facebook.presto.execution.MockQueryExecution)1 RootInternalResourceGroup (com.facebook.presto.execution.resourceGroups.InternalResourceGroup.RootInternalResourceGroup)1 Plot2 (ij.gui.Plot2)1 DataSize (io.airlift.units.DataSize)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1 BernoulliReconstructionDistribution (org.deeplearning4j.nn.conf.layers.variational.BernoulliReconstructionDistribution)1 ExponentialReconstructionDistribution (org.deeplearning4j.nn.conf.layers.variational.ExponentialReconstructionDistribution)1 GaussianReconstructionDistribution (org.deeplearning4j.nn.conf.layers.variational.GaussianReconstructionDistribution)1 ReconstructionDistribution (org.deeplearning4j.nn.conf.layers.variational.ReconstructionDistribution)1 Test (org.junit.Test)1 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1