DGrid bug cleared (merging mk branch revs. 315-317).
This commit is contained in:
parent
d8fbb01e29
commit
61a6c4649e
@ -68,7 +68,7 @@ public class CrossoverESPCX implements InterfaceCrossover, java.io.Serializable
|
|||||||
System.arraycopy(((InterfaceESIndividual)result[i]).getDGenotype(), 0, children[i], 0, parents[i].length);
|
System.arraycopy(((InterfaceESIndividual)result[i]).getDGenotype(), 0, children[i], 0, parents[i].length);
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] g = Mathematics.getMeanVector(parents), tmpD;
|
double[] g = Mathematics.meanVect(parents), tmpD;
|
||||||
double w, v;
|
double w, v;
|
||||||
ArrayList subSpace;
|
ArrayList subSpace;
|
||||||
// now determine the offsprings
|
// now determine the offsprings
|
||||||
|
@ -67,7 +67,7 @@ public class CrossoverESSPX implements InterfaceCrossover, java.io.Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
double r;
|
double r;
|
||||||
double[] g = Mathematics.getMeanVector(parents);
|
double[] g = Mathematics.meanVect(parents);
|
||||||
double[][] Y = new double[parents.length][], C;
|
double[][] Y = new double[parents.length][], C;
|
||||||
|
|
||||||
// calculate the Y vectors
|
// calculate the Y vectors
|
||||||
|
@ -72,7 +72,7 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
|
|||||||
for (int i = 1; i < parents.length; i++) {
|
for (int i = 1; i < parents.length; i++) {
|
||||||
nParents[i-1] = parents[i];
|
nParents[i-1] = parents[i];
|
||||||
}
|
}
|
||||||
double[] g = Mathematics.getMeanVector(nParents), tmpD;
|
double[] g = Mathematics.meanVect(nParents), tmpD;
|
||||||
double w, v;
|
double w, v;
|
||||||
ArrayList givenCoordinates = this.getGivenCoordinates(g, nParents);
|
ArrayList givenCoordinates = this.getGivenCoordinates(g, nParents);
|
||||||
ArrayList missingCorrdinates = this.getMissingCoordinates(g, parents[0], givenCoordinates);
|
ArrayList missingCorrdinates = this.getMissingCoordinates(g, parents[0], givenCoordinates);
|
||||||
|
64
src/eva2/server/go/tools/DoubleArrayComparator.java
Normal file
64
src/eva2/server/go/tools/DoubleArrayComparator.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package eva2.server.go.tools;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
import eva2.server.go.individuals.AbstractEAIndividual;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comparator implementation which compares two double arrays.
|
||||||
|
* It assigns -1 if first is pareto dominant (smaller), 1 if second is pareto dominant (larger), 0 if the two ind.s
|
||||||
|
* are not comparable.
|
||||||
|
* If a criterion>=0 is specified, only the thereby indexed entry of any array
|
||||||
|
* will be used for comparison (single criterion case).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DoubleArrayComparator implements Comparator<Object> {
|
||||||
|
int fitCriterion = -1;
|
||||||
|
|
||||||
|
public DoubleArrayComparator() {
|
||||||
|
this(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic constructor.
|
||||||
|
*
|
||||||
|
* @param fitnessCriterion
|
||||||
|
*/
|
||||||
|
public DoubleArrayComparator(int criterion) {
|
||||||
|
fitCriterion = criterion;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DoubleArrayComparator(DoubleArrayComparator o) {
|
||||||
|
fitCriterion = o.fitCriterion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object clone() {
|
||||||
|
return new DoubleArrayComparator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two double arrays based on dominance, return -1 if the first is dominant, 1 if the second is dominant, 0 if they
|
||||||
|
* are not comparable.
|
||||||
|
*
|
||||||
|
* @see #AbstractEAIndividual.isDominatingFitness(double[], double[])
|
||||||
|
* @param o1 the first double[] to compare
|
||||||
|
* @param o2 the second double[] to compare
|
||||||
|
* @return -1 if the first is dominant, 1 if the second is dominant, otherwise 0
|
||||||
|
*/
|
||||||
|
public int compare(Object o1, Object o2) {
|
||||||
|
boolean o1domO2, o2domO1;
|
||||||
|
|
||||||
|
double[] fit1 = (double[])o1;
|
||||||
|
double[] fit2 = (double[])o2;
|
||||||
|
if (fitCriterion < 0) {
|
||||||
|
o1domO2 = AbstractEAIndividual.isDominatingFitness(fit1, fit2);
|
||||||
|
o2domO1 = AbstractEAIndividual.isDominatingFitness(fit2, fit1);
|
||||||
|
} else {
|
||||||
|
if (fit1[fitCriterion] == fit2[fitCriterion]) return 0;
|
||||||
|
else return (fit1[fitCriterion] < fit2[fitCriterion]) ? -1 : 1;
|
||||||
|
}
|
||||||
|
if (o1domO2 ^ o2domO1) return (o1domO2 ? -1 : 1);
|
||||||
|
else return 0; // these are not comparable
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package eva2.tools;
|
package eva2.tools;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import eva2.server.go.individuals.InterfaceDataTypeDouble;
|
|
||||||
|
|
||||||
import wsi.ra.math.RNG;
|
import wsi.ra.math.RNG;
|
||||||
import wsi.ra.math.Jama.Matrix;
|
import wsi.ra.math.Jama.Matrix;
|
||||||
import wsi.ra.math.interpolation.BasicDataSet;
|
import wsi.ra.math.interpolation.BasicDataSet;
|
||||||
import wsi.ra.math.interpolation.InterpolationException;
|
import wsi.ra.math.interpolation.InterpolationException;
|
||||||
import wsi.ra.math.interpolation.SplineInterpolation;
|
import wsi.ra.math.interpolation.SplineInterpolation;
|
||||||
|
import eva2.server.go.tools.DoubleArrayComparator;
|
||||||
|
|
||||||
//created at June 27 2006
|
//created at June 27 2006
|
||||||
|
|
||||||
@ -16,15 +16,6 @@ import wsi.ra.math.interpolation.SplineInterpolation;
|
|||||||
* @author Andreas Dräger
|
* @author Andreas Dräger
|
||||||
*/
|
*/
|
||||||
public class Mathematics {
|
public class Mathematics {
|
||||||
|
|
||||||
public static void main(String args[]) {
|
|
||||||
int i = 0;
|
|
||||||
double y[] = new double[args.length];
|
|
||||||
for (; i < args.length; i++)
|
|
||||||
y[i] = Double.parseDouble(args[i]);
|
|
||||||
System.out.println(median(y) / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void revertArray(Object[] src, Object[] dst) {
|
public static void revertArray(Object[] src, Object[] dst) {
|
||||||
if (dst.length>=src.length) {
|
if (dst.length>=src.length) {
|
||||||
for (int i=0; i<src.length; i++) {
|
for (int i=0; i<src.length; i++) {
|
||||||
@ -34,17 +25,46 @@ public class Mathematics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the median of a given double vector.
|
* Computes the median of a given double vector by sorting x.
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x a vector of doubles
|
||||||
* a vector of doubles
|
* @param cloneX flag whether x should be cloned before sorting.
|
||||||
* @return the median
|
* @return the median
|
||||||
*/
|
*/
|
||||||
public static double median(double[] x) {
|
public static double median(double[] x, boolean cloneX) {
|
||||||
if (x.length == 1) return x[0];
|
double[] in;
|
||||||
Arrays.sort(x);
|
if (cloneX) in = (double[]) x.clone();
|
||||||
if (x.length % 2 == 0) return x[(x.length + 1) / 2];
|
else in = x;
|
||||||
return (x[x.length / 2] + x[x.length / 2 + 1]) / 2;
|
|
||||||
|
Arrays.sort(in);
|
||||||
|
if (in.length % 2 != 0) return in[(in.length-1) / 2];
|
||||||
|
else return (in[in.length/2] + in[(in.length/2)+1]) / 2.;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the median of a given list of double vectors by sorting it.
|
||||||
|
* If the size is even, no direct median is defined - in that case it may be
|
||||||
|
* interpolated by the two closest elements or one of them may be selected (always
|
||||||
|
* the smaller one depending on the comparator.
|
||||||
|
*
|
||||||
|
* @see #DoubleArrayComparator
|
||||||
|
* @param dblArrList a list of double vectors
|
||||||
|
* @param interpolate flag whether, for even size, the median is interpolated
|
||||||
|
* @return the median
|
||||||
|
*/
|
||||||
|
public static double[] median(List<double[]> dblArrList, boolean interpolate) {
|
||||||
|
java.util.Collections.sort(dblArrList, new DoubleArrayComparator());
|
||||||
|
|
||||||
|
int len = dblArrList.size();
|
||||||
|
if (len % 2 != 0) return dblArrList.get((len-1) / 2);
|
||||||
|
else {
|
||||||
|
double[] med = dblArrList.get(len/2).clone();
|
||||||
|
if (interpolate) {
|
||||||
|
vvAdd(med, dblArrList.get((len/2)+1), med);
|
||||||
|
svDiv(2, med, med);
|
||||||
|
}
|
||||||
|
return med;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,7 +346,7 @@ public class Mathematics {
|
|||||||
* @param d d[i] the vectors, d[i][j] the jth coordinate of the ith vector
|
* @param d d[i] the vectors, d[i][j] the jth coordinate of the ith vector
|
||||||
* @return The mean vector.
|
* @return The mean vector.
|
||||||
*/
|
*/
|
||||||
public static double[] getMeanVector(double[][] d) {
|
public static double[] meanVect(double[][] d) {
|
||||||
double[] result = new double[d[0].length];
|
double[] result = new double[d[0].length];
|
||||||
for (int i = 0; i < d.length; i++) {
|
for (int i = 0; i < d.length; i++) {
|
||||||
for (int j = 0; j < d[i].length; j++) {
|
for (int j = 0; j < d[i].length; j++) {
|
||||||
@ -948,4 +968,35 @@ public class Mathematics {
|
|||||||
return (2 * min - val - step);
|
return (2 * min - val - step);
|
||||||
return (val += step);
|
return (val += step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return first multiple of interval which is larger than len.
|
||||||
|
*
|
||||||
|
* @param len
|
||||||
|
* @param interval
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static double firstMultipleAbove(double len, double interval) {
|
||||||
|
double startVal,dn = (len / interval );
|
||||||
|
startVal = Math.round(dn-0.5)*interval;
|
||||||
|
|
||||||
|
if( startVal < len || (len==0)) {
|
||||||
|
startVal+=interval;
|
||||||
|
}
|
||||||
|
return startVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the product over a double vector.
|
||||||
|
* @param vals
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static double product(double[] vals) {
|
||||||
|
double prod=1.;
|
||||||
|
for (int i = 0; i < vals.length; i++) {
|
||||||
|
prod*=vals[i];
|
||||||
|
}
|
||||||
|
return prod;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ package wsi.ra.chart2d;
|
|||||||
import java.awt.Color ;
|
import java.awt.Color ;
|
||||||
import java.awt.Graphics ;
|
import java.awt.Graphics ;
|
||||||
|
|
||||||
|
import eva2.tools.Mathematics;
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* CLASS DECLARATION
|
* CLASS DECLARATION
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@ -94,12 +96,14 @@ public class DGrid extends DComponent
|
|||||||
DPoint p1, p2;
|
DPoint p1, p2;
|
||||||
DLine l;
|
DLine l;
|
||||||
|
|
||||||
minX = (int)( rectangle.x / hor_dist );
|
minX=Mathematics.firstMultipleAbove(rectangle.x, hor_dist);
|
||||||
if( minX * hor_dist <= rectangle.x ) minX++;
|
minY=Mathematics.firstMultipleAbove(rectangle.y, ver_dist);
|
||||||
minX *= hor_dist;
|
// minX = (int)( rectangle.x / hor_dist );
|
||||||
minY = ( rectangle.y / ver_dist );
|
// if( minX * hor_dist <= rectangle.x ) minX++;
|
||||||
if( minY * ver_dist <= rectangle.y ) minY++;
|
// minX *= hor_dist;
|
||||||
minY *= ver_dist;
|
// minY = (int)( rectangle.y / ver_dist );
|
||||||
|
// if( minY * ver_dist <= rectangle.y ) minY++;
|
||||||
|
// minY *= ver_dist;
|
||||||
|
|
||||||
p1 = new DPoint( 0, rectangle.y );
|
p1 = new DPoint( 0, rectangle.y );
|
||||||
p2 = new DPoint( 0, rectangle.y + rectangle.height );
|
p2 = new DPoint( 0, rectangle.y + rectangle.height );
|
||||||
@ -127,16 +131,6 @@ public class DGrid extends DComponent
|
|||||||
public String toString(){
|
public String toString(){
|
||||||
return "chart2d.DGrid[ hor: "+hor_dist+", ver: "+ver_dist+" ]";
|
return "chart2d.DGrid[ hor: "+hor_dist+", ver: "+ver_dist+" ]";
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void updateDistByRect(DRectangle rect) {
|
|
||||||
// System.out.println(rect);
|
|
||||||
// if (!rect.isEmpty() && (hor_dist>0 && ver_dist>0)) {
|
|
||||||
// double horRatio = Math.abs(rectangle.x)/hor_dist;
|
|
||||||
// double verRatio = Math.abs(rectangle.y)/ver_dist;
|
|
||||||
//// rectangle = visRect;
|
|
||||||
// setDistances(rect.x*horRatio, rect.y*verRatio);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -3,6 +3,9 @@ package wsi.ra.chart2d;
|
|||||||
import java.awt.* ;
|
import java.awt.* ;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.border.* ;
|
import javax.swing.border.* ;
|
||||||
|
|
||||||
|
import eva2.tools.Mathematics;
|
||||||
|
|
||||||
import java.awt.geom.AffineTransform ;
|
import java.awt.geom.AffineTransform ;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
@ -291,16 +294,19 @@ public class ScaledBorder implements Border
|
|||||||
|
|
||||||
FontMetrics fm = g.getFontMetrics();
|
FontMetrics fm = g.getFontMetrics();
|
||||||
int fontAsc = fm.getAscent(), v2m = fm.stringWidth("0") / y_values2marker;
|
int fontAsc = fm.getAscent(), v2m = fm.stringWidth("0") / y_values2marker;
|
||||||
int n = (int)( src_rect.y / src_dY );
|
|
||||||
// if( n * src_dY < src_rect.y || ( src_rect.x == 0 && src_rect.y == 0 ) ) n++;
|
// double startVal,dn = (src_rect.y / src_dY );
|
||||||
if( n * src_dY < src_rect.y || ( src_rect.x == 0 && src_rect.y == 0 ) ) {
|
// startVal = Math.round(dn-0.5)*src_dY;
|
||||||
if (n+1 > n) n++;
|
//
|
||||||
else System.err.println("Overflow error A in ScaledBorder!");
|
// if( startVal < src_rect.y || ( src_rect.x == 0 && src_rect.y == 0 ) ) {
|
||||||
}
|
// startVal+=src_dY;
|
||||||
|
// }
|
||||||
|
|
||||||
|
double startVal = Mathematics.firstMultipleAbove(src_rect.y, src_dY);
|
||||||
|
|
||||||
double v, scaledV, minx = src_rect.x;
|
double v, scaledV, minx = src_rect.x;
|
||||||
if( x_scale != null ) minx = x_scale.getImageOf( minx );
|
if( x_scale != null ) minx = x_scale.getImageOf( minx );
|
||||||
v = n * src_dY;
|
v = startVal;
|
||||||
while (v <= src_rect.y + src_rect.height){
|
while (v <= src_rect.y + src_rect.height){
|
||||||
if( y_scale != null ) scaledV = y_scale.getImageOf( v );
|
if( y_scale != null ) scaledV = y_scale.getImageOf( v );
|
||||||
else scaledV=v;
|
else scaledV=v;
|
||||||
@ -333,6 +339,7 @@ public class ScaledBorder implements Border
|
|||||||
double minsrc_dY = 2 * src_rect.height / (double)max; // die 2 einfach mal so eingesetzt <--------------------------
|
double minsrc_dY = 2 * src_rect.height / (double)max; // die 2 einfach mal so eingesetzt <--------------------------
|
||||||
src_dY = aBitBigger( minsrc_dY );
|
src_dY = aBitBigger( minsrc_dY );
|
||||||
if( src_dY < minimal_increment ) src_dY = minimal_increment;
|
if( src_dY < minimal_increment ) src_dY = minimal_increment;
|
||||||
|
if( under_construction ) System.out.println("Setting src_dY to " + src_dY + " for " + src_rect);
|
||||||
return src_dY;
|
return src_dY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user