【优化算法】头脑风暴优化算法(BSO)【含Matlab源码 497期】

2021-06-29 02:05

阅读:307

标签:alt   RoCE   loading   step   dimen   技术   简介   intro   产生   

一、简介

1 算法原理
头脑风暴优化算法主要由聚类和变异组成。
1.1 聚类
聚类:BSO采用K-means聚类算法,将相似的个体聚成k类,并将人为设定的适应度函数值最优的个体作为聚类的中心。当然,为了避免陷入局部最优,将有概率随机产生一个新个体替换其中
一个聚类中心。
1.2 变异
BSO变异主要有4种方式,分别是:(a)在随机一个类中心,即该类最优个体上添加随机扰动产生新的个体;(b)在随机一个类中随机选择一个个体添加随机扰动产生新的个体;?随机融合两个类中心,并添加随机扰动产生新的个体;(d)随机融合两个类中随机的两个个体,并添加随机扰动产生新的个体。
上述4种方式每个聚类中心,即类中最优个体
被选中的概率为:
技术图片
2 算法流程
技术图片

二、源代码

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  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()  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 

三、运行结果

技术图片

四、备注

版本:2014a
完整代码或代写加1564658423

【优化算法】头脑风暴优化算法(BSO)【含Matlab源码 497期】

标签:alt   RoCE   loading   step   dimen   技术   简介   intro   产生   

原文地址:https://www.cnblogs.com/homeofmatlab/p/14943974.html


评论


亲,登录后才可以留言!