use of org.apache.commons.math3.stat.descriptive.rank.Min in project vcell by virtualcell.
the class TimeSeriesMultitrialData method kolmogorovSmirnovTest.
public static double kolmogorovSmirnovTest(double[] rawData1, double[] rawData2) {
try {
int numBins = 1 + (int) Math.ceil(Math.sqrt(rawData1.length));
// rawData2 = ramp(0,10,rawData2.length);
Max max = new Max();
max.incrementAll(rawData1);
max.incrementAll(rawData2);
Min min = new Min();
min.incrementAll(rawData1);
min.incrementAll(rawData2);
double[] cdf1 = calculateCDF(rawData1, min.getResult(), max.getResult(), numBins);
double[] cdf2 = calculateCDF(rawData2, min.getResult(), max.getResult(), numBins);
KolmogorovSmirnovTest test = new KolmogorovSmirnovTest();
return test.kolmogorovSmirnovStatistic(cdf1, cdf2);
} catch (Exception e) {
e.printStackTrace(System.out);
return -1;
}
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project vcell by virtualcell.
the class TimeSeriesMultitrialData method chiSquaredTest.
public static double chiSquaredTest(double[] rawData1, double[] rawData2) {
try {
int numBins = 1 + (int) Math.ceil(Math.sqrt(rawData1.length));
// rawData2 = ramp(0,10,rawData2.length);
TimeSeriesMultitrialData.MinMaxHelp minMaxHelp1 = new TimeSeriesMultitrialData.MinMaxHelp(rawData1);
TimeSeriesMultitrialData.MinMaxHelp minMaxHelp2 = new TimeSeriesMultitrialData.MinMaxHelp(rawData2);
double min = Math.min(minMaxHelp1.min, minMaxHelp2.min);
double max = Math.max(minMaxHelp1.max, minMaxHelp2.max);
long[] histogram1 = calcHistogram(rawData1, min, max, numBins);
long[] histogram2 = calcHistogram(rawData2, min, max, numBins);
//
// remove histogram indices where both bins are zero
//
ArrayList<Long> histogram1List = new ArrayList<Long>();
ArrayList<Long> histogram2List = new ArrayList<Long>();
for (int i = 0; i < histogram1.length; i++) {
if (histogram1[i] != 0 || histogram2[i] != 0) {
histogram1List.add(histogram1[i]);
histogram2List.add(histogram2[i]);
// }else{
// histogram1List.add(new Long(1));
// histogram2List.add(new Long(1));
}
}
histogram1 = new long[histogram1List.size()];
histogram2 = new long[histogram2List.size()];
for (int i = 0; i < histogram1List.size(); i++) {
histogram1[i] = histogram1List.get(i);
histogram2[i] = histogram2List.get(i);
}
if (histogram1.length == 1) {
return 0.0;
}
ChiSquareTest chiSquareTest = new ChiSquareTest();
return chiSquareTest.chiSquareTestDataSetsComparison(histogram1, histogram2);
} catch (Exception e) {
e.printStackTrace(System.out);
return -1;
}
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project tetrad by cmu-phil.
the class SemOptimizerPowell method optimize.
// =========================PUBLIC METHODS==========================//
public void optimize(SemIm semIm) {
double min = Double.POSITIVE_INFINITY;
double[] point = null;
for (int count = 0; count < numRestarts + 1; count++) {
// System.out.println("Trial " + (count + 1));
SemIm _sem2 = new SemIm(semIm);
List<Parameter> freeParameters = _sem2.getFreeParameters();
double[] p = new double[freeParameters.size()];
for (int i = 0; i < freeParameters.size(); i++) {
if (freeParameters.get(i).getType() == ParamType.VAR) {
p[i] = RandomUtil.getInstance().nextUniform(0, 1);
} else {
p[i] = RandomUtil.getInstance().nextUniform(-1, 1);
}
}
_sem2.setFreeParamValues(p);
MultivariateOptimizer search = new PowellOptimizer(1e-7, 1e-7);
PointValuePair pair = search.optimize(new InitialGuess(_sem2.getFreeParamValues()), new ObjectiveFunction(fittingFunction(semIm)), GoalType.MINIMIZE, new MaxEval(100000));
double chisq = _sem2.getChiSquare();
if (chisq < min) {
min = chisq;
point = pair.getPoint();
}
}
if (point == null) {
throw new NullPointerException("Point could not be found.");
}
System.arraycopy(point, 0, semIm.getFreeParamValues(), 0, point.length);
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project FSensor by KalebKE.
the class CalibrationUtil method getCalibration.
/**
* Transforms the ellipsoid into a sphere with the offset vector = [0,0,0]
* and the radii vector = [1,1,1].
*
* @param fitPoints the representation of the calibration ellipsoid
*/
public static Calibration getCalibration(FitPoints fitPoints) {
// The scalar values to transform the radii vector into [1,1,1]
RealMatrix scalar = new Array2DRowRealMatrix(3, 3);
// RIV determines the magnitude of the radii. We have to know the
// magnitudes because the eigenvalues, and thus the radii, are returned
// in ascending order. Without knowing the magnitudes, we wouldn't know
// what radii to apply to what axis.
// Find the max and minimum magnitudes.
double max = fitPoints.riv.getEntry(0);
double min = fitPoints.riv.getEntry(0);
// The indexes of the maximum, median, and minimum radii.
// Note that these are the opposite of the max and min
// because a smaller riv value means a greater magnitude.
int maxi = 0, midi = 0, mini = 0;
// Find max and min radii
for (int i = 0; i < fitPoints.riv.getDimension(); i++) {
if (fitPoints.riv.getEntry(i) > max) {
max = fitPoints.riv.getEntry(i);
mini = i;
}
if (fitPoints.riv.getEntry(i) < min) {
min = fitPoints.riv.getEntry(i);
maxi = i;
}
}
// Find median radii
for (int i = 0; i < fitPoints.riv.getDimension(); i++) {
if (fitPoints.riv.getEntry(i) < max && fitPoints.riv.getEntry(i) > min) {
midi = i;
}
}
// Create the scalar vector in the correct orientation.
scalar.setEntry(0, 0, 1 / fitPoints.radii.getEntry(mini));
scalar.setEntry(1, 1, 1 / fitPoints.radii.getEntry(midi));
scalar.setEntry(2, 2, 1 / fitPoints.radii.getEntry(maxi));
return new Calibration(scalar, fitPoints.center);
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project narchy by automenta.
the class Optimize method solve.
public void solve(int dim, ObjectiveFunction func, double[] mid, double[] min, double[] max, double[] inc, int maxIterations) {
if (dim == 1) {
// use a solver capable of 1 dim
new SimplexOptimizer(1e-10, 1e-30).optimize(new MaxEval(maxIterations), func, GoalType.MAXIMIZE, new InitialGuess(mid), // new NelderMeadSimplex(inc)
new MultiDirectionalSimplex(inc));
} else {
int popSize = // 4 + 3 ln(n)
(int) Math.ceil(4 + 3 * Math.log(tweaks.size()));
double[] sigma = MathArrays.scale(1f, inc);
MyCMAESOptimizer m = new MyCMAESOptimizer(maxIterations, Double.NaN, true, 0, 1, new MersenneTwister(System.nanoTime()), true, null, popSize, sigma);
m.optimize(func, GoalType.MAXIMIZE, new MaxEval(maxIterations), new SimpleBounds(min, max), new InitialGuess(mid));
m.print(System.out);
// final int numIterpolationPoints = 3 * dim; //2 * dim + 1 + 1;
// new BOBYQAOptimizer(numIterpolationPoints,
// dim * 2.0,
// 1.0E-4D /* ? */).optimize(
// MaxEval.unlimited(), //new MaxEval(maxIterations),
// new MaxIter(maxIterations),
// func,
// GoalType.MAXIMIZE,
// new SimpleBounds(min, max),
// new InitialGuess(mid));
}
}
Aggregations