为什么optim()的结果取决于初始值? [英] Why do results from optim() depend on initial values?

查看:264
本文介绍了为什么optim()的结果取决于初始值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中,我使用函数optim()来找到两个变量的目标函数的最小值.我正在使用的实际目标函数非常复杂,因此我尝试使自己熟悉一个更简单的目标函数.运行optim()的最简单方法是optim(par,function),其中par是算法初始值的向量.我发现我得到的答案在很大程度上取决于我输入的初始值.但是,我使用的函数是如此简单,担心我误解了optim()的输入或输出.

In R, I am using the function optim() to find the minimum of an objective function of two variables. The real objective functions I'm working with are quite complex, so I tried to familiarize myself with the a simpler objective function. The simplest way to run optim() is optim(par,function) where par is a vector of initial values for the algorithm. I find that the answer I get depends heavily on the initial values I input. However, the function I used is so simple, I'm worried that I am misunderstanding either the input or output of optim().

我正在使用的目标函数是:

The objective function I am using is:

f <- function(x){
    abs(x[1])*abs(x[2])
}

当我运行optim(c(-1.2,1),f)optim(c(-1.2,10),f)时,对于最佳参数(参数)和最小值(值),我得到了截然不同的输出.有谁知道为什么会这样?

When I run optim(c(-1.2,1),f) and optim(c(-1.2,10),f) I get drastically different output for the optimal arguments (par) and the minimum (value). Does anyone have an idea why this would be so?

推荐答案

在这种情况下,您的目标函数具有无限多个最佳点(不一定只是不同的局部最大值).参数之一为零的任何地方0都与参数接近0的任何其他点一样好.我不确定您是否期望(0,0),但是(0,34)具有相同的值并且可以也被认为是最佳的.

In this case your objective function has infinitely many optimal points (not necessarily just different local maxima). Anywhere one of the parameters is zero 0 is just as good as any other point where a parameter is near 0. I'm not sure if you were expecting (0,0), but (0,34) has the same value and can also be considered optimal.

这篇关于为什么optim()的结果取决于初始值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆