Documenation update in statistics package.

refs #2
This commit is contained in:
Fabian Becker 2014-10-24 20:49:03 +02:00
parent 3987cd11e2
commit 6b05a71a86
5 changed files with 60 additions and 14 deletions

View File

@ -8,9 +8,7 @@ import eva2.tools.StringTools;
import eva2.tools.math.Mathematics;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.logging.Logger;
/**
@ -270,6 +268,53 @@ public class EvAStatisticalEvaluation {
return "" + t;
}
/**
* ToDo: Figure out why this gives different results than jsc.independentsamples.MannWhitneyTest#getSP
* @param field The field for which the test should be executed for.
* @param job1 First job to test
* @param job2 Second job to test
* @return
*/
private static String calculateMannWhitneyU(String field, OptimizationJob job1, OptimizationJob job2) {
double[] dat1 = job1.getDoubleDataColumn(field);
double[] dat2 = job2.getDoubleDataColumn(field);
double t = Double.NaN;
// We can't compute the MannWhitney test if one of the samples is empty
if (dat1 != null && dat2 != null) {
double n1 = dat1.length;
double n2 = dat2.length;
ArrayList<Double> sortedValues = new ArrayList<>();
// This is stupid. Find a better way.
for (Double d : dat1) {
sortedValues.add(d);
}
for (Double d : dat2) {
sortedValues.add(d);
}
Collections.sort(sortedValues);
double tA = 0.0;
for (Double value : dat1) {
tA += (sortedValues.indexOf(value) + 1.0 + sortedValues.lastIndexOf(value) + 1.0) / 2.0;;
}
double tB = 0.0;
for (Double value : dat2) {
tB += (sortedValues.indexOf(value) + 1 + sortedValues.lastIndexOf(value) + 1) / 2.0;
}
double uA = (n1 * n2) + ((0.5 * n1) * (n1 + 1.0)) - tA;
double uB = (n1 * n2) + ((0.5 * n2) * (n2 + 1.0)) - tB;
assert(uA + uB == n1 * n2);
double u = Math.min(uA, uB);
double mU = (n1 * n2) / 2;
double omegaU = Math.sqrt((n1*n2*(n1 + n2 + 1.0))/12.0);
t = (u - mU) / omegaU;
}
return "" + t;
}
private static String compare(String field, OptimizationJob job1, OptimizationJob job2) {
// TODO do some statistical test
int numRuns1 = job1.getNumRuns();

View File

@ -124,7 +124,7 @@ public class OptimizationJob implements Serializable, InterfaceStatisticsListene
return multiRunFinalObjectData;
}
public InterfaceOptimizationParameters getGOParams() {
public InterfaceOptimizationParameters getOptimizationParameters() {
return params;
}
@ -197,14 +197,15 @@ public class OptimizationJob implements Serializable, InterfaceStatisticsListene
* Retrieve a single column of double data indicated by a field name. If the field is unknown
* or there is no double data, null is returned.
*
* @param field
* @return
* @param field Field name
* @return An array of values from the field provided
*/
public double[] getDoubleDataColumn(String field) {
int index = getFieldIndex(field);
int numRuns = getNumRuns();
if (index >= 0) {
double[] data = new double[getNumRuns()];
for (int i = 0; i < getNumRuns(); i++) {
double[] data = new double[numRuns];
for (int i = 0; i < numRuns; i++) {
Object o = multiRunFinalObjectData.get(i)[index];
try {
if ((o instanceof Double)) {

View File

@ -141,7 +141,7 @@ public class OptimizationJobList extends PropertySelectableList<OptimizationJob>
*/
public OptimizationJob getJobOf(InterfaceOptimizationParameters params) {
for (OptimizationJob job : getObjects()) {
if (job.getGOParams() == params) {
if (job.getOptimizationParameters() == params) {
return job;
}
}
@ -206,7 +206,7 @@ public class OptimizationJobList extends PropertySelectableList<OptimizationJob>
if (jobs.size() == 1) {
OptimizationJob job = jobs.get(0);
AbstractOptimizationParameters curParams = (AbstractOptimizationParameters) ((AbstractModuleAdapter) jobList.module).getOptimizationParameters();
curParams.setSameParams((AbstractOptimizationParameters) job.getGOParams());
curParams.setSameParams((AbstractOptimizationParameters) job.getOptimizationParameters());
((GenericModuleAdapter) jobList.module).setOptimizationParameters(curParams);
((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameter().setMultiRuns(job.getNumRuns());
((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameter().setFieldSelection(job.getFieldSelection(((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameter().getFieldSelection()));

View File

@ -217,7 +217,7 @@ public class HillClimbing implements InterfaceOptimizer, java.io.Serializable {
*/
@Override
public String getName() {
return "MS-HC" + getIdentifier();
return "MS-HC";
}
@Override

View File

@ -683,7 +683,7 @@ public class Mathematics {
/**
* Computes the 2-norm of an array of doubles.
*
* @param doubles the array of double
* @param d the array of double
* @return the 2-norm of the elements
*/
public static double norm(double[] d) {
@ -698,7 +698,7 @@ public class Mathematics {
* Normalizes the doubles in the array by their sum, so that they add up to
* one.
*
* @param doubles the array of double
* @param d the array of double
* @throws IllegalArgumentException if sum is Zero or NaN
*/
public static double[] normalizeSum(double[] v) {
@ -711,7 +711,7 @@ public class Mathematics {
* Normalizes the doubles in the array by their sum, so that they add up to
* one.
*
* @param doubles the array of double
* @param v the array of double
* @throws IllegalArgumentException if sum is Zero or NaN
*/
public static void normalizeSum(double[] v, double[] res) {