声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 5143|回复: 5

[工具箱] matlab7.0版本中遗传算法怎么设置变量范围呢

[复制链接]
发表于 2006-5-14 17:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

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

[ 本帖最后由 eight 于 2007-10-6 22:28 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-10-6 22:27 | 显示全部楼层
我也遇到了此问题,翻了很久的资料和书(包括上网),也没有发现答案。高手帮忙,谢谢啊
发表于 2008-11-15 20:33 | 显示全部楼层

回复 沙发 dunmin 的帖子

[0.1 0.3;1 3]这样就是定义了(0.1,1)(0.3,3)这样的两个变量;
但是我现在也遇到了一个问题,就是定了之后,只有第一个种群数在里面,后面的都不在里面了,而且还是负数,不知道是不是我交叉变异那里是否出了问题!
发表于 2008-11-22 16:07 | 显示全部楼层

迷惑不解

有谁知道matlab7.0的变量范围定义问题。我也遇到了同样问题,随后的种群不在最初定义的范围,也是到最后得到的适应度是负数。:@L
发表于 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 编辑 ]

评分

1

查看全部评分

发表于 2009-2-20 17:33 | 显示全部楼层
谢谢楼上的解答,我也遇到了这个问题,照你说的改改试试
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-29 17:38 , Processed in 0.065918 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表