混沌优化算法修改
创始人
2024-05-31 04:34:07
0


%function BAS()
%bas:beetle antenna searching for global minimum天牛须算法搜索全局最小值
clear
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%parameter setup参数设置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%antenna distance天牛须间的距离
d0=0.001;
d1=3;
d=d1;
eta_d=0.95;
%random walk随机步进
l0=0.0;
l1=0.0;
l=l1;
eta_l=0.95;
%steps
step=0.8;%step length步长
eta_step=0.95;
n=100;%iterations迭代次数
k=2;%space dimension空间维数
x0=2*rands(k,1);
x=x0;
xbest=x0;
fbest=fun(xbest);
fbest_store=fbest;
x_store=[0;x;fbest];
display(['0:','xbest=[',num2str(xbest(1)),num2str(xbest(2)),'],fbest=',num2str(fbest)])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%iteration迭代
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:n
dir=rands(k,1);
dir=dir/(eps+norm(dir));
xleft=x+dir*d;
fleft=fun(xleft);
xright=x-dir*d;
fright=fun(xright);
w=l*rands(k,1);
x=x-step*dir*sign(fleft-fright)+w;
f=fun(x);
%%%%%%%%%%%
if f
xbest=x;
fbest=f;
end
%------------混沌---------------------------------
xlhd = xbest(1:k);
for t=1:n %次数
%1生成
cxl=rand(1,k);
for j=1:k
if cxl(j)==0
cxl(j)=0.1;
end
if cxl(j)==0.25
cxl(j)=0.26;
end
if cxl(j)==0.5
cxl(j)=0.51;
end
if cxl(j)==0.75
cxl(j)=0.76;
end
if cxl(j)==1
cxl(j)=0.9;
end
end
%2映射
al=-4;bl=4;
rxl=al+(bl-al)*cxl;
%3搜索
bate = 0.3;
xlhd=xlhd+(bate*rxl)';
if fun(xlhd)
xbest(1:k)=xlhd;           %更新全局最优值
xbest(end)=fun(xlhd);
end
%4更新
for j=1:k
cxl(j)=4*cxl(j)*(1-cxl(j));   %logic混沌方程
end
end
%-------------混沌--------------------------------
%当前代的最优粒子的适应度(取自最后一列)保存
fbest_store = xbest(end);
end
%%%%%%%%%%%
x_store=cat(2,x_store,[i;x;f]);
fbest_store=[fbest_store;fbest];
display([num2str(i),':xbest=[',num2str(xbest(1)),num2str(xbest(2)),'],fbest=',num2str(fbest)])
%%%%%%%%%%%
d=d*eta_d+d0;
l=l*eta_l+l0;
step=step*eta_step;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%data visualization数据可视化
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1),clf(1),
plot(x_store(2,:),x_store(3,:),'r-.'),axis equal
xlim0=[min(x_store(2,:)),max(x_store(2,:))];
ylim0=[min(x_store(3,:)),max(x_store(3,:))];
[x,y]=meshgrid(xlim0(1):(xlim0(2)-xlim0(1))/50:xlim0(2),ylim0(1):(ylim0(2)-ylim0(1))/50:ylim0(2));
f_val=x;
[s1,s2]=size(x);
for i=1:s1
for j=1:s2
f_val(i,j)=fun([x(i,j),y(i,j)]);
end
end
hold on,contour(x,y,f_val,50);
colorbar;
xlim([xlim0(1),xlim0(2)]);
ylim([ylim0(1),ylim0(2)]);
hold on, plot(x_store(2,end),x_store(3,end),'b*')
hold on, plot(xbest(1),xbest(2),'r*')
figure(3),clf(3),
plot(x_store(1,:),x_store(4,:),'r-o')
hold on,
plot(x_store(1,:),fbest_store,'b-.')
xlabel('iteration')
ylabel('minimum value')
function yout=fun(x)
theta=x;
x=theta(1);
y=theta(2);
% Michalewicz function函数
yout=-sin(x).*(sin(x.^2/pi)).^20-sin(y).*(sin(2*y.^2/pi)).^20;
end

相关内容

热门资讯

监控摄像头接入GB28181平... 流程简介将监控摄像头的视频在网站和APP中直播,要解决的几个问题是:1&...
Windows10添加群晖磁盘... 在使用群晖NAS时,我们需要通过本地映射的方式把NAS映射成本地的一块磁盘使用。 通过...
protocol buffer... 目录 目录 什么是protocol buffer 1.protobuf 1.1安装  1.2使用...
在Word、WPS中插入AxM... 引言 我最近需要写一些文章,在排版时发现AxMath插入的公式竟然会导致行间距异常&#...
【PdgCntEditor】解... 一、问题背景 大部分的图书对应的PDF,目录中的页码并非PDF中直接索引的页码...
修复 爱普生 EPSON L4... L4151 L4153 L4156 L4158 L4163 L4165 L4166 L4168 L4...
Fluent中创建监测点 1 概述某些仿真问题,需要创建监测点,用于获取空间定点的数据࿰...
educoder数据结构与算法...                                                   ...
MySQL下载和安装(Wind... 前言:刚换了一台电脑,里面所有东西都需要重新配置,习惯了所...
MFC文件操作  MFC提供了一个文件操作的基类CFile,这个类提供了一个没有缓存的二进制格式的磁盘...