mutation.m

来自「遗传算法和bp神经网络结合matlab源码」· M 代码 · 共 28 行

M
28
字号
function y=mutation(chrom,P_mutation,Popsize,ecope)  %均匀变异

m=25;
% P=rand(Popsize,1);
% n=find(P<P_mutation);
% len=length(n);
% for i=1:len
%     d=fix(9*rand(1))+1;
%     x=4*rand(1)-2;
%     chrom(n(i),d)=x;  %
% end
P=rand(size(chrom));
n=find(P<P_mutation);
len=length(n);
% R=4/ecope;
for i=1:len
    tem_a=chrom(n(i));
    R=min(m-tem_a,tem_a-m);
    tem_a=tem_a+R*2*rand-R;
    if tem_a>m
        tem_a=m-rand;
    elseif tem_a<-m
        tem_a=-m+rand;
    end
        
    chrom(n(i))=tem_a;
end
y=chrom;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?