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;
}
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);
}
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));
}
}
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;
}
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)));
}
}
}
}
Aggregations