一、布谷鸟算法简介

布谷鸟算法,英文叫做Cuckoo search (CS algorithm)。首先还是同样,介绍一下这个算法的英文含义, Cuckoo是布谷鸟的意思,啥是布谷鸟呢,是一种叫做布谷的鸟,o(∩_∩)o ,这种鸟她妈很懒,自己生蛋自己不养,一般把它的宝宝扔到别的种类鸟的鸟巢去。但是呢,当孵化后,遇到聪明的鸟妈妈,一看就知道不是亲生的,直接就被鸟妈妈给杀了。于是这群布谷鸟宝宝为了保命,它们就模仿别的种类的鸟叫,让智商或者情商极低的鸟妈妈误认为是自己的亲宝宝,这样它就活下来了。
布谷鸟搜索算法(Cuckoo Search, CS)是2009年Xin-She Yang 与Suash Deb在《Cuckoo Search via Levy Flights》一文中提出的一种优化算法。布谷鸟算法是一种集合了布谷鸟巢寄生性和莱维飞行(Levy Flights)模式的群体智能搜索技术,通过随机游走的方式搜索得到一个最优的鸟巢来孵化自己的鸟蛋。这种方式可以达到一种高效的寻优模式。

1 布谷鸟的巢寄生性

2 莱维飞行

图1.模拟莱维飞行轨迹示意图

3 布谷鸟搜索算法的实现过程

二、部分源代码


%% 数据的提取和预处理                            % 载入测试数据上证指数(1990.12.19-2009.08.19)
% 数据是一个4579*6的double型的矩阵,每一行表示每一天的上证指数
% 6列分别表示当天上证指数的开盘指数,指数最高值,指数最低值,收盘指数,当日交易量,当日交易额.
clear
clc
load chapter_sh.mat;% 提取数据
[m,n] = size(sh);
ts = sh(2:m,1);    % 选取2到4579个交易日内每日的开盘指数作为因变量
tsx =sh(1:m-1,:); %选取1到4578个交易日% 数据预处理,将原始数据进行归一化
ts = ts';
tsx = tsx';% mapminmax为matlab自带的映射函数
% 对ts进行归一化
[TS,TSps] = mapminmax(ts,1,2); %归一化在区间[1 2]
% 对TSX进行转置,以符合libsvm工具箱的数据格式要求
TS = TS';% mapminmax为matlab自带的映射函数
% 对tsx进行归一化
[TSX,TSXps] = mapminmax(tsx,1,2);  %归一化在区间[1 2]
% 对TSX进行转置,以符合libsvm工具箱的数据格式要求
TSX = TSX';Tol=1.0e-5;
n=25;%鸟巢个数
% Discovery rate of alien eggs/solutions
pa=0.25;%为最大迭代次数限制
%% Simple bounds of the search domain
% Lower bounds
nd=2;
Lb=0.01*ones(1,nd);
% Upper bounds
Ub=100*ones(1,nd);                                                              %随机产生初始解
% Random initial solutions
for i=1:n,
nest(i,:)=Lb+(Ub-Lb).*rand(size(Lb));
end
%得到当前的最优解
% Get the current best
for i=1:nfitness(i)=fun(nest(i,:));
endfitness=10^10*ones(n,1);
[fmin,bestnest,nest,fitness]=get_best_nest(nest,nest,fitness,Ub,Lb);
for i=1:nnest(i,find(nest(i,:)>Ub(1)))=Ub(1);nest(i,find(nest(i,:)<Lb(1)))=Lb(1);
endN_iter=0;                                                                   %开始迭代
%% Starting iterations
for iter=1:1 %while (fmin>Tol),% Generate new solutions (but keep the current best)new_nest=get_cuckoos(nest,bestnest,Lb,Ub);   [fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness,Ub,Lb);% Update the counterN_iter=N_iter+n; % Discovery and randomizationnew_nest=empty_nests(nest,Lb,Ub,pa) ;% Evaluate this set of solutions[fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness,Ub,Lb);% Update the counter againN_iter=N_iter+n;% Find the best objective so far  if fnew<fmin,fmin=fnew;bestnest=best;end
end %% End of iterations(迭代)% -----------------------------------------------------------------
% Cuckoo Search (CS) algorithm by Xin-She Yang and Suash Deb      %
% Programmed by Xin-She Yang at Cambridge University              %
% Programming dates: Nov 2008 to June 2009                        %
% Last revised: Dec  2009   (simplified version for demo only)    %
% -----------------------------------------------------------------
% Papers -- Citation Details:
% 1) X.-S. Yang, S. Deb, Cuckoo search via Levy flights,
% in: Proc. of World Congress on Nature & Biologically Inspired
% Computing (NaBIC 2009), December 2009, India,
% IEEE Publications, USA,  pp. 210-214 (2009).
% http://arxiv.org/PS_cache/arxiv/pdf/1003/1003.1594v1.pdf
% 2) X.-S. Yang, S. Deb, Engineering optimization by cuckoo search,
% Int. J. Mathematical Modelling and Numerical Optimisation,
% Vol. 1, No. 4, 330-343 (2010).
% http://arxiv.org/PS_cache/arxiv/pdf/1005/1005.2908v2.pdf
% ----------------------------------------------------------------%
% This demo program only implements a standard version of         %
% Cuckoo Search (CS), as the Levy flights and generation of       %
% new solutions may use slightly different methods.               %
% The pseudo code was given sequentially (select a cuckoo etc),   %
% but the implementation here uses Matlab's vector capability,    %
% which results in neater/better codes and shorter running time.  %
% This implementation is different and more efficient than the    %
% the demo code provided in the book by
%    "Yang X. S., Nature-Inspired Metaheuristic Algoirthms,       %
%     2nd Edition, Luniver Press, (2010).                 "       %
% --------------------------------------------------------------- %% =============================================================== %
% Notes:                                                          %
% Different implementations may lead to slightly different        %
% behavour and/or results, but there is nothing wrong with it,    %
% as this is the nature of random walks and all metaheuristics.   %
% -----------------------------------------------------------------function [bestnest,fmin]=cuckoo_search(n)                                   %n为鸟巢数目
if nargin<1, % nargin是用来判断输入变量个数的函数
% Number of nests (or different solutions)
n=25;
end% Discovery rate of alien eggs/solutions
pa=0.25;%% Change this if you want to get better results
% Tolerance
Tol=1.0e-5;                                                                 %为最大迭代次数限制
%% Simple bounds of the search domain
% Lower bounds
nd=15;
Lb=-5*ones(1,nd);
% Upper bounds
Ub=5*ones(1,nd);%随机产生初始解
% Random initial solutions
for i=1:n,
nest(i,:)=Lb+(Ub-Lb).*rand(size(Lb));
end%得到当前的最优解
% Get the current best
fitness=10^10*ones(n,1);
[fmin,bestnest,nest,fitness]=get_best_nest(nest,nest,fitness);N_iter=0;                                                                   %开始迭代
%% Starting iterations
while (fmin>Tol),% Generate new solutions (but keep the current best)new_nest=get_cuckoos(nest,bestnest,Lb,Ub);   [fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness);% Update the counterN_iter=N_iter+n; % Discovery and randomizationnew_nest=empty_nests(nest,Lb,Ub,pa) ;% Evaluate this set of solutions[fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness);% Update the counter againN_iter=N_iter+n;% Find the best objective so far  if fnew<fmin,fmin=fnew;bestnest=best;end
end %% End of iterations(迭代)%% Post-optimization processing
%% Display all the nests
disp(strcat('Total number of iterations=',num2str(N_iter)));
fmin
bestnest%% --------------- All subfunctions are list below ------------------
%% Get cuckoos by ramdom walk
function nest=get_cuckoos(nest,best,Lb,Ub)
% Levy flights
n=size(nest,1);
% Levy exponent and coefficient
% For details, see equation (2.21), Page 16 (chapter 2) of the book
% X. S. Yang, Nature-Inspired Metaheuristic Algorithms, 2nd Edition, Luniver Press, (2010).
beta=3/2;
sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta);for j=1:n,s=nest(j,:);% This is a simple way of implementing Levy flights% For standard random walks, use step=1;%% Levy flights by Mantegna's algorithmu=randn(size(s))*sigma;v=randn(size(s));step=u./abs(v).^(1/beta);% In the next equation, the difference factor (s-best) means that % when the solution is the best solution, it remains unchanged.     stepsize=0.01*step.*(s-best);% Here the factor 0.01 comes from the fact that L/100 should the typical% step size of walks/flights where L is the typical lenghtscale; % otherwise, Levy flights may become too aggresive/efficient, % which makes new solutions (even) jump out side of the design domain % (and thus wasting evaluations).% Now the actual random walks or flightss=s+stepsize.*randn(size(s));% Apply simple bounds/limitsnest(j,:)=simplebounds(s,Lb,Ub);
end%% Find the current best nest
function [fmin,best,nest,fitness]=get_best_nest(nest,newnest,fitness)
% Evaluating all new solutions
for j=1:size(nest,1),fnew=fobj(newnest(j,:));if fnew<=fitness(j),fitness(j)=fnew;nest(j,:)=newnest(j,:);end
end
% Find the current best
[fmin,K]=min(fitness) ;
best=nest(K,:);%% Replace some nests by constructing new solutions/nests
function new_nest=empty_nests(nest,Lb,Ub,pa)
% A fraction of worse nests are discovered with a probability pa
n=size(nest,1);
% Discovered or not -- a status vector
K=rand(size(nest))>pa;% In the real world, if a cuckoo's egg is very similar to a host's eggs, then
% this cuckoo's egg is less likely to be discovered, thus the fitness should
% be related to the difference in solutions.  Therefore, it is a good idea
% to do a random walk in a biased way with some random step sizes.
%% New solution by biased/selective random walks
stepsize=rand*(nest(randperm(n),:)-nest(randperm(n),:));
new_nest=nest+stepsize.*K;% Application of simple constraints
function s=simplebounds(s,Lb,Ub)% Apply the lower boundns_tmp=s;I=ns_tmp<Lb;ns_tmp(I)=Lb(I);% Apply the upper bounds J=ns_tmp>Ub;ns_tmp(J)=Ub(J);% Update this new move s=ns_tmp;%% You can replace the following by your own functions
% A d-dimensional objective function
function z=fobj(x)
%% d-dimensional sphere function sum_j=1^d (u_j-1)^2.
%  with a minimum at (1,1, ...., 1);
sum=0;
global nd;
for i=1:ndsum=sum+x(i)^2;
end
z=sum;

三、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
[3]周品.MATLAB 神经网络设计与应用[M].清华大学出版社,2013.
[4]陈明.MATLAB神经网络原理与实例精解[M].清华大学出版社,2013.
[5]方清城.MATLAB R2016a神经网络设计与应用28个案例分析[M].清华大学出版社,2018.

【优化预测】基于matlab布谷鸟算法优化SVM预测【含Matlab源码 1422期】相关推荐

  1. 【PID优化】基于花朵授粉算法PID控制器优化设计含Matlab源码

    ​1 内容介绍 PID参数优化对PID控制性能起着决定性作用,针对PID参数寻优问题,提出运用一种花授粉算法(FPA).该算法启发于自然界中花粉的传播授粉过程,以三个PID参数组成每个花粉单元的位置坐 ...

  2. 【Matlab电力负荷预测】粒子群优化支持向量机短期电力负荷预测【含GUI源码 751期】

    一.代码运行视频(哔哩哔哩) [Matlab电力负荷预测]粒子群优化支持向量机短期电力负荷预测[含GUI源码 751期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 ...

  3. 【Matlab验证码识别】遗传算法和最大熵优化+大津法(OTSU)+自定义阈值数字验证码识别【含GUI源码 1694期】

    一.代码运行视频(哔哩哔哩) [Matlab验证码识别]遗传算法和最大熵优化+大津法(OTSU)+自定义阈值数字验证码识别[含GUI源码 1694期] 二.matlab版本及参考文献 1 matlab ...

  4. 【MVO TSP】基于matlab灰狼算法求解旅行商问题【含Matlab源码 1327期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[TSP]基于matlab灰狼算法求解旅行商问题[含Matlab源码 1327期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2: ...

  5. 【BA TSP】基于matlab蜜蜂算法求解旅行商问题【含matlab源码 1248期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[TSP]基于matlab蜜蜂算法求解旅行商问题[含matlab源码 1248期] 获取代码方式2: 付费专栏Matlab路径规划(初级版 ...

  6. 【IA TSP】基于matlab免疫算法求解旅行商问题【含Matlab源码 195期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[旅行商问题]基于matlab免疫算法求解旅行商问题[含Matlab源码 195期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2 ...

  7. 【Matlab破损识别】机器视觉+SVM玉米种子破损识别(带面板)【含GUI源码 1651期】

    一.代码运行视频(哔哩哔哩) [Matlab破损识别]机器视觉+SVM玉米种子破损识别(带面板)[含GUI源码 1651期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考 ...

  8. 【Matlab图像加密】正交拉丁方置乱算法图像加解密【含GUI源码 182期】

    一.代码运行视频(哔哩哔哩) [Matlab图像加密]正交拉丁方置乱算法图像加解密[含GUI源码 182期] 二.matlab版本及参考文献 一.代码运行视频(哔哩哔哩) [Matlab图像处理]自动 ...

  9. 【Matlab图像融合】小波变换遥感图像融合【含GUI源码 744期】

    一.代码运行视频(哔哩哔哩) [Matlab图像融合]小波变换遥感图像融合[含GUI源码 744期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 包子阳,余 ...

  10. 【Matlab指纹识别】指纹识别门禁系统【含GUI源码 1692期】

    一.代码运行视频(哔哩哔哩) [Matlab指纹识别]指纹识别门禁系统[含GUI源码 1692期] 二.matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 包子阳,余继 ...

最新文章

  1. Linux进程管理: 多进程编程
  2. ## *将以下学生成绩数据,存放在Hdfs上,使用Spark读取完成下面分析**
  3. # 对象json互相转换_推荐一款 Java 对象映射神器
  4. java版DVD影碟片出租赁系统C/S模式 java电影购票系统课程设计
  5. Python 装饰器 函数
  6. [转载] 常用应届生Java开发笔试面试题(更新中)
  7. Android 系统(94)---Android属性之build.prop生成过程分析
  8. Spark SQL兼容Hive及扩展
  9. java none怎么用tomcat_在docker中部署tomcat并且部署java应用程序的步骤详解
  10. 使用Doxygen + graphviz生成Unity 3d的UGUI类图
  11. C++ string用法
  12. Python 多线程7-线程通信
  13. java程序员挣外快_Java程序员如何赚外快
  14. 计算机辅助三维设计大纲,《电脑辅助三维设计》课程教学大纲.doc
  15. java resourcebundle_java.util.ResourceBundle使用详解
  16. python实验原理_python实验报告5
  17. 东哥带你们认清五险一金︿( ̄︶ ̄)︿
  18. “数据打通”不等于“数据共融”,智能数据营销解决方案了解一下
  19. 混合硬盘计算机,什么是混合硬盘 什么是hhd硬盘?
  20. 为了整出自主的CPU,他们死磕了20年。

热门文章

  1. 动态规划-有关计数问题的DP-多重集组合数
  2. AngularJS图片上传功能的实现
  3. jquery 删除数组元素
  4. [转]良好用户体验的网站主页需具备12个特征
  5. 2020-08-18 每日一句
  6. Atitit webclient httpclient技术总结 RestTemplate Atitit CateIT重要技术httpclient iduah2 impt 体系树路径:CS
  7. Atitit.spring体系结构大总结 1. Spel表达式解析 1 2. Srping mvc 1 3. Ioc 4 3.1. ApplicationContext在BeanFactory的基础
  8. Atitit websocket 的前后端实现最佳实践t66 目录 1. 技术选型 1 2. 1.首先,在pom.xml引入如下jar包。Java-WebSocket-1.3.0.jar 1 3.
  9. Atitit java播放mp3 目录 1.1. 不能直接支持mp3播放。。需要解码播放转化为pcm 1 1.2. 使用\javalayer类库播放 3 1.3. ,就是普通的java sound
  10. Atitit 提升开发效率使用内嵌Tomcat 内嵌webserver 于单元测试