Fix Step function and add test for known optimum.

This commit is contained in:
Fabian Becker 2014-12-01 19:22:30 +01:00
parent b19d1c5d39
commit f01258fff1
3 changed files with 29 additions and 5 deletions

View File

@ -28,7 +28,9 @@ public class F3Problem extends AbstractProblemDoubleOffset implements java.io.Se
}
/**
* Ths method allows you to evaluate a double[] to determine the fitness
* Evaluates a double vector according to the Step function.
*
* fitness = sum(floor(x_i + 0.5)^2)
*
* @param x The n-dimensional input vector
* @return The m-dimensional output vector.
@ -37,9 +39,9 @@ public class F3Problem extends AbstractProblemDoubleOffset implements java.io.Se
public double[] evaluate(double[] x) {
x = rotateMaybe(x);
double[] result = new double[1];
result[0] = yOffset + 6 * x.length;
result[0] = yOffset;
for (int i = 0; i < x.length - 1; i++) {
result[0] += Math.floor(x[i] - this.xOffset);
result[0] += Math.pow(Math.floor(x[i] + 0.5 - this.xOffset), 2);
}
return result;
}

View File

@ -0,0 +1,24 @@
package eva2.problems;
import eva2.tools.math.Mathematics;
import junit.framework.TestCase;
public class F3ProblemTest extends TestCase {
/**
* The Step function has its minimum
* at x_{i} = 0
*
* @throws Exception
*/
public void testEvaluate() throws Exception {
F3Problem problem = new F3Problem();
for (int i = 1; i < 100; i++) {
double[] x = Mathematics.zeroes(i);
double[] res = problem.evaluate(x);
assertEquals(1, res.length);
assertEquals(0.0, res[0]);
}
}
}

View File

@ -68,7 +68,6 @@ public class SerializerTest {
*/
@Test
public void testStoreObject() {
System.out.println("storeObject");
OutputStream outStream = null;
Serializable s = null;
Serializer.storeObject(outStream, s);
@ -81,7 +80,6 @@ public class SerializerTest {
*/
@Test
public void testLoadObject_InputStream() {
System.out.println("loadObject");
InputStream inputStream = null;
Object expResult = null;
Object result = Serializer.loadObject(inputStream);