Gradients for F6 (Rastrigins)

This commit is contained in:
Marcel Kronfeld
2009-11-20 10:48:43 +00:00
parent 77395aa7b8
commit 567b7ef1b7
2 changed files with 18 additions and 3 deletions

View File

@@ -11,7 +11,7 @@ import eva2.tools.math.Jama.Matrix;
* Time: 13:09:36 * Time: 13:09:36
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
public class F6Problem extends AbstractProblemDoubleOffset implements InterfaceMultimodalProblem, java.io.Serializable { public class F6Problem extends AbstractProblemDoubleOffset implements InterfaceMultimodalProblem, InterfaceFirstOrderDerivableProblem, java.io.Serializable {
private boolean doRotation = false; private boolean doRotation = false;
private double m_A = 10; private double m_A = 10;
@@ -55,7 +55,6 @@ public class F6Problem extends AbstractProblemDoubleOffset implements InterfaceM
* @return The m-dimensional output vector. * @return The m-dimensional output vector.
*/ */
public double[] eval(double[] x) { public double[] eval(double[] x) {
if (doRotation) { if (doRotation) {
Matrix resVec = rotation.times(new Matrix(x, x.length)); Matrix resVec = rotation.times(new Matrix(x, x.length));
x = resVec.getColumnPackedCopy(); x = resVec.getColumnPackedCopy();
@@ -68,7 +67,21 @@ public class F6Problem extends AbstractProblemDoubleOffset implements InterfaceM
} }
return result; return result;
} }
public double[] getFirstOrderGradients(double[] x) {
if (doRotation) {
Matrix resVec = rotation.times(new Matrix(x, x.length));
x = resVec.getColumnPackedCopy();
}
double[] result = new double[x.length];
for (int j=0; j<x.length; j++) {
result[j]=0;
double xj = x[j]-m_XOffSet;
result[j] += 2*xj + this.m_Omega * this.m_A * Math.sin(this.m_Omega*xj);
}
return result;
}
/** This method returns a string describing the optimization problem. /** This method returns a string describing the optimization problem.
* @return The description. * @return The description.
*/ */

View File

@@ -207,6 +207,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
} // for loop population size } // for loop population size
this.m_Problem.evaluate(this.m_Population); this.m_Problem.evaluate(this.m_Population);
m_Population.incrGeneration();
if (this.recovery) { if (this.recovery) {
for (int i = 0; i < this.m_Population.size(); i++) { for (int i = 0; i < this.m_Population.size(); i++) {
@@ -232,6 +233,7 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
} }
} }
this.m_Problem.evaluate(this.m_Population); this.m_Problem.evaluate(this.m_Population);
m_Population.incrGeneration();
} }
if (this.globalStepSizeAdaption) { if (this.globalStepSizeAdaption) {