Merge branch 'testing' into 'master'

Testing improvements

refs #53

See merge request !8
This commit is contained in:
2015-12-14 17:36:41 +01:00
16 changed files with 758 additions and 110 deletions

View File

@@ -5,30 +5,26 @@ package eva2.gui;
*/
class Mnemonic {
private char mnemonic;
private String text;
private final char mnemonic;
private final String text;
/**
*
*/
public Mnemonic(String s) {
setString(s);
}
/**
*
*/
public void setString(String s) {
StringBuilder buf = new StringBuilder(s);
char c = Character.MIN_VALUE;
for (int i = 0; i < buf.length(); i++) {
if (buf.charAt(i) == '&') {
buf.deleteCharAt(i);
i++;
if (i < buf.length() && buf.charAt(i) != '&') {
mnemonic = buf.charAt(i - 1);
c = buf.charAt(i - 1);
}
}
}
mnemonic = c;
text = buf.toString();
}

View File

@@ -1088,7 +1088,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
}
return pos;
} // TODO check some more types here?
EVAERROR.errorMsgOnce("Unhandled case in AbstractEAIndividual.getPosition()!");
EVAERROR.errorMsgOnce("Unhandled case in AbstractEAIndividual.getDoublePositionShallow()!");
return null;
}

View File

@@ -13,12 +13,15 @@ import eva2.tools.math.RNG;
import eva2.util.annotation.Description;
import eva2.util.annotation.Hidden;
import java.util.logging.Logger;
/**
* This individual uses a real-valued genotype to code for double values.
*/
@Description(value = "This is an ES individual suited to optimize double values.")
public class ESIndividualDoubleData extends AbstractEAIndividual implements InterfaceESIndividual, InterfaceDataTypeDouble, java.io.Serializable {
private static final Logger LOGGER = Logger.getLogger(ESIndividualDoubleData.class.getName());
private double[] genotype;
private double[] phenotype;
private double[][] range;
@@ -46,7 +49,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
this.genotype[i] = individual.genotype[i];
this.range[i][0] = individual.range[i][0];
this.range[i][1] = individual.range[i][1];
}
};
// cloning the members of AbstractEAIndividual
this.age = individual.age;
@@ -108,7 +111,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
/**
* This method allows you to request a certain amount of double data
*
* @param length The lenght of the double[] that is to be optimized
* @param length The length of the double[] that is to be optimized
*/
@Override
public void setDoubleDataLength(int length) {
@@ -154,7 +157,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
@Hidden
public void setDoubleRange(double[][] range) {
if (range.length != this.range.length) {
System.out.println("Warning: Trying to set a range of length " + range.length + " to a vector of length "
LOGGER.warning("Trying to set a range of length " + range.length + " to a vector of length "
+ this.range.length + "!\n Use method setDoubleDataLength first! (ESIndividualDoubleData:setDoubleRange)");
}
for (int i = 0; ((i < this.range.length) && (i < range.length)); i++) {
@@ -209,7 +212,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
/**
* This method allows you to set the phenotype double data. To change the genotype,
* use SetDoubleDataLamarckian().
* use #setDoubleDataLamarckian().
*
* @param doubleData The new double data.
*/
@@ -226,7 +229,6 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
*/
@Override
public void setDoubleGenotype(double[] doubleData) {
// this.setDoublePhenotype(doubleData);
this.setDoublePhenotype(null); // tag it as invalid
this.genotype = new double[doubleData.length];
System.arraycopy(doubleData, 0, this.genotype, 0, doubleData.length);
@@ -271,7 +273,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
/**
* This method will return a string description of the GAIndividal
* noteably the Genotype.
* notably the Genotype.
*
* @return A descriptive string
*/
@@ -390,7 +392,7 @@ public class ESIndividualDoubleData extends AbstractEAIndividual implements Inte
}
/**
* This method allows the CommonJavaObjectEditorPanel to read the
* This method allows the ObjectEditorPanel to read the
* name to the current object.
*
* @return The name.

View File

@@ -2,7 +2,7 @@ package eva2.optimization.individuals;
/**
* This interface gives access to a real-valued genotype and should
* only be used by mutation and crossover operators. Onyl exception are
* only be used by mutation and crossover operators. Only exception are
* data type specific optimization strategies like PSO or DE.
*/
public interface InterfaceESIndividual {

View File

@@ -305,8 +305,8 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
/**
* This method calculates the distance between two double values
*
* @param d1
* @param d2
* @param indy
* @param p
* @return The scalar distances between d1 and d2
*/
private double distance(AbstractEAIndividual indy, double[] p) {
@@ -357,19 +357,8 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
return metric.distance(species1.getBestEAIndividual(), species2.getBestEAIndividual()) < mergeDist;
}
// /** This method decides if a unclustered individual belongs to an already established species.
// * @param indy A unclustered individual.
// * @param species A species.
// * @return True or False.
// */
// public boolean belongsToSpecies(AbstractEAIndividual indy, Population species, Population pop) {
// // @todo perhaps the same as in convergingSpecies
// return false;
// }
@Override
public int[] associateLoners(Population loners, Population[] species, Population referencePop) {
// tmpIndy = (AbstractEAIndividual)loners.getEAIndividual(0).clone();
int[] res = new int[loners.size()];
System.err.println("Warning, associateLoners not implemented for " + this.getClass());
Arrays.fill(res, -1);
@@ -413,7 +402,7 @@ public class ClusteringKMeans implements InterfaceClustering, java.io.Serializab
/**
* This method allows you to set/get the number of
* clusters tofind
* clusters to find
*
* @return The current number of clusters to find.
*/

View File

@@ -24,7 +24,7 @@ public class MOSONoConvert implements InterfaceMOSOConverter, java.io.Serializab
/**
* This method takes a population of individuals with an array of
* fitness values and calculates a single fitness value to replace
* the former fitness array. Please note: The orignal fitness values
* the former fitness array. Please note: The original fitness values
* are lost this way, so please use the individual.setData() method
* if you still want to access the original fitness values.
*

View File

@@ -163,7 +163,6 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
}
Population sols = allSolutions.getSolutions();
for (int i = 0; i < sols.size(); i++) {
// addPopulation(allSolutions.getSolutions());
if (!checkCols.containsKey(sols.getEAIndividual(i).getIndyID())) {
add(sols.getEAIndividual(i));
}
@@ -376,7 +375,7 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
this.historyList = new LinkedList<>();
this.generationCount = 0;
this.functionCallCount = 0;
double[] popSeed = null;
double[] popSeed;
if (this.populationArchive != null) {
this.populationArchive.clear();
this.populationArchive.initialize();
@@ -1850,7 +1849,8 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
/**
* Returns the average, minimal and maximal individual distance as diversity
* measure for the population. If the given metric argument is null, the
* euclidian distance of individual positions is used, which presumes that {@link eva2.optimization.individuals.AbstractEAIndividual#getDoublePosition(eva2.optimization.individuals.AbstractEAIndividual)}
* euclidean distance of individual positions is used, which presumes that
* {@link AbstractEAIndividual#getDoublePosition(AbstractEAIndividual)}
* returns a valid double position for the individuals of the population.
* This is of course rather expensive computationally.
*
@@ -1858,7 +1858,6 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
* an array of three
*/
public double[] getPopulationMeasures(InterfaceDistanceMetric metric) {
double[] res = getPopulationMeasures(this, metric);
return res;
}
@@ -1866,7 +1865,8 @@ public class Population extends ArrayList<AbstractEAIndividual> implements Popul
/**
* Returns the average, minimal and maximal individual distance as diversity
* measure for the population. If the given metric argument is null, the
* euclidian distance of individual positions is used, which presumes that {@link AbstractEAIndividual#getDoublePosition(eva2.optimization.individuals.AbstractEAIndividual)}
* euclidean distance of individual positions is used, which presumes that
* {@link AbstractEAIndividual#getDoublePosition(AbstractEAIndividual)}
* returns a valid double position for the individuals of the population.
* This is of course rather expensive computationally.
*

View File

@@ -198,7 +198,7 @@ public class StatisticalEvaluation {
double[] dat = job1.getDoubleDataColumn(field);
double median = Double.NaN;
if (dat != null) {
median = Mathematics.median2(dat, true);
median = Mathematics.median(dat, true);
median = StatisticalEvaluation.formatOutput(median);
}

View File

@@ -31,7 +31,7 @@ public final class ToolBox {
ret[i] = fields[i].toString();
}
System.arraycopy(additionalValues, enumLen - enumLen, ret, enumLen, ret.length - enumLen);
System.arraycopy(additionalValues, 0, ret, enumLen, ret.length - enumLen);
return ret;
}

View File

@@ -389,8 +389,8 @@ public final class Mathematics {
/**
* Intersect two ranges resulting in the maximum range contained in both.
*
* @param modRange
* @param makeRange
* @param r1
* @param r2
* @param destRange
*/
public static void intersectRange(double[][] r1, double[][] r2,
@@ -475,8 +475,9 @@ public final class Mathematics {
* Check whether the given value lies within the interval in every
* dimension.
*
* @param x
* @param range
* @param v Value
* @param lower Lower bound
* @param upper Upper bound
* @return true if the vector lies within the range, else false
*/
public static boolean isInRange(double v, double lower, double upper) {
@@ -507,8 +508,8 @@ public final class Mathematics {
* @return
*/
public static boolean isValidVec(double[][] d) {
for (int i = 0; i < d.length; i++) {
if (!isValidVector(d[i])) {
for (double[] vec : d) {
if (!isValidVector(vec)) {
return false;
}
}
@@ -537,6 +538,8 @@ public final class Mathematics {
}
/**
* Linear interpolation between two points
*
* @param f0
* @param f1
* @param t
@@ -552,7 +555,7 @@ public final class Mathematics {
*
* @param x The argument at the point with unknown function value
* @param x0 The argument at the last position with a function value
* @param x1 The argument at the next known fuction value
* @param x1 The argument at the next known function value
* @param f0 The function value at the position x0
* @param f1 The function value at the position x1
* @return The function value at position x given by linear interpolation.
@@ -621,16 +624,18 @@ public final class Mathematics {
in = x;
}
if (in.length == 1) {
Arrays.sort(in);
if (in.length == 0) {
return Double.NaN;
} else if (in.length == 1) {
return in[0];
} else if (in.length == 2) {
return (in[0] + in[1]) / 2.;
} else {
Arrays.sort(in);
if (in.length % 2 != 0) {
return in[(in.length - 1) / 2];
if (in.length % 2 == 1) {
return in[in.length / 2];
} else {
return (in[in.length / 2] + in[(in.length / 2) + 1]) / 2.;
return (in[in.length / 2 - 1] + in[in.length / 2]) / 2.;
}
}
}
@@ -663,21 +668,6 @@ public final class Mathematics {
}
}
public static double median2(double[] vector, boolean clone) {
double[] in;
if (clone) {
in = vector.clone();
} else {
in = vector;
}
if (in.length == 0) {
return 0;
}
Arrays.sort(in);
return in[(int) Math.floor(((double) in.length) / 2.0)];
}
public static double variance(double[] vector) {
double mean = Mathematics.mean(vector);
double result = 0.0;
@@ -787,7 +777,7 @@ public final class Mathematics {
}
/**
* Normalize the given vector to an euclidian length of 1.
* Normalize the given vector to a euclidean length of 1.
*
* @param v
* @return
@@ -797,7 +787,7 @@ public final class Mathematics {
}
/**
* Normalize the given vector to an euclidian length of 1.
* Normalize the given vector to a euclidean length of 1.
*
* @param v
* @return
@@ -821,7 +811,7 @@ public final class Mathematics {
}
/**
* Project the values in x to the range given. The range must be an vector
* Project the values in x to the range given. The range must be a vector
* of 2d-arrays each of which containing lower and upper bound in the i-th
* dimension. x must not be longer than the available ranges. Values
* exceeding the bounds are set on the bound. The number of bound violations
@@ -851,9 +841,9 @@ public final class Mathematics {
/**
* Project the value to the range given.
*
* @param v
* @param min
* @param max
* @param v Value
* @param min Lower bound
* @param max Upper bound
* @return the closest value to v within [min,max]
*/
public static double projectValue(double v, double min, double max) {
@@ -943,7 +933,7 @@ public final class Mathematics {
if ((val + step) < min) {
return (2 * min - val - step);
}
return (val += step);
return val + step;
}
/**
@@ -954,7 +944,7 @@ public final class Mathematics {
*
* @param x A vector
* @param y The reference vector
* @param def The default value to be use to avoid division by zero.
* @param def The default value to be used to avoid division by zero.
* @return The relative distance of x to y.
* @throws Exception
*/
@@ -997,8 +987,8 @@ public final class Mathematics {
/**
* Rotate the vector by angle alpha around axis i/j
*
* @param vect
* @param alpha
* @param vect Vector
* @param alpha Rotation angle
* @param i
* @param j
*/
@@ -1013,8 +1003,8 @@ public final class Mathematics {
* Rotate a given double vector using a rotation matrix. If the matrix is
* null, x will be returned unchanged. Matrix dimensions must fit.
*
* @param x
* @param rotMatrix
* @param x Vector
* @param rotMatrix Rotation matrix
* @return the rotated vector
*/
public static double[] rotate(double[] x, Matrix rotMatrix) {
@@ -1087,6 +1077,7 @@ public final class Mathematics {
* Shift bounds by a constant value in every dimension.
*
* @param range
* @param dist
* @return
*/
public static void shiftRange(double[][] range, double dist) {
@@ -1183,7 +1174,6 @@ public final class Mathematics {
* @return the sum of the elements
*/
public static int sum(int[] ints) {
int sum = 0;
for (int value : ints) {
@@ -1208,8 +1198,8 @@ public final class Mathematics {
/**
* Add each entry of a vector with a scalar in a result vector.
*
* @param s
* @param v
* @param s Scalar
* @param v Vector
* @return
*/
public static void svAdd(double s, double[] v, double[] res) {
@@ -1227,9 +1217,7 @@ public final class Mathematics {
*/
public static double[] svDiv(double s, double[] v) {
double[] res = new double[v.length];
for (int i = 0; i < v.length; i++) {
res[i] = v[i] / s;
}
svDiv(s, v, res);
return res;
}
@@ -1256,9 +1244,7 @@ public final class Mathematics {
*/
public static double[] svMult(double s, double[] v) {
double[] res = new double[v.length];
for (int i = 0; i < v.length; i++) {
res[i] = v[i] * s;
}
svMult(s, v, res);
return res;
}
@@ -1267,7 +1253,6 @@ public final class Mathematics {
*
* @param s a scalar
* @param v an array to be multiplied with s.
* @return a scaled array.
*/
public static void svMult(double s, double[] v, double[] res) {
for (int i = 0; i < v.length; i++) {
@@ -1278,7 +1263,7 @@ public final class Mathematics {
/**
* Add vectors scaled: res[i] = s*v[i] + w[i]
*
* @param s
* @param s Scaling factor
* @param v
* @param w
* @return
@@ -1308,8 +1293,8 @@ public final class Mathematics {
/**
* Add vectors returning a new vector c = a + b;
*
* @param a
* @param b
* @param a Vector 1
* @param b Vector 2
* @return a new vector c = a + b
*/
public static double[] vvAdd(double[] a, double[] b) {

View File

@@ -0,0 +1,12 @@
<html>
<head>
<title>Differential Evolution - DE</title>
</head>
<body>
<h1 align="center">Differential Evolution - DE</h1>
<center>
</center><br>
Description of DE.
<br>
</body>
</html>