⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot.m

📁 一些用matlab编写的经典遗传算法算例 挺有用的
💻 M
字号:
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.
figure
a=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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -