【优化算法】头脑风暴优化算法(BSO)【含Matlab源码 497期】
【摘要】
一、获取代码方式
获取代码方式1: 完整代码已上传我的资源:【优化算法】头脑风暴优化算法(BSO)【含Matlab源码 497期】
获取代码方式2: 通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主...
一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【优化算法】头脑风暴优化算法(BSO)【含Matlab源码 497期】
获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、头脑风暴优化算法(BSO)简介
受人类创造性解决问题过程——头脑风暴会议的启发, 2011年史玉回老师在第二次群体智能国际会议 (The Second International Conference on Swarm Intelligence(ICSI11)) 中提出一种新的群智能优化算法——头脑风暴优化算法,算法采用聚 类思想搜索局部最优,通过局部最优的比较得到全局最优;采用变异思想增加了算法的多 样性,避免算法陷入局部最优,在这聚与散相辅相承的过程中搜索最优解,思想新颖,适合于解决多峰高维函数问题。
算法流程建模如下
算法步骤描述
三、部分源代码
function best_fitness = bso2(fun,n_p,n_d,n_c,rang_l,rang_r,max_iteration)
% fun = fitness_function
% n_p; population size
% n_d; number of dimension
% n_c: number of clusters
% rang_l; left boundary of the dynamic range
% rang_r; right boundary of the dynamic range
prob_one_cluster = 0.8; % probability for select one cluster to form new individual;
stepSize = ones(1,n_d); % effecting the step size of generating new individuals by adding random values
popu = rang_l + (rang_r - rang_l) * rand(n_p,n_d); % initialize the population of individuals
popu_sorted = rang_l + (rang_r - rang_l) * rand(n_p,n_d); % initialize the population of individuals sorted according to clusters
n_iteration = 0; % current iteration number
% initialize cluster probability to be zeros
prob = zeros(n_c,1);
best = zeros(n_c,1); % index of best individual in each cluster
centers = rang_l + (rang_r - rang_l) * rand(n_c,n_d); % initialize best individual in each cluster
centers_copy = rang_l + (rang_r - rang_l) * rand(n_c,n_d); % initialize best individual-COPY in each cluster FOR the purpose of introduce random best
best_fitness = 1000000*ones(max_iteration,1);
fitness_popu = 1000000*ones(n_p,1); % store fitness value for each individual
fitness_popu_sorted = 1000000*ones(n_p,1); % store fitness value for each sorted individual
indi_temp = zeros(1,n_d); % store temperary individual
%**************************************************************************
%**************************************************************************
% calculate fitness for each individual in the initialized population
for idx = 1:n_p
fitness_popu(idx,1) = fun(popu(idx,:));
end
while n_iteration < max_iteration
cluster = kmeans(popu, n_c,'Distance','cityblock','Start',centers,'EmptyAction','singleton') % k-mean cluster
% clustering
fit_values = 100000000000000000000000000.0*ones(n_c,1); % assign a initial big fitness value as best fitness for each cluster in minimization problems
number_in_cluster = zeros(n_c,1); % initialize 0 individual in each cluster
for idx = 1:n_p
number_in_cluster(cluster(idx,1),1)= number_in_cluster(cluster(idx,1),1) + 1;
% find the best individual in each cluster
if fit_values(cluster(idx,1),1) > fitness_popu(idx,1) % minimization
fit_values(cluster(idx,1),1) = fitness_popu(idx,1);
best(cluster(idx,1),1) = idx;
end
end
best
% form population sorted according to clusters
counter_cluster = zeros(n_c,1); % initialize cluster counter to be 0
acculate_num_cluster = zeros(n_c,1); % initialize accumulated number of individuals in previous clusters
for idx =2:n_c
acculate_num_cluster(idx,1) = acculate_num_cluster((idx-1),1) + number_in_cluster((idx-1),1);
end
%start form sorted population
for idx = 1:n_p
counter_cluster(cluster(idx,1),1) = counter_cluster(cluster(idx,1),1) + 1 ;
temIdx = acculate_num_cluster(cluster(idx,1),1) + counter_cluster(cluster(idx,1),1);
popu_sorted(temIdx,:) = popu(idx,:);
fitness_popu_sorted(temIdx,1) = fitness_popu(idx,1);
end
% record the best individual in each cluster
for idx = 1:n_c
centers(idx,:) = popu(best(idx,1),:);
end
centers_copy = centers % make a copy
if (rand() < 0.2) % select one cluster center to be replaced by a randomly generated center
cenIdx = ceil(rand()*n_c);
centers(cenIdx,:) = rang_l + (rang_r - rang_l) * rand(1,n_d);
end
% calculate cluster probabilities based on number of individuals in
% each cluster
for idx = 1:n_c
prob(idx,1) = number_in_cluster(idx,1)/n_p;
if idx > 1
prob(idx,1) = prob(idx,1) + prob(idx-1,1);
end
end
% generate n_p new individuals by adding Gaussian random values
for idx = 1:n_p
r_1 = rand(); % probability for select one cluster to form new individual
if r_1 < prob_one_cluster % select one cluster
r = rand();
for idj = 1:n_c
if r < prob(idj,1)
if rand() < 0.4 % use the center
indi_temp(1,:) = centers(idj,:);
else % use one randomly selected cluster
indi_1 = acculate_num_cluster(idj,1) + ceil(rand() * number_in_cluster(idj,1));
indi_temp(1,:) = popu_sorted(indi_1,:);
end
break
end
end
else % select two clusters
% pick two clusters
cluster_1 = ceil(rand() * n_c);
indi_1 = acculate_num_cluster(cluster_1,1) + ceil(rand() * number_in_cluster(cluster_1,1));
cluster_2 = ceil(rand() * n_c);
indi_2 = acculate_num_cluster(cluster_2,1) + ceil(rand() * number_in_cluster(cluster_2,1));
tem = rand();
if rand() < 0.5 %use center
indi_temp(1,:) = tem * centers(cluster_1,:) + (1-tem) * centers(cluster_2,:);
else % use randomly selected individuals from each cluster
indi_temp(1,:) = tem * popu_sorted(indi_1,:) + (1-tem) * popu_sorted(indi_2,:);
end
end
%Griewank
function z = griewank(x)
% unimodal optimum 0
[m,n]=size(x);
for j=1:m
for e=1:n
f1(e)=x(j,e)^2;
f2(e)=cos(x(j,e)/sqrt(e));
end
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/118299787
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)