plot.m

来自「多目标遗传算法/用法不用多说、要用的赶快下载吧」· M 代码 · 共 74 行

M
74
字号
function plot(chr,varargin)% PLOT - plots the generations.  %   plot(chr,arch) plots the best member in each generation as well as%   the average value of the population.  The argument chr should be a%   mxn matrix with m generations and n chromosomes. The second%   argument arch should be a vector consisting of the prototypes of%   the different species.  If specified the best of each species in%   each generation are plotted in a separate figure. If not specified%   only the best and the average values are plotted.figurea=mean(chr);m=max(chr);plot(m);xlabel('Generation')hold on title('Max and average fitness for the population');plot(a,'r');ylabel('Fitness')legend('max','average',4)colour={'b' 'r-.' 'm:' 'k' 'c' 'g' 'y' };if ~isempty(varargin)  figure  title('Max values of each species')  hold on  [m n]=size(chr);  for k=1:length(varargin{1})    name=get(varargin{1}(k),'name');    leg{k}=strcat('Species: ',name);    for l=1:m      tmp_ind=find(chr(l,:),name);      if tmp_ind	tmp_pop=chr(l,tmp_ind);	ma(l)=max(tmp_pop);	mi(l)=min(tmp_pop);      end    end    plot(ma,colour{k});    xlabel('Generation')    ylabel('Fitness')  end  legend(leg,4)  %Plot of nmbr of # members in the generations   figure  title('Distribution of members')  hold on  for j=1:length(varargin{1})    name=get(varargin{1}(j),'name');    leg{j}=strcat('Species: ',name);    for i=1:m      tmp=find(chr(i,:),name);      if tmp(1)~=0	nmbr(i)=length(tmp);      else	nmbr(i)=0;      end    end    plot(1:m,nmbr,colour{j})  end    xlabel('Generation')  ylabel('# of members')  legend(leg,4)end

⌨️ 快捷键说明

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