我有一个复杂的函数定义(4个双参数),它有很多不同的局部最优值。我没有理由认为它也应该是可区分的。我唯一能说的是可以找到(有趣的)最优解的超立方体。不规则函数的优化
我写了一个真正的原油和缓慢的算法优化的功能:
public static OptimalParameters brutForce(Model function) throws FunctionEvaluationException, OptimizationException {
System.out.println("BrutForce");
double startingStep = 0.02;
double minStep = 1e-6;
int steps = 30;
double[] start = function.startingGuess();
int n = start.length;
Comparer comparer = comparer(function);
double[] minimum = start;
double result = function.value(minimum);
double step = startingStep;
while (step > minStep) {
System.out.println("STEP step=" + step);
GridGenerator gridGenerator = new GridGenerator(steps, step, minimum);
double[] point;
while ((point = gridGenerator.NextPoint()) != null) {
double value = function.value(point);
if (comparer.better(value, result)) {
System.out.println("New optimum " + value + " at " + model.timeSeries(point));
result = value;
minimum = point;
}
}
step /= 1.93;
}
return new OptimalParameters(result, function.timeSeries(minimum));
}
private static Comparer comparer(Model model) {
if (model.goalType() == GoalType.MINIMIZE) {
return new Comparer() {
@Override
public boolean better(double newVal, double optimumSoFar) {
return newVal < optimumSoFar;
}
};
}
return new Comparer() {
@Override
public boolean better(double newVal, double optimumSoFar) {
return newVal > optimumSoFar;
}
};
}
private static interface Comparer {
boolean better(double newVal, double optimumSoFar);
}
注意,更重要的是找到一个更好的局部最优比算法的速度。
有没有更好的算法来做这种优化?你有什么想法如何改进这种设计?
找到了这个Apache Commons的Java实现:http://commons.apache.org/math/apidocs/org/apache/commons/math/optimization/direct/NelderMead.html – Grzenio 2012-01-05 11:49:53
@Grzenio,在这种情况下,你可以考虑接受答案? :) – 2012-01-05 11:50:42