Search in sources :

Example 1 with MersenneTwister

use of cern.jet.random.engine.MersenneTwister in project processdash by dtuma.

the class ConfidenceIntervalSum method runSimulation.

protected void runSimulation() {
    u = new MersenneTwister();
    super.runSimulation();
}
Also used : MersenneTwister(cern.jet.random.engine.MersenneTwister)

Example 2 with MersenneTwister

use of cern.jet.random.engine.MersenneTwister in project processdash by dtuma.

the class EVScheduleConfidenceIntervals method runSimulation.

private void runSimulation() {
    long start = System.currentTimeMillis();
    RandomEngine random = new MersenneTwister();
    int sampleCount = Settings.getInt("ev.simulationSize", BOOTSTRAP_SIZE);
    if (USE_RATIO && indivDates == null) {
        double factor = Math.exp(0.75 * Math.log(randomObjects.size()));
        sampleCount = (int) (sampleCount / factor);
        if (sampleCount < 100)
            sampleCount = 100;
    }
    for (int i = 0; i < sampleCount; i++) runOneTest(random);
    cost.samplesDone();
    date.samplesDone();
    if (optimizedDate != null)
        optimizedDate.samplesDone();
    if (indivDates != null)
        for (int i = 0; i < indivDates.length; i++) indivDates[i].samplesDone();
    long finish = System.currentTimeMillis();
    long elapsed = finish - start;
    System.out.println("schedule simulation took " + elapsed + " ms.");
    if (optimizedDate != null)
        date.debug = true;
}
Also used : RandomEngine(cern.jet.random.engine.RandomEngine) MersenneTwister(cern.jet.random.engine.MersenneTwister)

Example 3 with MersenneTwister

use of cern.jet.random.engine.MersenneTwister in project processdash by dtuma.

the class LognormalConfidenceInterval method generateBootstrapSamples.

private double[] generateBootstrapSamples() {
    RandomEngine u = new MersenneTwister();
    Normal normal = new Normal(0, 1, u);
    ChiSquare chisquare = new ChiSquare(numSamples - 1, u);
    int bootstrapSize = Settings.getInt("logCI.bootstrapSize", 2000);
    double[] samples = new double[bootstrapSize];
    for (int i = bootstrapSize; i-- > 0; ) samples[i] = generateBootstrapSample(normal, chisquare, numSamples, logstd);
    Arrays.sort(samples);
    return samples;
}
Also used : ChiSquare(cern.jet.random.ChiSquare) RandomEngine(cern.jet.random.engine.RandomEngine) MersenneTwister(cern.jet.random.engine.MersenneTwister) Normal(cern.jet.random.Normal)

Example 4 with MersenneTwister

use of cern.jet.random.engine.MersenneTwister in project Gemma by PavlidisLab.

the class ComBat method plot.

/**
 * Make diagnostic plots.
 * FIXME: As in the original ComBat, this only graphs the first batch's statistics. In principle we can (and perhaps
 * should) examine these plots for all the batches.
 *
 * @param filePrefix file prefix
 */
public void plot(String filePrefix) {
    if (this.gammaHat == null)
        throw new IllegalArgumentException("You must call 'run' first");
    /*
         * View the distribution of gammaHat, which we assume will have a normal distribution
         */
    DoubleMatrix1D ghr = gammaHat.viewRow(0);
    int NUM_HIST_BINS = 100;
    Histogram gammaHatHist = new Histogram("GammaHat", NUM_HIST_BINS, ghr);
    XYSeries ghplot = gammaHatHist.plot();
    Normal rn = new Normal(this.gammaBar.get(0), Math.sqrt(this.t2.get(0)), new MersenneTwister());
    Histogram ghtheoryT = new Histogram("Gamma", NUM_HIST_BINS, gammaHatHist.min(), gammaHatHist.max());
    for (int i = 0; i < 10000; i++) {
        double n = rn.nextDouble();
        ghtheoryT.fill(n);
    }
    XYSeries ghtheory = ghtheoryT.plot();
    File tmpfile;
    try {
        tmpfile = File.createTempFile(filePrefix + ".gammahat.histogram.", ".png");
        ComBat.log.info(tmpfile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    try (OutputStream os = new FileOutputStream(tmpfile)) {
        this.writePlot(os, ghplot, ghtheory);
        /*
             * View the distribution of deltaHat, which we assume has an inverse gamma distribution
             */
        DoubleMatrix1D dhr = deltaHat.viewRow(0);
        Histogram deltaHatHist = new Histogram("DeltaHat", NUM_HIST_BINS, dhr);
        XYSeries dhplot = deltaHatHist.plot();
        Gamma g = new Gamma(aPrior.get(0), bPrior.get(0), new MersenneTwister());
        Histogram deltaHatT = new Histogram("Delta", NUM_HIST_BINS, deltaHatHist.min(), deltaHatHist.max());
        for (int i = 0; i < 10000; i++) {
            double invg = 1.0 / g.nextDouble();
            deltaHatT.fill(invg);
        }
        XYSeries dhtheory = deltaHatT.plot();
        tmpfile = File.createTempFile(filePrefix + ".deltahat.histogram.", ".png");
        ComBat.log.info(tmpfile);
        try (OutputStream os2 = new FileOutputStream(tmpfile)) {
            this.writePlot(os2, dhplot, dhtheory);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) Histogram(ubic.basecode.math.distribution.Histogram) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Normal(cern.jet.random.Normal) Gamma(cern.jet.random.Gamma) DoubleMatrix1D(cern.colt.matrix.DoubleMatrix1D) DenseDoubleMatrix1D(cern.colt.matrix.impl.DenseDoubleMatrix1D) FileOutputStream(java.io.FileOutputStream) MersenneTwister(cern.jet.random.engine.MersenneTwister) File(java.io.File)

Example 5 with MersenneTwister

use of cern.jet.random.engine.MersenneTwister in project tetrad by cmu-phil.

the class NormalityTests method getNormal.

/**
 * Generates an ideal Normal distribution for some variable.
 *
 * @return Ideal Normal distribution for a variable.
 */
private static Normal getNormal(DataSet dataSet, Variable variable) {
    double[] paramsForNormal = normalParams(dataSet, variable);
    double mean = paramsForNormal[0];
    double sd = paramsForNormal[1];
    return new Normal(mean, sd, new MersenneTwister());
}
Also used : Normal(cern.jet.random.Normal) MersenneTwister(cern.jet.random.engine.MersenneTwister)

Aggregations

MersenneTwister (cern.jet.random.engine.MersenneTwister)8 Normal (cern.jet.random.Normal)4 ChiSquare (cern.jet.random.ChiSquare)2 RandomEngine (cern.jet.random.engine.RandomEngine)2 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)1 DenseDoubleMatrix1D (cern.colt.matrix.impl.DenseDoubleMatrix1D)1 Gamma (cern.jet.random.Gamma)1 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)1 Exponential (edu.cmu.tetrad.util.dist.Exponential)1 Normal (edu.cmu.tetrad.util.dist.Normal)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 NumberFormat (java.text.NumberFormat)1 XYSeries (org.jfree.data.xy.XYSeries)1 Histogram (ubic.basecode.math.distribution.Histogram)1