Search in sources :

Example 86 with RandomGenerator

use of org.apache.commons.math3.random.RandomGenerator in project cruise-control by linkedin.

the class AnalyzerUtils method testDifference.

/**
 * Test if two clusters are significantly different in the metrics we look at for balancing.
 *
 * @param orig the utilization matrix from the original cluster
 * @param optimized the utilization matrix from the optimized cluster
 * @return The P value that the various derived resources come from the same probability distribution.  The probability
 * that the null hypothesis is correct.
 */
public static double[] testDifference(double[][] orig, double[][] optimized) {
    int nResources = RawAndDerivedResource.values().length;
    if (orig.length != nResources) {
        throw new IllegalArgumentException("orig must have number of rows equal to RawAndDerivedResource.");
    }
    if (optimized.length != nResources) {
        throw new IllegalArgumentException("optimized must have number of rows equal to RawAndDerivedResource.");
    }
    if (orig[0].length != optimized[0].length) {
        throw new IllegalArgumentException("The number of brokers must be the same.");
    }
    double[] pValues = new double[orig.length];
    // TODO:  For small N we want to do statistical bootstrapping (not the same as bootstrapping data).
    for (int resourceIndex = 0; resourceIndex < nResources; resourceIndex++) {
        RandomGenerator rng = new MersenneTwister(0x5d11121018463324L);
        KolmogorovSmirnovTest kolmogorovSmirnovTest = new KolmogorovSmirnovTest(rng);
        pValues[resourceIndex] = kolmogorovSmirnovTest.kolmogorovSmirnovTest(orig[resourceIndex], optimized[resourceIndex]);
    }
    return pValues;
}
Also used : KolmogorovSmirnovTest(org.apache.commons.math3.stat.inference.KolmogorovSmirnovTest) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) RandomGenerator(org.apache.commons.math3.random.RandomGenerator)

Example 87 with RandomGenerator

use of org.apache.commons.math3.random.RandomGenerator in project mixcr by milaboratory.

the class ClonalSequenceTest method testIsCompatible5.

@Test
public void testIsCompatible5() throws Exception {
    RandomGenerator random = new Well1024a();
    ClonalSequence c1 = create("AAAAAAAAAA", "AAAAAAAAAAAAAA");
    ClonalSequence c2 = create("AAAAA", "AAAAAAA");
    testCompatiblePair(c1, c2, random);
    testCompatiblePair(c2, c1, random);
// c2 = create("AAAAA", "AAAAAAAAAAAAAAAAAAAAAAAAAA");
// testCompatiblePair(c1, c2, random);
// testCompatiblePair(c2, c1, random);
// c2 = create("AAAAAAAAAAAAAAAAAAAAAAAAAA", "AAAAA");
// testCompatiblePair(c1, c2, random);
// testCompatiblePair(c2, c1, random);
}
Also used : RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Well1024a(org.apache.commons.math3.random.Well1024a) Test(org.junit.Test)

Example 88 with RandomGenerator

use of org.apache.commons.math3.random.RandomGenerator in project mixcr by milaboratory.

the class ClonalSequenceTest method testIsCompatible2.

@Test
public void testIsCompatible2() throws Exception {
    RandomGenerator generator = new Well1024a();
    Mutations<NucleotideSequence> muts = Mutations.decode("", NucleotideSequence.ALPHABET);
    for (int i = 0; i < 100; i++) {
        ClonalSequence c1 = createRandom(5 + generator.nextInt(10), generator);
        Assert.assertTrue(c1.isCompatible(c1, muts));
    }
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) Well1024a(org.apache.commons.math3.random.Well1024a) Test(org.junit.Test)

Example 89 with RandomGenerator

use of org.apache.commons.math3.random.RandomGenerator in project tetrad by cmu-phil.

the class RandomUtil method setSeed.

/**
 * Sets the seed to the given value.
 *
 * @param seed A long value. Once this seed is set, the behavior of the random number generator is deterministic, so
 *             setting the seed can be used to repeat previous behavior.
 */
public void setSeed(long seed) {
    // Do not change this generator; you will screw up innuerable unit tests!
    randomGenerator = new SynchronizedRandomGenerator(new Well44497b(seed));
    seedsToGenerators.put(seed, randomGenerator);
    normal = new NormalDistribution(randomGenerator, 0, 1);
    this.seed = seed;
}
Also used : Well44497b(org.apache.commons.math3.random.Well44497b) SynchronizedRandomGenerator(org.apache.commons.math3.random.SynchronizedRandomGenerator)

Example 90 with RandomGenerator

use of org.apache.commons.math3.random.RandomGenerator in project repseqio by repseqio.

the class ExportCloneSequencesAction method go.

@Override
public void go(ActionHelper helper) throws Exception {
    Chains chains = params.getChains();
    GeneFeature geneFeature = params.getGeneFeature();
    RandomGenerator random = new Well19937c(1232434);
    try (GRepertoireReader input = new GRepertoireReader(createBufferedReader(params.getInput()));
        FastaWriter<NucleotideSequence> output = createSingleFastaWriter(params.getOutput())) {
        List<DescriptionExtractor> extractors = params.getExtractors(input.getLibrary());
        long i = 0;
        for (GClone clone : CUtils.it(input)) {
            int f = params.factor == null ? 1 : randomizedRound(clone.abundance * params.factor, random);
            for (int j = 0; j < f; j++) for (Map.Entry<String, GGene> e : clone.genes.entrySet()) if (chains.contains(e.getKey())) {
                StringBuilder descriptionLine = new StringBuilder("GClone");
                for (DescriptionExtractor extractor : extractors) descriptionLine.append("|").append(extractor.extract(clone, e.getValue(), e.getKey()));
                output.write(new FastaRecord<>(i++, descriptionLine.toString(), e.getValue().getFeature(geneFeature)));
            }
        }
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) Chains(io.repseq.core.Chains) Well19937c(org.apache.commons.math3.random.Well19937c) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence)

Aggregations

RandomGenerator (org.apache.commons.math3.random.RandomGenerator)82 Well19937c (org.apache.commons.math3.random.Well19937c)27 Random (java.util.Random)20 Test (org.testng.annotations.Test)18 RandomGeneratorFactory (org.apache.commons.math3.random.RandomGeneratorFactory)16 Assert (org.testng.Assert)16 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)14 Test (org.junit.Test)14 Collectors (java.util.stream.Collectors)12 IntStream (java.util.stream.IntStream)12 Arrays (java.util.Arrays)10 List (java.util.List)10 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)10 ArrayList (java.util.ArrayList)9 NormalDistribution (org.apache.commons.math3.distribution.NormalDistribution)8 ModeledSegment (org.broadinstitute.hellbender.tools.exome.ModeledSegment)8 AllelicCountCollection (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection)8 java.util (java.util)6 GammaDistribution (org.apache.commons.math3.distribution.GammaDistribution)6 ConvergenceException (org.apache.commons.math3.exception.ConvergenceException)6