防灾数学分享 http://blog.sciencenet.cn/u/fzmath 防灾科技学院数学教研室

博文

一种有效的最优化方法——Nelder-Mead单纯形直接搜索算法

已有 16484 次阅读 2017-7-23 21:41 |系统分类:科研笔记

虽然MATLAB本身自带了fminsearch()函数,可以求解目标函数无梯度的最优化问题,但是感觉下面的程序在很多时候更好用,特别是自变量有边界和非线性约束的时候。


这里是John D'Errico 根据Nelder-Mead单纯形直接搜索算法编写的fminsearchbnd()程序,可从

http://cn.mathworks.com/matlabcentral/fileexchange/8277-fminsearchbnd--fminsearchcon

下载。也可以本地下载

FMINSEARCHBND.zip




%% Optimization of a simple (Rosenbrock) function, with no constraints

% The unconstrained solution is at [1,1]

rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;


% With no constraints, operation simply passes through

% directly to fminsearch. The solution should be [1 1]

xsol = fminsearchbnd(rosen,[3 3])


%% Full lower and upper bound constraints which will all be inactive

xsol = fminsearchbnd(rosen,[3 3],[-1 -1],[4 4])


%% Only lower bound constraints

xsol = fminsearchbnd(rosen,[3 3],[2 2])


%% Only upper bound constraints

xsol = fminsearchbnd(rosen,[-5 -5],[],[0 0])


%% Dual constraints

xsol = fminsearchbnd(rosen,[2.5 2.5],[2 2],[3 3])


%% Dual constraints, with an infeasible starting guess

xsol = fminsearchbnd(rosen,[0 0],[2 2],[3 3])


%% Mixed constraints

xsol = fminsearchbnd(rosen,[0 0],[2 -inf],[inf 3])


%% Provide your own fminsearch options

opts = optimset('fminsearch');

opts.Display = 'iter';

opts.TolX = 1.e-12;


n = [10,5];

H = randn(n);

H=H'*H;

Quadraticfun = @(x) x*H*x';


% Global minimizer is at [0 0 0 0 0].

% Set all lower bound constraints, all of which will

% be active in this test.

LB = [.5 .5 .5 .5 .5];

xsol = fminsearchbnd(Quadraticfun,[1 2 3 4 5],LB,[],opts)


%% Exactly fix one variable, constrain some others, and set a tolerance

opts = optimset('fminsearch');

opts.TolFun = 1.e-12;


LB = [-inf 2 1 -10];

UB = [ inf  inf 1  inf];

xsol = fminsearchbnd(@(x) norm(x),[1 3 1 1],LB,UB,opts)


%% All the standard outputs from fminsearch are still returned

[xsol,fval,exitflag,output] = fminsearchbnd(@(x) norm(x),[1 3 1 1],LB,UB)












https://wap.sciencenet.cn/blog-292361-1067771.html

上一篇:立体心形曲面绘制——隐函数图形
下一篇:雪兔和猞猁数据与微分建模
收藏 IP: 27.189.54.*| 热度|

1 彭真明

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-9 01:49

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部