function [p,f] = spm_powell(p,xi,tolsc,func,varargin)
% Powell optimisation method
% FORMAT [p,f] = spm_powell(p,xi,tolsc,func,varargin)
% p - Starting parameter values
% xi - columns containing directions in which to begin
% searching.
% tolsc - stopping criteria
% - optimisation stops when
% sqrt(sum(((p-p_prev)./tolsc).^2))<1
% func - name of evaluated function
% varargin - remaining arguments to func (after p)
%
% p - final parameter estimates
% f - function value at minimum
%
%_______________________________________________________________________
% Method is based on Powell's optimisation method from Numerical Recipes
% in C (Press, Flannery, Teukolsky & Vetterling).
%_______________________________________________________________________
% @(#)spm_powell.m 2.3 John Ashburner 01/09/28
p = p(:);
f = feval(func,p,varargin{:});
for iter=1:128,
fprintf('iteration %d...\n', iter);
pp = p;
fp = f;
del = 0;
for i=1:length(p),
ft = f;
[p,junk,f] = linmin(p,xi(:,i),func,f,tolsc,varargin{:});
if abs(ft-f) > del,
del = abs(ft-f);
ibig = i;
end;
end;
if sqrt(sum(((p(:)-pp(:))./tolsc(:)).^2))<1, return; end;
ft = feval(func,2.0*p-pp,varargin{:});
if ft < f,
[p,xi(:,ibig),f] = linmin(p,p-pp,func,f,tolsc,varargin{:});
end;
end;
warning('Too many optimisation iterations');
return;
%_______________________________________________________________________
%_______________________________________________________________________
function [p,pi,f] = linmin(p,pi,func,f,tolsc,varargin)
% Line search for minimum.
global lnm % used in linmineval
lnm = struct('p',p,'pi',pi,'func',func,'args',[]);
lnm.args = varargin;
% linmin_plot('Init', 'Line Minimisation','Function','Parameter Value');
% linmin_plot('Set', 0, f);
tol = 1/sqrt(sum((pi(:)./tolsc(:)).^2));
t = bracket(f);
[f,pmin] = brents(t,tol);
pi = pi*pmin;
p = p + pi;
for i=1:length(p), fprintf('%-8.4g ', p(i)); end;
fprintf('| %.5g\n', f);
% linmin_plot('Clear');
return;
%_______________________________________________________________________
%_______________________________________________________________________
function f = linmineval(p)
% Reconstruct parameters and evaluate.
global lnm % defined in linmin
pt = lnm.p+p.*lnm.pi;
f = feval(lnm.func,pt,lnm.args{:});
% linmin_plot('Set',p,f);
return;
%_______________________________________________________________________
%_______________________________________________________________________
function t = bracket(f)
% Bracket the minimum (t(2)) between t(1) and t(2)
gold = (1+sqrt(5))/2; % Golden ratio
t(1) = struct('p',0,'f',f);
t(2).p = 1;
t(2).f = linmineval(t(2).p);
% if not better then swap
if t(2).f > t(1).f,
tmp = t(1);
t(1) = t(2);
t(2) = tmp;
end;
t(3).p = t(2).p + gold*(t(2).p-t(1).p);
t(3).f = linmineval(t(3).p);
while t(2).f > t(3).f,
% fit a polynomial to t
tmp = cat(1,t.p)-t(2).p;
pol = pinv([ones(3,1) tmp tmp.^2])*cat(1,t.f);
% minimum is when gradient of polynomial is zero
% sign of pol(3) (the 2nd deriv) should be +ve
d = -pol(2)/(2*pol(3)+eps);
u.p = t(2).p+d;
ulim = t(2).p+100*(t(3).p-t(2).p);
if (t(2).p-u.p)*(u.p-t(3).p) > 0.0,
% u is between t(2) and t(3)
u.f = linmineval(u.p);
if u.f < t(3).f,
% minimum between t(2) and t(3) - done
t(1) = t(2);
t(2) = u;
return;
elseif u.f > t(2).f,
% minimum between t(1) and u - done
t(3) = u;
return;
end;
% try golden search instead
u.p = t(3).p+gold*(t(3).p-t(2).p);
u.f = linmineval(u.p);
elseif (t(3).p-u.p)*(u.p-ulim) > 0.0
% u is between t(3) and ulim
u.f = linmineval(u.p);
if u.f < t(3).f,
% still no minimum as function is still decreasing
% t(1) = t(2);
t(2) = t(3);
t(3) = u;
u.p = t(3).p+gold*(t(3).p-t(2).p);
u.f = linmineval(u.p);
end;
elseif (u.p-ulim)*(ulim-t(3).p) >= 0.0,
% gone too far - constrain it
u.p = ulim;
u.f = linmineval(u.p);
else,
% try golden search instead
u.p = t(3).p+gold*(t(3).p-t(2).p);
u.f = linmineval(u.p);
end;
% Move all 3 points along
t(1) = t(2);
t(2) = t(3);
t(3) = u;
end;
return;
%_______________________________________________________________________
%_______________________________________________________________________
function [f,p] = brents(t, tol)
% Brent's method for line searching - given that minimum is bracketed
% 1 - golden ratio
Cgold = 1 - (sqrt(5)-1)/2;
% Current and previous displacements
d = Inf;
pd = Inf;
% t(1) and t(3) bracket the minimum
if t(1).p>t(3).p,
brk(1) = t(3).p;
brk(2) = t(1).p;
else,
brk(1) = t(1).p;
brk(2) = t(3).p;
end;
% sort t into best first order
tmp = t(1);
t(1) = t(2);
t(2) = tmp;
if t(2).f>t(3).f,
tmp = t(2);
t(2) = t(3);
t(3) = tmp;
end;
for iter=1:128,
% check stopping criterion
if abs(t(1).p - 0.5*(brk(1)+brk(2)))+0.5*(brk(2)-brk(1)) <= 2*tol,
p = t(1).p;
f = t(1).f;
return;
end;
% keep last two displacents
ppd = pd;
pd = d;
% fit a polynomial to t
tmp = cat(1,t.p)-t(1).p;
pol = pinv([ones(3,1) tmp tmp.^2])*cat(1,t.f);
% minimum is when gradient of polynomial is zero
d = -pol(2)/(2*pol(3)+eps);
u.p = t(1).p+d;
% check so that displacement is less than the last but two,
% that the displaced point is between the brackets
% and (not sure if it is necessary) that the solution is a minimum
% rather than a maximum
eps2 = 2*eps*abs(t(1).p)+eps;
if abs(d) >= abs(ppd)/2 | u.p <= brk(1)+eps2 | u.p >= brk(2)-eps2 | pol(3)<=0,
% if criteria are not met, then golden search into the larger part
if t(1).p >= 0.5*(brk(1)+brk(2)),
d = Cgold*(brk(1)-t(1).p);
else,
d = Cgold*(brk(2)-t(1).p);
end;
u.p = t(1).p+d;
end;
% FUNCTION EVALUATION
u.f = linmineval(u.p);
% Insert the new point into the appropriate position and update
% the brackets if necessary
if u.f <= t(1).f,
if u.p >= t(1).p, brk(1)=t(1).p; else, brk(2)=t(1).p; end;
t(3) = t(2);
t(2) = t(1);
t(1) = u;
else,
if u.p < t(1).p, brk(1)=u.p; else, brk(2)=u.p; end;
if u.f <= t(2).f | t(1).p==t(2).p,
t(3) = t(2);
t(2) = u;
elseif u.f <= t(3).f | t(1).p==t(3).p | t(2).p==t(3).p,
t(3) = u;
end;
end;
end;
warning('Too many iterations in Brents');
return;
%_______________________________________________________________________
% %_______________________________________________________________________
% function linmin_plot(action,arg1,arg2,arg3,arg4)
% % Visual output for line minimisation
% global linminplot
% %-----------------------------------------------------------------------
% if (nargin == 0)
% linmin_plot('Init');
% else
% % initialize
% %---------------------------------------------------------------
% if (strcmp(lower(action),'init'))
% if (nargin<4)
% arg3 = 'Function';
% if (nargin<3)
% arg2 = 'Value';
% if (nargin<2)
% arg1 = 'Line minimisation';
% end
% end
% end
% fg = spm_figure('FindWin','Interactive');
%
% if ~isempty(fg)
% linminplot = struct('pointer',get(fg,'Pointer'),'name',get(fg,'Name'),'ax',[]);
% linmin_plot('Clear');
% set(fg,'Pointer','watch');
% % set(fg,'Name',arg1);
% linminplot.ax = axes('Position', [0.15 0.1 0.8 0.75],...
% 'Box', 'on','Parent',fg);
% lab = get(linminplot.ax,'Xlabel');
% set(lab,'string',arg3,'FontSize',10);
% lab = get(linminplot.ax,'Ylabel');
% set(lab,'string',arg2,'FontSize',10);
% lab = get(linminplot.ax,'Title');
% set(lab,'string',arg1);
% line('Xdata',[], 'Ydata',[],...
% 'LineWidth',2,'Tag','LinMinPlot','Parent',linminplot.ax,...
% 'LineStyle','-','Marker','o');
% drawnow;
% end
%
% % reset
% %---------------------------------------------------------------
% elseif (strcmp(lower(action),'set'))
% F = spm_figure('FindWin','Interactive');
% br = findobj(F,'Tag','LinMinPlot');
% if (~isempty(br))
% [xd,indx] = sort([get(br,'Xdata') arg1]);
% yd = [get(br,'Ydata')
没有合适的资源?快使用搜索试试~ 我知道了~
基于MATLAB实现的powell优化算法程序+使用说明文档.rar
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共2个文件
md:1个
m:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 38 浏览量
2024-05-22
17:17:36
上传
评论
收藏 7KB RAR 举报
温馨提示
CSDN IT狂飙上传的代码均可运行,功能ok的情况下才上传的,直接替换数据即可使用,小白也能轻松上手 【资源说明】 基于MATLAB实现的powell优化算法程序+使用说明文档.rar 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2020b;若运行有误,根据提示GPT修改;若不会,私信博主(问题描述要详细); 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可后台私信博主; 4.1 期刊或参考文献复现 4.2 Matlab程序定制 4.3 科研合作 功率谱估计: 故障诊断分析: 雷达通信:雷达LFM、MIMO、成像、定位、干扰、检测、信号分析、脉冲压缩 滤波估计:SOC估计 目标定位:WSN定位、滤波跟踪、目标定位 生物电信号:肌电信号EMG、脑电信号EEG、心电信号ECG 通信系统:DOA估计、编码译码、变分模态分解、管道泄漏、滤波器、数字信号处理+传输+分析+去噪、数字信号调制、误码率、信号估计、DTMF、信号检测识别融合、LEACH协议、信号检测、水声通信 5、欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 2 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
IT狂飙
- 粉丝: 4778
- 资源: 2640
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
下载权益
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
C知道特权
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
VIP文章
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
课程特权
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)