zlj 发表于 2006-5-14 17:49

matlab7.0版本中遗传算法怎么设置变量范围呢

求助高手:
matlab 7.0中自带的遗传算法工具箱怎么在里面设置变量范围呢?它的gatool里面只有initial range啊?谢谢!

[ 本帖最后由 eight 于 2007-10-6 22:28 编辑 ]

dunmin 发表于 2007-10-6 22:27

我也遇到了此问题,翻了很久的资料和书(包括上网),也没有发现答案。高手帮忙,谢谢啊

图立 发表于 2008-11-15 20:33

回复 沙发 dunmin 的帖子

这样就是定义了(0.1,1)(0.3,3)这样的两个变量;
但是我现在也遇到了一个问题,就是定了之后,只有第一个种群数在里面,后面的都不在里面了,而且还是负数,不知道是不是我交叉变异那里是否出了问题!

lhw_qdu 发表于 2008-11-22 16:07

迷惑不解

有谁知道matlab7.0的变量范围定义问题。我也遇到了同样问题,随后的种群不在最初定义的范围,也是到最后得到的适应度是负数。:@L

xxxxxxxxxx 发表于 2009-2-15 23:08

只需查看option中的变异函数mutationgaussian.m 然后打开它:open mutationgaussian 。在71行      mutationChildren(i,:) = parent+ scale .* randn(1,length(parent));
后面加上两行来控制范围即可。
      mutationChildren(i,find(mutationChildren(i,:)>upper))=upper(find(mutationChildren(i,:)>upper));
      mutationChildren(i,find(mutationChildren(i,:)<lower))=lower(find(mutationChildren(i,:)<lower));

整个函数mutationgaussian 的内容为:
function mutationChildren = mutationgaussian(parents,options,GenomeLength,FitnessFcn,state,thisScore,thisPopulation,scale,shrink)
%MUTATIONGAUSSIAN Gaussian mutation.
%   MUTATIONCHILDREN = MUTATIONGAUSSIAN(PARENTS,OPTIONS,GENOMELENGTH,...
%                      FITNESSFCN,STATE,THISSCORE,THISPOPULATION,SCALE, ...
%                      SRHINK) Creates the mutated children using gaussian
%   mutation. Mutated genes are gaussianly distributed about their parents
%   values.
%
%   SCALE controls what fraction of the gene's range is searched. A
%   value of 0 will result in no change, a SCALE of 1 will result in a
%   distribution whose standard deviation is equal to the range of this gene.
%   Intermediate values will produce ranges in between these extremes.
%
%   SHRINK controls how fast the SCALE is reduced as generations go by.
%   A SHRINK value of 0 will result in no shrinkage, yielding a constant search
%   size. A value of 1 will result in SCALE shrinking linearly to 0 as
%   GA progresses to the number of generations specified by the options
%   structure. (See 'Generations' in GAOPTIMSET for more details). Intermediate
%   values of SHRINK will produce shrinkage between these extremes.
%   Note: SHRINK may be outside the interval (0,1), but this is ill-advised.
%
%   Example:
%   options = gaoptimset('MutationFcn',{@mutationgaussian});
%   
%   This specifies that the mutation function used will be
%   MUTATIONGAUSSIAN, and since no values for SCALE or SHRINK are specified
%   the default values are used.
%   
%   scale = 0.5; shrink = 0.75;
%   options = gaoptimset('MutationFcn',{@mutationgaussian,scale,shrink});
%
%   This specifies that the mutation function used will be
%   MUTATIONGAUSSIAN, and the values for SCALE or SHRINK are specified
%   as 0.5 and 0.75 respectively.
%
%   Copyright 2003-2004 The MathWorks, Inc.
%   $Revision: 1.10.4.1 $$Date: 2004/08/20 19:48:37 $
% Use default parameters if the are not passed in.
% If these defaults are not what you prefer, you can pass in your own
% values when you set the mutation function:
%
% options.MutationFunction = { mutationgaussian, 0.3, 0} ;
%
if(strcmpi(options.PopulationType,'doubleVector'))
   
    if(nargin < 9)
      shrink = 1;
      if(nargin < 8)
            scale = 1;
      end
    end
   
    if (shrink > 1) || (shrink < 0)
      msg = sprintf('Shrink factors that are less than zero or greater than one may \n\t\t result in unexpected behavior.');
      warning('gads:MUTATIONGAUSSIAN:ShrinkFactor',msg);
    end
   
    scale = scale - shrink * scale * state.Generation/options.Generations;
   
    range = options.PopInitRange;
    lower = range(1,:);
    upper = range(2,:);
    scale = scale * (upper - lower);
   
    mutationChildren = zeros(length(parents),GenomeLength);
    for i=1:length(parents)
      parent = thisPopulation(parents(i),:);
      mutationChildren(i,:) = parent+ scale .* randn(1,length(parent));
       mutationChildren(i,find(mutationChildren(i,:)>upper))=upper(find(mutationChildren(i,:)>upper));
      mutationChildren(i,find(mutationChildren(i,:)<lower))=lower(find(mutationChildren(i,:)<lower));
    end
elseif(strcmpi(options.PopulationType,'bitString'))
    % there's no such thing as binary gaussian mutation se we'll just
    % revert to uniform.
    mutationChildren = mutationuniform(parents ,options, GenomeLength,FitnessFcn,state, thisScore,thisPopulation);
end

[ 本帖最后由 ChaChing 于 2009-2-16 08:20 编辑 ]

louisa 发表于 2009-2-20 17:33

谢谢楼上的解答,我也遇到了这个问题,照你说的改改试试
页: [1]
查看完整版本: matlab7.0版本中遗传算法怎么设置变量范围呢