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