优化算法的起始值

时间:2019-05-28 17:14:54

标签: c# accord.net

我正在尝试在C#的Accord.net数学软件包中使用L-BFGS求解器。 但是,我找不到如何定义优化的起始值。 我们如何定义它?

根据官方示例,以下语法定义了优化过程中x的初始值。但是,在下面的示例中,它无法正常工作-就像算法使用了另一个起点一样。


//Target function to minimize;
public double f(double[] x) { 
   double z = Math.Cos(x[0])-0.2*x[0] + x[1] * x[1]; //Function with multiple local minima : x ~ { (2n+1)pi , 0 }
   return z;
  }

//Gradient
  public double[] g(double[] x) { 
      double[] grad = {-Math.Sin(x[0])-0.2 , 2 * x[1]};
      return grad;
  }

  double[] x = {3*3.141592,0}; // Starting value (local minimum, -2.88)

  var lbfgs = new BroydenFletcherGoldfarbShanno(numberOfVariables: 2, function: f, gradient: g);

  bool success = lbfgs.Minimize();
  double minValue = lbfgs.Value;
  double[] solution = lbfgs.Solution; // {3.34,0} This solution is a local min that has a higher value (-1.65) than the local min next to which we started !!

1 个答案:

答案 0 :(得分:1)

语法很简单: lbfgs.Minimize(x); 谢谢“ 500-内部服务器错误”!