ILNumerics:Returns 优化函数时意外的最小值

ILNumerics: Returns unexpected minimum when optimizing a function

我正在 运行 试用 ILNumerics(发布时的最新版本),但在 运行 Optimization.fmin 优化器时得到错误的最小值。

最小值应为 f(-5.218) = -3.342,搜索范围为 -10 <= x <= 10。

private void Compute()
    {
        //var function = new Func<double, double>(input =>
        //{
        //    var output = Math.Pow(input, 3) / Math.Exp(Math.Pow(input, 0.8));
        //    return output;
        //});

        Array<double> bounds = new double[] {-10.0, 10.0};
        Array<double> start = new double[] {1};
        Array<double> y = Optimization.fmin(myfunc, start, lowerBound: bounds[0], upperBound: bounds[1]);

        Console.WriteLine("The minimum is found at");
        Console.WriteLine("{0}", y);
        Console.WriteLine("The value is");
        Console.WriteLine("{0}", myfunc(y));

        Console.ReadLine();

        return;


    }

    static RetArray<double> myfunc(InArray<double> x)
    {
        var input = x.GetValue(0);
        var output = Math.Pow(input, 3) / Math.Exp(Math.Pow(input, 0.8));
        return output;
    }

您的 objective 函数 returns NaN 在负数位置。您可以轻松查看:

首先,在目标范围 (-10...10) 内添加样本值并计算 objective 函数的结果。

Array<double> bounds = new double[] { -10.0, 10.0 };
Array<double> start = new double[] { 1 };
Array<double> y = Optimization.fmin(myfunc, start, lowerBound: bounds[0], upperBound: bounds[1]);

Array<double> range = linspace(-10.0, 10, 100); 
Array<double> YinRange = apply(range, range, (a,b) => (double)myfunc(a));

Console.WriteLine("The minimum is found at");
Console.WriteLine("{0}", y);
Console.WriteLine("The value is");
Console.WriteLine("{0}", myfunc(y));

现在可以在调试会话期间使用 ArrayVisualizer 可视化实际值:

fmin 大致返回 0 这似乎是合理的,因为它试图忽略 NaN 值。根据这个图 0 事实上 最小值 最小值。

另请参阅:MSDN on Math.Pow