|
免疫粒子群算法的函数寻优分析(MATLAB视频)
百度网盘链接:
链接:https://pan.baidu.com/s/125n5yEDQhulsRpj9qzfx6w
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,并提交给我,我来设置视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1
- % 基于免疫粒子群算法的函数寻优
- clc,clear,close all
- warning off
- tic % 计时开始
- %% AIA算法
- nvar = 2; % 2个未知数
- % 取值范围
- popmin = [-1, -1]; % Lb
- popmax =[ 1, 1]; % Ub
- itermax = 30; % 迭代次数
- sizepop = 30; % 种群
- Ak = -0.01; % 聚合适应度常数k
- lamda = 0.9; % 相似度常数[0.9,1]
- %% PSO 参数
- c1 = 1.4995;
- c2 = 1.4995;
- Vmin = -1;
- Vmax = 1;
- %% 初始化种群
- for i=1:sizepop
- pop(i,:) = code(popmin,popmax); % 实数编码
- V(i,1:nvar) = 0;
- fitness(i) = fun(pop(i,:)); % 目标函数值
- end
- [bestfitness,index] = min(fitness); % 极小值
- zbest = pop(index,:); % 最佳个体
- fitnesszbest = bestfitness; % 全局最优
- gbest=pop; % 个体最佳
- fitnessgbest=fitness; % 个体最佳适应度值
- %% 迭代寻优
- for i=1:itermax
- % 选择算子
- pop = select_AIA(sizepop,pop,fitness,popmin,popmax);
- % % 交叉算子
- % pop = cross_AIA(sizepop,pop,popmin,popmax);
- % % 变异
- % pop = mutation_AIA(sizepop,pop,popmin,popmax);
- % 计算相似度
- for j=1:sizepop
- % AIA计算相似度
- AN = 1./( 1+norm( zbest-pop(j,:), 2 ) );
- if(AN>lamda)
- Ci = 1;
- else
- Ci = 0;
- end
- fitness(j) = fun( pop(j,:) ) .* exp( Ak*Ci ); % 计算适应度值
-
- % 速度更新
- V(j,:) = V(j,:) + c1*rand*(gbest(j,:) - pop(j,:)) + c2*rand*(zbest - pop(j,:));
- % V范围约束
- V(j,:) = lb_ub(V(j,:), Vmin, Vmax);
- % 个体更新
- newpop = pop(j,:) + 0.5 * V(j,:);
- % pop范围约束
- newpop = lb_ub(newpop, popmin, popmax);
-
- % PSO计算相似度
- AN = 1./( 1+norm( zbest-newpop, 2 ) );
- if(AN>lamda)
- Ci = 1;
- else
- Ci = 0;
- end
- newfitness = fun( newpop ) .* exp( Ak*Ci ); % 计算适应度值
- if newfitness<fitness(j)
- fitness(j) = newfitness;
- pop(j,:)=newpop;
- end
-
- % 交叉算子
- pop1 = cross_AIA2(sizepop,pop,popmin,popmax);
- % AIA计算相似度
- AN = 1./( 1+norm( zbest-pop1, 2 ) );
- if(AN>lamda)
- Ci = 1;
- else
- Ci = 0;
- end
- fitness1 = fun( pop1 ) .* exp( Ak*Ci ); % 计算适应度值
- if fitness1<fitness(j)
- fitness(j) = fitness1;
- pop(j,:)=pop1;
- end
-
- % 变异
- pop2 = mutation_AIA2(sizepop,pop,popmin,popmax);
- % AIA计算相似度
- AN = 1./( 1+norm( zbest-pop2, 2 ) );
- if(AN>lamda)
- Ci = 1;
- else
- Ci = 0;
- end
- fitness2 = fun( pop2 ) .* exp( Ak*Ci ); % 计算适应度值
- if fitness2<fitness(j)
- fitness(j) = fitness2;
- pop(j,:)=pop2;
- end
-
- % 比较 个体间比较
- if fitness(j)<fitnessgbest(j)
- fitnessgbest(j) = fitness(j);
- gbest(j,:) = pop(j,:);
- end
- if fitness(j)<bestfitness
- bestfitness = fitness(j);
- zbest = pop(j,:);
- end
-
- end
-
- fitness_iter(i) = bestfitness;
- end
- toc; % 结束开始
- figure,
- plot(fitness_iter,'ro-','linewidth',2)
- % loglog(fitness_iter,'ro-','linewidth',2)
- grid on
- axis tight
- disp(['最优解 ', num2str(zbest)] )
复制代码
|
|