Extension of the Interface2DBorderProblem interface
This commit is contained in:
parent
66e1fc7e8b
commit
42dd66e2e7
@ -120,7 +120,7 @@ public class TopoPlot extends Plot {
|
|||||||
if (tmp < min) min = tmp;
|
if (tmp < min) min = tmp;
|
||||||
if (tmp > max) max = tmp;
|
if (tmp > max) max = tmp;
|
||||||
if (withGradientsIfAvailable && (problem instanceof InterfaceFirstOrderDerivableProblem)) {
|
if (withGradientsIfAvailable && (problem instanceof InterfaceFirstOrderDerivableProblem)) {
|
||||||
double[] deriv = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(pos);
|
double[] deriv = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(problem.project2DPoint(pos));
|
||||||
for (int i=0; i<2;i++) maxDeriv=Math.max(maxDeriv, Math.abs(deriv[i])); // maximum deriv of first 2 dims
|
for (int i=0; i<2;i++) maxDeriv=Math.max(maxDeriv, Math.abs(deriv[i])); // maximum deriv of first 2 dims
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ public class TopoPlot extends Plot {
|
|||||||
for (int y=0; y<gridy; y++) {
|
for (int y=0; y<gridy; y++) {
|
||||||
pos[0] = border[0][0]+x*deltaX;
|
pos[0] = border[0][0]+x*deltaX;
|
||||||
pos[1] = border[1][0]+y*deltaY;
|
pos[1] = border[1][0]+y*deltaY;
|
||||||
double[] derivPos = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(pos);
|
double[] derivPos = ((InterfaceFirstOrderDerivableProblem)problem).getFirstOrderGradients(problem.project2DPoint(pos));
|
||||||
Mathematics.svDiv(1.1*(2*maxDeriv/Math.max(deltaX, deltaY)), derivPos, derivPos);
|
Mathematics.svDiv(1.1*(2*maxDeriv/Math.max(deltaX, deltaY)), derivPos, derivPos);
|
||||||
Mathematics.vvAdd(pos, derivPos, derivPos);
|
Mathematics.vvAdd(pos, derivPos, derivPos);
|
||||||
getFunctionArea().drawLine(pos, derivPos);
|
getFunctionArea().drawLine(pos, derivPos);
|
||||||
|
@ -338,12 +338,12 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
|
|||||||
return makeRange();
|
return makeRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double[] project2DPoint(double[] point) {
|
||||||
|
return Mathematics.expandVector(point, getProblemDimension(), 0.);
|
||||||
|
}
|
||||||
|
|
||||||
public double functionValue(double[] point) {
|
public double functionValue(double[] point) {
|
||||||
double x[] = new double[getProblemDimension()];
|
return eval(project2DPoint(point))[0];
|
||||||
for (int i=0; i<point.length; i++) x[i]=point[i];
|
|
||||||
for (int i=point.length; i<x.length; i++) x[i] = 0;
|
|
||||||
return eval(x)[0];
|
|
||||||
}
|
}
|
||||||
/**********************************************************************************************************************
|
/**********************************************************************************************************************
|
||||||
* These are for GUI
|
* These are for GUI
|
||||||
|
@ -22,6 +22,7 @@ import eva2.server.go.strategies.InterfaceOptimizer;
|
|||||||
|
|
||||||
|
|
||||||
import eva2.server.go.problems.Interface2DBorderProblem;
|
import eva2.server.go.problems.Interface2DBorderProblem;
|
||||||
|
import eva2.tools.math.Mathematics;
|
||||||
|
|
||||||
public class ExternalRuntimeProblem extends AbstractOptimizationProblem implements Interface2DBorderProblem, InterfaceProblemDouble {
|
public class ExternalRuntimeProblem extends AbstractOptimizationProblem implements Interface2DBorderProblem, InterfaceProblemDouble {
|
||||||
|
|
||||||
@ -328,10 +329,10 @@ public class ExternalRuntimeProblem extends AbstractOptimizationProblem implemen
|
|||||||
return (InterfaceDataTypeDouble)this.m_Template;
|
return (InterfaceDataTypeDouble)this.m_Template;
|
||||||
}
|
}
|
||||||
public double functionValue(double[] point) {
|
public double functionValue(double[] point) {
|
||||||
double x[] = new double[m_ProblemDimension];
|
return eval(project2DPoint(point))[0];
|
||||||
for (int i=0; i<point.length; i++) x[i]=point[i];
|
}
|
||||||
for (int i=point.length; i<m_ProblemDimension; i++) x[i] = 0;
|
public double[] project2DPoint(double[] point) {
|
||||||
return eval(x)[0];
|
return Mathematics.expandVector(point, getProblemDimension(), 0.);
|
||||||
}
|
}
|
||||||
public double[][] get2DBorder() {
|
public double[][] get2DBorder() {
|
||||||
return getDoubleRange();
|
return getDoubleRange();
|
||||||
|
@ -12,9 +12,20 @@ public interface Interface2DBorderProblem {
|
|||||||
*/
|
*/
|
||||||
public double[][] get2DBorder();
|
public double[][] get2DBorder();
|
||||||
|
|
||||||
/** This method returns the double value at a given position.
|
/**
|
||||||
|
* This method returns the double value at a given position. The value should be
|
||||||
|
* based on the same projection delivered by the project2DPoint function.
|
||||||
|
*
|
||||||
* @param point The double[2] that is queried.
|
* @param point The double[2] that is queried.
|
||||||
* @return double
|
* @return double
|
||||||
*/
|
*/
|
||||||
public double functionValue(double[] point);
|
public double functionValue(double[] point);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project a 2D point to the default higher-dimensional cut to be displayed (if required for plotting).
|
||||||
|
*
|
||||||
|
* @param point the double[2] that is queried
|
||||||
|
* @return a (higher dimensional) projection of the point
|
||||||
|
*/
|
||||||
|
public double[] project2DPoint(double[] point);
|
||||||
}
|
}
|
||||||
|
@ -1020,6 +1020,27 @@ public class Mathematics {
|
|||||||
} else return v;
|
} else return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expand a vector to a higher dimension (len) by filling it up
|
||||||
|
* with a constant value.
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param len
|
||||||
|
* @param v
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static double[] expandVector(double[] x, int len, double v) {
|
||||||
|
if (len <= x.length ) {
|
||||||
|
System.err.println("Error, invalid length in expandVector, expecting l>" + x.length);
|
||||||
|
return x;
|
||||||
|
} else {
|
||||||
|
double[] expanded = new double[len];
|
||||||
|
System.arraycopy(x, 0, expanded, 0, x.length);
|
||||||
|
for (int i=x.length; i<expanded.length; i++) expanded[i] = v;
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the average length of the range intervals over all dimensions.
|
* Calculate the average length of the range intervals over all dimensions.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user