MATLAB fmincon 的初值x0的选取问题[通俗易懂]

MATLAB fmincon 的初值x0的选取问题[通俗易懂]问题描述:在使用fmincon求解局部(全局)最优值时,我们需要在fmincon函数中输入初值x0,那么这个初值是否要像原始的牛顿法一样初值必须在可行域内(严格可行)?MATLAB在Document(https://cn.mathworks.com/help/optim/ug/fmincon.html?s_tid=doc_ta)中是这样描述的:大译:初始点为实值(fmincon只…

大家好,又见面了,我是你们的朋友全栈君。

问题描述:在使用fmincon求解局部(全局)最优值时,我们需要在fmincon函数中输入初值x0,那么这个初值是否要像原始的牛顿法一样初值必须在可行域内(严格可行)?

MATLAB在Document (https://cn.mathworks.com/help/optim/ug/fmincon.html?s_tid=doc_ta)中是这样描述的:

MATLAB fmincon 的初值x0的选取问题[通俗易懂]

大译:

初始点为实值(fmincon只能用于计算实数):

1、若使用内点法,如果 Honorbounds项为真 (正常为默认真),x0不在lb和ub内时,会将其移动到严格的上下界内。(此处并未说明x0必须满足线性和非线性约束)。

2、若使用信赖域反射算法,fimincon 会将不可行的x0重新设置为满足上下界或线性等式的可行初始点。(此处并未说明x0必须满足线性和非线性不等式约束)。

3、如果使用’sqp’, 或者’active-set’算法,同内点法。

这样我们可以得出结论,初始点可以不在上界ub和下界lb内(需要满足线性和非线性不等式)。若优化问题是可行域是凸集(convex set),目标函数是凸函数(convex function),则初值的选取不会对最优值造成影响。如果目标函数是一个非凸函数,想得到全局最优,就需要在最优点附近找初值,否则可能得到局部最优。

我们举一个凸优化的例子:

objective function(convex in constraints):  y = sin(x)

constraint(convex)

                bounds: 2.5<=x<=7

                nonlinear constraint  cos(x)<=0.4;

编程:

fun = @(x)sin(x);

 

lb = 2.5;
ub = 7;
A = [];
b = [];
Aeq = [];
beq = [];
nonlcon = @circlecon;
[x,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)

 

function [c,ceq] = circlecon(x)
 
c = cos(x)-0.4;
ceq = [];

1、当设 x0 = 0 得到结果:

Your initial point x0 is not between bounds lb and ub; FMINCON
shifted x0 to strictly satisfy the bounds.

                                            First-order      Norm of
 Iter F-count            f(x)  Feasibility   optimality         step
    0       2   -3.414013e-01    0.000e+00    8.765e-01
    1       4   -9.358700e-01    0.000e+00    2.093e-01    8.623e-01
    2       6   -9.972133e-01    0.000e+00    7.339e-02    2.854e-01
    3       8   -9.997119e-01    0.000e+00    1.023e-02    5.067e-02
    4      10   -9.999938e-01    0.000e+00    1.423e-03    2.048e-02
    5      12   -1.000000e+00    0.000e+00    2.205e-05    3.467e-03
    6      14   -1.000000e+00    0.000e+00    1.000e-05    3.129e-05
    7      16   -1.000000e+00    0.000e+00    1.006e-07    2.460e-05
 

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 

 

feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
    4.7124
fval =
   -1.0000

 

2、当设 x0 = 3 得到结果:

 Iter F-count            f(x)  Feasibility   optimality         step
    0       2    1.411200e-01    0.000e+00    9.778e-01
    1       4   -6.305350e-01    0.000e+00    6.608e-01    8.238e-01
    2       7   -9.983306e-01    0.000e+00    2.018e-01    9.463e-01
    3       9   -9.860621e-01    0.000e+00    6.715e-02    2.249e-01
    4      11   -9.978028e-01    0.000e+00    2.966e-02    1.009e-01
    5      13   -9.999612e-01    0.000e+00    3.837e-03    5.750e-02
    6      15   -9.999998e-01    0.000e+00    2.715e-04    8.133e-03
    7      17   -1.000000e+00    0.000e+00    2.447e-06    6.658e-04
    8      19   -1.000000e+00    0.000e+00    2.004e-08    6.083e-06
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
    4.7124
fval =

   -1.0000

可以看到,两次得到的都是全局最优解(提示是局部最小,实际是在满足限制条件的最小)。所以,fmincon的初始值x0可以任意取,只要保证为实数就行。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/137442.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月1日 下午11:46
下一篇 2022年6月2日 上午6:00


相关推荐

  • SpringBoot 集成Kafka的demo

    SpringBoot 集成Kafka的demoWindow 环境下 SpringBoot 集成 Kafka 一 windows 环境下启动 Kafka1 kafka 前提由于 kafka 是基于 zookeeper 运行的 在 kafka2 x 的版本中 自带了 zk 本文介绍的是基于 2 X 版本的集成 2 kafka 本地启动下载地址 https kafka apache org downloads2 1 解压后修改 config 两个配置文件 kafka 安装目录 D software kafka kafka 2 13 3 1 0zookeeper pr

    2026年3月26日
    2
  • Log4cpp 配置文件格式说明

    Log4cpp 配置文件格式说明https www cnblogs com diegodu p 6100804 htmllog4cpp 有 3 个主要的组件 categories 类别 appenders 附加目的地 和 layouts 布局 log4cpp 当前提供以下 layout 格式 log4cpp BasicLayout 以 时间戳优先级 priority 下文介绍 类别 category 下文介绍 NDC 标签 log4cpp PatternLayou 让用户根据类似于 C 语

    2026年3月17日
    2
  • spring源码搭建_积木搭建的基本技巧

    spring源码搭建_积木搭建的基本技巧一Spring源码下载官网下载(下载太慢):https://github.com/spring-projects/spring-framework/archive/v5.0.2.RELEASE.zip码云下载:https://gitee.com/mirrors/Spring-Framework/tree/v5.0.2.RELEASE/二Gradle的源码构建技巧1Gr…

    2022年8月12日
    9
  • toolchain安装教程支持_orocos toolchain安装

    toolchain安装教程支持_orocos toolchain安装首先需要安装有 ruby 且版本有要求 ruby1 8 7 以上 makesurethat gt 1 8 7 isinstalledo 方法 1 脚本安装 cd HOMEmkdiroro toolchaincdo toolchai

    2026年3月18日
    2
  • Python3列表_python tuple

    Python3列表_python tuple列表列表特点:是一种序列结构,与元组不同,列表具有可变性,可以追加、插入、删除、替换列表中的元素新增元素appendappend添加一个对象,可以是任意类型a=['zhangsa

    2022年7月31日
    9
  • 网页鼠标点击特效案例收集

    网页鼠标点击特效案例收集1 鼠标点击出随机颜色的爱心 DOCTYPE tml htmllang en head metacharset UTF 8 metaname viewport content width device width initial scale 1 0 title Document title metaname viewport content width device width initial scale 1 0 metacharset UTF 8 head htmllang en

    2026年3月17日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号