-
Notifications
You must be signed in to change notification settings - Fork 0
/
SphereEvaluation.java
88 lines (75 loc) · 2.63 KB
/
SphereEvaluation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Properties;
import org.vu.contest.ContestEvaluation;
// This is an example evalation. It is based on the standard sphere function. It is a maximization problem with a maximum of 10 for
// vector x=0.
// The sphere function itself is for minimization with minimum at 0, thus fitness is calculated as Fitness = 10 - 10*(f-fbest),
// where f is the result of the sphere function
// Base performance is calculated as the distance of the expected fitness of a random search (with the same amount of available
// evaluations) on the sphere function to the function minimum, thus Base = E[f_best_random] - ftarget. Fitness is scaled
// according to this base, thus Fitness = 10 - 10*(f-fbest)/Base
public class SphereEvaluation implements ContestEvaluation
{
// Evaluations budget
private final static int EVALS_LIMIT_ = 10000;
// The base performance. It is derived by doing random search on the sphere function (see function method) with the same
// amount of evaluations
private final static double BASE_ = 11.5356;
// The minimum of the sphere function
private final static double ftarget_=0;
// Best fitness so far
private double best_;
// Evaluations used so far
private int evaluations_;
// Properties of the evaluation
private String multimodal_ = "false";
private String regular_ = "true";
private String separable_ = "true";
private String evals_ = Integer.toString(EVALS_LIMIT_);
public SphereEvaluation()
{
best_ = 0;
evaluations_ = 0;
}
// The standard sphere function. It has one minimum at 0.
private double function(double[] x)
{
double sum = 0;
for(int i=0; i<10; i++) sum += x[i]*x[i];
return sum;
}
@Override
public Object evaluate(Object result)
{
// Check argument
if(!(result instanceof double[])) throw new IllegalArgumentException();
double ind[] = (double[]) result;
if(ind.length!=10) throw new IllegalArgumentException();
if(evaluations_>EVALS_LIMIT_) return null;
// Transform function value (sphere is minimization).
// Normalize using the base performance
double f = 10 - 10*( (function(ind)-ftarget_) / BASE_ ) ;
if(f>best_) best_ = f;
evaluations_++;
return new Double(f);
}
@Override
public Object getData(Object arg0)
{
return null;
}
@Override
public double getFinalResult()
{
return best_;
}
@Override
public Properties getProperties()
{
Properties props = new Properties();
props.put("Multimodal", multimodal_);
props.put("Regular", regular_);
props.put("Separable", separable_);
props.put("Evaluations", evals_);
return props;
}
}