Search in sources :

Example 6 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)

Example 7 with MersenneTwister

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

the class QQPlot method testPlot.

// ============================ Private Methods =======================//
/**
 * Used to test this class.
 *
 * Generates a continuous test variable and q-q plots it.
 */
private void testPlot() {
    ContinuousVariable c = new ContinuousVariable("test");
    if (dataSet.getVariable("test") == null)
        dataSet.addVariable(c);
    ContinuousVariable c2 = new ContinuousVariable("test2");
    if (dataSet.getVariable("test2") == null)
        dataSet.addVariable(c2);
    this.selectedVariable = c;
    int columnIndex = dataSet.getColumn(c);
    Normal g = new Normal(1, 1);
    Exponential e = new Exponential(1);
    double mean = 0.0;
    double sd = 0.0;
    this.minData = 10000000000000.0;
    this.maxData = 0.0;
    this.minComparison = 1000000000000.0;
    this.maxComparison = 0.0;
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        double value = g.nextRandom();
        double value2 = e.nextRandom();
        dataSet.setDouble(i, columnIndex, value);
        dataSet.setDouble(i, columnIndex + 1, value2);
        mean += value;
        if (value < this.minData)
            this.minData = value;
        if (value > this.maxData)
            this.maxData = value;
    // System.out.println(value);
    // System.out.println(mean);
    }
    // System.out.println(this.dataSet.getNumRows());
    NormalityTests.kolmogorovSmirnov(dataSet, c2);
    // sort the dataset
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        for (int k = i; k < dataSet.getNumRows(); k++) {
            if (dataSet.getDouble(i, columnIndex) > dataSet.getDouble(k, columnIndex)) {
                double temp = dataSet.getDouble(i, columnIndex);
                dataSet.setDouble(i, columnIndex, dataSet.getDouble(k, columnIndex));
                dataSet.setDouble(k, columnIndex, temp);
            }
        }
    }
    if (mean == 0.0)
        mean = 1.0;
    else
        mean /= dataSet.getNumRows();
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        sd += (dataSet.getDouble(i, columnIndex) - mean) * (dataSet.getDouble(i, columnIndex) - mean);
    // System.out.println(dataSet.getDouble(i, columnIndex));
    // System.out.println(sd);
    }
    if (sd == 0.0) {
        sd = 1.0;
    } else {
        sd /= dataSet.getNumRows() - 1.0;
        sd = Math.sqrt(sd);
    }
    // System.out.println("Mean: " + mean + " SD: " + sd + " Min: " + this.minData + " Max: " + this.maxData);
    this.comparison = new cern.jet.random.Normal(mean, sd, new MersenneTwister());
    calculateComparisonSet(this.comparison, this.dataSet);
    if (this.minData < this.minComparison)
        this.min = this.minData;
    else
        this.min = this.minComparison;
    if (this.maxData > this.maxComparison)
        this.max = this.maxData;
    else
        this.max = this.maxComparison;
// end test code
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) Exponential(edu.cmu.tetrad.util.dist.Exponential) Normal(edu.cmu.tetrad.util.dist.Normal) MersenneTwister(cern.jet.random.engine.MersenneTwister)

Example 8 with MersenneTwister

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

the class DescriptiveStats method getNormal.

/**
 * Generates an ideal Normal distribution for some variable.
 *
 * @return Ideal Normal distribution for a variable.
 */
public static Normal getNormal(double[] data) {
    double[] paramsForNormal = normalParams(data);
    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