今天我要讲的内容是布谷鸟算法,英文叫做Cuckoo search (CS algorithm)。首先还是同样,介绍一下这个算法的英文含义, Cuckoo是布谷鸟的意思,啥是布谷鸟呢,是一种叫做布谷的鸟,o(∩_∩)o ,这种鸟她妈很懒,自己生蛋自己不养,一般把它的宝宝扔到别的种类鸟的鸟巢去。但是呢,当孵化后,遇到聪明的鸟妈妈,一看就知道不是亲生的,直接就被鸟妈妈给杀了。于是这群布谷鸟宝宝为了保命,它们就模仿别的种类的鸟叫,让智商或者情商极低的鸟妈妈误认为是自己的亲宝宝,这样它就活下来了。 Search指的是搜索,这搜索可不是谷歌一下,你就知道。而是搜索最优值,举个简单的例子,y=(x-0.5)^2+1,它的最小值是1,位置是(0.5,1),我们要搜索的就是这个位置。

现在我们应该清楚它是干嘛的了吧,它就是为了寻找最小值而产生的一种算法,有些好装X的人会说,你傻X啊,最小值不是-2a/b吗,用你找啊? 说的不错,确实是,但是要是我们的函数变成 y=sin(x^3+x^2)+e^cos(x^3)+log(tan(x)+10,你怎么办吶?你解不了,就算你求导数,但是你知道怎么解导数等于0吗?所以我们就得引入先进的东西来求最小值。

为了使大家容易理解,我还是用y=(x-0.5)^2+1来举例子,例如我们有4个布谷鸟蛋(也就是4个x坐标),鸟妈妈发现不是自己的宝宝的概率是0.25,我们x的取值范围是[0,1]之间,于是我们就可以开始计算了。

目标:求x在[0,1]之内的函数y=(x-0.5)^2+1最小值

(1)初始化x的位置,随机生成4个x坐标,x1=0.4,x2=0.6,x3=0.8,x4=0.3 ——> X=[0.4, 0.6 ,0.8, 0.3]

(2)求出y1~y4,把x1~x4带入函数,求得Y=[1,31, 1.46, 1.69, 1.265],并选取当前最小值ymin= y4=1.265

(3)开始定出一个y的最大值为Y_global=INF(无穷大),然后与ymin比较,把Y中最小的位置和值保留,例如Y_global=INF>ymin=1.265,所以令Y_global=1.265

(4)记录Y_global的位置,(0.3,1.265)。

(5)按概率0.25,随机地把X中的值过塞子,选出被发现的蛋。例如第二个蛋被发现x2=0.6,那么他就要随机地变换位子,生成一个随机数,例如0.02,然后把x2=x2+0.02=0.62,之后求出y2=1.4794。那么X就变为了X=[0.4, 0.62 ,0.8, 0.3],Y=[1,31, 1.4794, 1.69, 1.265]。

(6)进行莱维飞行,这名字听起来挺高大上,说白了,就是把X的位置给随机地改变了。怎么变?有一个公式x=x+alpha*L。

L=S*(X-Y_global)*rand3

S=[rand1*sigma/|rand2|]^(1/beta)

sigma=0.6966

beta=1.5

alpha=0.01

rand1~rand3为正态分布的随机数

然后我们把X=[0.4, 0.6 ,0.8, 0.3]中的x1带入公式,首先随机生成rand1=-1.2371,rand2=-2.1935,rand3=-0.3209,接下来带入公式中,获得x1=0.3985

之后同理计算:

x2=0.6172

x3=0.7889

x4=0.3030

(7)更新矩阵X,X=[0.3985, 0.6172, 0.7889, 0.3030]

(8)计算Y=[1.3092, 1.4766, 1.6751, 1.2661],并选取当前最小值ymin= y4=1.2661,然后与ymin比较,把Y中最小的位置和值保留,例如Y_global=1.265

(9)返回步骤(5)用更新的X去循环执行,经过多次计算即可获得y的最优值和的最值位置(x,y)

代码:

% -----------------------------------------------------------------

% 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 inthe 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. %

% -----------------------------------------------------------------

% Additional Note: This version uses a fixed number of generation %

% (not a given tolerance) because many readers asked me to add %

% or implement this option. Thanks.%function [bestnest,fmin]=cuckoo_search_new(n)if nargin<1,%Number of nests (or different solutions)

n=25;

end% Discovery rate of alien eggs/solutions

pa=0.25;%% Change this if you want to getbetter results

N_IterTotal=1000;%%Simple bounds of the search domain%Lower bounds

nd=15;

Lb=-5*ones(1,nd);%Upper bounds

Ub=5*ones(1,nd);%Random initial solutionsfor 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 iterationsfor iter=1:N_IterTotal,% Generate newsolutions (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 counter

N_iter=N_iter+n;%Discovery and randomization

new_nest=empty_nests(nest,Lb,Ub,pa) ;% Evaluate this setof solutions

[fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness);%Update the counter again

N_iter=N_iter+n;%Find the best objective so farif fnew

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 isa simple way of implementing Levy flights% For standard random walks, use step=1;%% Levy flights by Mantegna's algorithm

u=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 isthe best solution, it remains unchanged.

stepsize=0.01*step.*(s-best);% Here the factor 0.01 comes from the fact that L/100should the typical% step size of walks/flights where L isthe typical lenghtscale;% otherwise, Levy flights may become too aggresive/efficient,% which makes new solutions (even) jump outside of the design domain%(and thus wasting evaluations).%Now the actual random walks or flights

s=s+stepsize.*randn(size(s));% Apply simple bounds/limits

nest(j,:)=simplebounds(s,Lb,Ub);

end%%Find the current best nest

function [fmin,best,nest,fitness]=get_best_nest(nest,newnest,fitness)% Evaluating all newsolutionsfor 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 isa good idea% to do a random walk ina 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;for j=1:size(new_nest,1)

s=new_nest(j,:);

new_nest(j,:)=simplebounds(s,Lb,Ub);

end%Application of simple constraints

function s=simplebounds(s,Lb,Ub)%Apply the lower bound

ns_tmp=s;

I=ns_tmp

ns_tmp(I)=Lb(I);%Apply the upper bounds

J=ns_tmp>Ub;

ns_tmp(J)=Ub(J);% Update this newmove

s=ns_tmp;%%You can replace the following by your own functions% A d-dimensional objective function

function z=fobj(u)%% d-dimensional sphere function sum_j=1^d (u_j-1)^2.% with a minimum at (1,1, ...., 1);

z=sum((u-1).^2);

版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/u013631121/article/details/76944879

布谷鸟哈希函数的参数_布谷鸟算法详细讲解相关推荐

  1. 布谷鸟哈希函数的参数_用于并发读密集型的乐观Cuckoo(布谷鸟) Hashing

    用于并发读密集型的乐观Cuckoo(布谷鸟) Hashing:Optimistic Cuckoo Hashing for concurrent, read-intensive applications ...

  2. 布谷鸟哈希函数的参数_系统学习hash算法(哈希算法)

    系统学习hash算法(哈希算法) 转载请说明出处. 前言: 关于本文<系统学习hash算法>的由来.在看到了<十一.从头到尾彻底解析Hash 表算法>这篇文章之后,原文中没有暴 ...

  3. 布谷鸟哈希函数的参数_Cuckoo Hash 布谷鸟哈希

    布谷鸟哈希最早于2001 年由Rasmus Pagh 和Flemming Friche Rodler 提出.该哈希方法是为了解决哈希冲突的问题而提出,利用较少计算换取了较大空间.名称源于该哈希方法行为 ...

  4. 布谷鸟哈希函数的参数_Cuckoo Hash 布谷鸟哈希

    查看原文:http://www.dullgull.com/2012/05/cuckoo-hash-%e5%b8%83%e8%b0%b7%e9%b8%9f%e5%93%88%e5%b8%8c/ 布谷鸟哈 ...

  5. js有默认参数的函数加参数_函数参数:默认,关键字和任意

    js有默认参数的函数加参数 PYTHON开发人员的提示 (TIPS FOR PYTHON DEVELOPERS) Think that you are writing a function that ...

  6. python怎么理解函数的参数_理解Python中函数的参数

    定义函数的时候,我们把参数的名字和位置确定下来,函数的接口定义就完成了.对于函数的调用者来说,只需要知道如何传递正确的参数,以及函数将返回什么样的值就够了,函数内部的复杂逻辑被封装起来,调用者无需了解 ...

  7. 函数传参数_算法笔记(7)第二章C、C++快速入门函数,main函数,

    #includevoid change(int x){ x=x+1;}int main(){ int x=10; change(x); prinf("%d\n",x); retur ...

  8. mysql函数输出参数_函数--返回值、参数和作用域

    一.函数的返回值--return的作用 1.return将return后面的值作为函数的输出返回值,当函数被调用时,返回值可以被其他变量接收.使用. 而print只是打印在控制台,一个函数如果没有re ...

  9. 哈希函数的特征_哈希函数及其特征

    哈希函数的特征 Prerequisite: Hashing data structure 先决条件: 哈希数据结构 The hash function is the component of hash ...

  10. mysql 自定义哈希函数_C++ STL无序容器自定义哈希函数和比较规则(超级详细)...

    前面在讲解 unordered_map.unordered_multimap.unordered_set 以及 unordered_multiset 这 4 种无序关联式容器(哈希容器)时,遗留过一个 ...

最新文章

  1. 2021-2027年中国一氧化氮行业市场研究及前瞻分析报告
  2. IntelliJ IDEA 的 .idea 目录加入.gitignore无效的解决方法
  3. 大数据学习——spark安装
  4. 【网址收藏】WIN10进入超级管理员账号(Administrator)
  5. python爬去朋友圈_利用Python爬取朋友圈数据,爬到你开始怀疑人生
  6. 算法高级(36)-如何利用并行提高算法的执行效率?
  7. 云和恩墨技术通讯:Oracle AMM自动内存管理引起数据库阻塞
  8. 在 Delphi 6 中使用 Hashtable
  9. 解决python中 .to_csv() 的乱码问题
  10. [转载] Python——函数练习(包括简单递归)
  11. hadoop重新启动之后Datanode无法启动的问题
  12. Redhat 5.4 Oracle 10g RAC 删除节点
  13. 树中两个节点的最低公共祖先节点
  14. mapgis坡度分析_gis气候分析图_用MAPGIS做城市气候的分析需要什么类型的数据可以从哪下载_滁州气象...
  15. W25Q64 的 QSPI 模式 问题
  16. 吴恩达张潼接受WSJ采访:如何让AI像电力一样颠覆世界?
  17. Rust: Descending Order
  18. 【有料c++题目周刊 | 第一期】希腊诸神
  19. css 实现图片间用间隔线(竖线)
  20. 值得收藏的12款小众冷门但功能强大的在线神器

热门文章

  1. 【PR】一看就会的常用视频效果
  2. bim 水利枢纽 运维_BIM技术与现代化建筑运维管理
  3. 步进电机怎么选型?步进电机驱动器选型要怎么选?
  4. sas入门学习 via.数说工作室
  5. 独家 | 精彩!这27本书籍,每位数据科学家都应该阅读(附说明图表)
  6. OpenDRIVE坐标系解读
  7. MicroSIP软电话的安装和使用--从电脑上接听和拨打电话
  8. Micro Sip 配置自己的freeswitch服务器地址
  9. 送书 | 别泡枸杞,别晒步数!7招搞懂健康数据,有型有颜等TA来撩
  10. bt协议详解 DHT篇(上)