优化算法中的起始值
Starting value in optimization algorithms
我正在尝试在 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 !!
语法很简单:
lbfgs.Minimize(x);
谢谢“500 - 内部服务器错误”!
我正在尝试在 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 !!
语法很简单: lbfgs.Minimize(x); 谢谢“500 - 内部服务器错误”!