2012-01-05 78 views
2

我有一个复杂的函数定义(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); 
} 

注意,更重要的是找到一个更好的局部最优比算法的速度。

有没有更好的算法来做这种优化?你有什么想法如何改进这种设计?

回答

2

您可以使用基于Simplex的优化。它完全适用于像你一样的问题。

如果可以用Matlab,至少对于原型,尝试使用fminsearch
http://www.mathworks.com/help/techdoc/ref/fminsearch.html

[1] Lagarias,JC,JA芦苇,MH莱特和PE莱特,“收敛性。 Nelder-Mead Simplex Method in Low Dimensions“,SIAM Journal of Optimization,Vol。 9 1号,第112-147,1998年

+1

找到了这个Apache Commons的Java实现:http://commons.apache.org/math/apidocs/org/apache/commons/math/optimization/direct/NelderMead.html – Grzenio 2012-01-05 11:49:53

+0

@Grzenio,在这种情况下,你可以考虑接受答案? :) – 2012-01-05 11:50:42

0

你的问题听起来好像启发式将是一个理想的解决方案。您可以尝试使用元启发式算法,如Evolution Strategies (ES)。 ES是专为苛刻的多模式实矢量功能而设计的。 ES和几个实际功能在我们的软件HeuristicLab中实现(Rosenbrock,Rastrigin,Ackley等)。您可以在那里实现自己的功能并对其进行优化。您不需要添加大量代码,并且可以直接从其他可以作为示例的函数中进行复制。您需要将代码移植到C#,但只有评估,其他部分不需要。 一个优点是,如果您的功能在HeuristicLab中实现,您还可以尝试使用粒子群优化(PSO)方法,遗传算法或模拟退火来对其进行优化,这些方法也已实施,并查看哪一个效果最好。您只需执行一次评估功能。

或者你只是扫描文献的进化策略和自己重新实现。 IIRC Beyer在his website上实现 - 它是为MatLab编写的。