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

📄 probmut.m

📁 一些用matlab编写的经典遗传算法算例。可以用于解决许多优化问题
💻 M
字号:
function pmut = probmut(chr,muteinfo)
% PROBMUT - Calculates the probability of mutation in the population.
%
%   pmut=probmut(chr,muteinfo) returns the probability of mutation,
%   given the population (chr) and the mutation information (muteinfo).
%   The argument muteinfo is a structure containing user supplied
%   information, it is most easily constructed with ui_mutate.
%   Every species is assigned a probability of mutation and
%   transmutation.  Currently a constant is used for transmutaion.
%   For mutation within a species a constant can be choosen, or the
%   probability of mutation is calculated using the diversity of
%   the subpopulation. 
%
% See also UI_MUTATE, MUTATE, CHILDREN

len_pop=length(chr);
for k=1:length(muteinfo);
  
  mut_lim=muteinfo(k).mut_lim;
  if isempty(mut_lim)
    pm=muteinfo(k).pc;
  else
  
    p_min=muteinfo(k).mut_lim(1);
    p_max=muteinfo(k).mut_lim(2);
    population=create_pop(chr,muteinfo(k).name);
    
    kk=-1*log(p_min/p_max);
    d=diverse(population);
    if d>1
      d=1;
    end
    if d<0
      d=0;
    end
    pm=p_max*exp(-1*kk*d);
  end
  
  muteinfo(k).pc=pm;
  pmut(k)=muteinfo(k);
  if isempty(pmut(k).trans)
    pmut(k).trans=[];
  else
    pmut(k).trans=nmbr_of_members(chr,muteinfo(k).name)/len_pop;
  end
end 
    
function pop = create_pop(chr,name)
% CREATE_POP - Creates an old fashioned population
%   
ind=find(chr,name);
c=chr(ind);

for k=1:length(c);
  cdvs=get(c(k),'cdvs');
  ddvs=get(c(k),'ddvs');
  if ~isempty(cdvs)
    tmp=[];
    for l=1:length(cdvs);
      tmp=[tmp get(cdvs(l),'dna')];
    end
  end
  
  if ~isempty(ddvs)
    for l=1:length(cdvs);
      tmp=[tmp get(ddvs(l),'dna')];
    end
  end
  dn(k,:)=tmp;
end
pop=dn;


function [d]=diverse(population)
%
% Type d=diverse(population)
%

%
% This function calculates the diversity of the population,
% using a "entropy like" measure.
%

%  Copyright (c) 1994-1995 by David C. Zimmerman.  All rights reserved

[m,n]=size(population);
p_one=sum(population)/m;
p_zero=1-p_one;
p_one=p_one.*log(p_one+ (1e-10));
p_zero=p_zero.*log(p_zero+(1e-10));
d=-1*(sum(p_one) + sum(p_zero))/(n*log(2));










⌨️ 快捷键说明

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