如何使用Sheffield大学的Matlab GA遗传算法工具箱

本文假设阅读本文章的各位已经安装好工具箱,并基于个人对Sheffield工具箱的理解,以1.2版本的工具箱为例,对函数进行简单讲解。

SheffieldGA工具箱在CONTENTS.M文件中给出其工具箱内各函数的定义:

% Creating populations
%   crtbase	- create a base vector
%   crtbp	- create a binary population
%   crtrp	- create a real-valued population
%   
% Fitness assignment
%   ranking	- rank-based fitness assignment
%   scaling	- proportional fitness-scaling
%   
% Selection and reinsertion
%   reins	- uniform random and fitness-based reinsertion
%   rws		- roulette wheel selection
%   select	- high-level selection routine
%   sus		- stochastic universal sampling
%   
% Mutation operators
%   mut		- discrete mutation
%   mutate	- high-level mutation function
%   mutbga	- real-value mutation

以selection and reinsertion为例,工具箱中包含三个较基本的operator(即reins,rws与sus三个选择函数)与一较高级的函数select。在select.m中可以找到该函数的调用格式:

% Syntax:  SelCh = select(SEL_F, Chrom, FitnV, GGAP, SUBPOP)
%
% Input parameters:
%    SEL_F     - Name of the selection function
%    Chrom     - Matrix containing the individuals (parents) of the current
%                population. Each row corresponds to one individual.
%    FitnV     - Column vector containing the fitness values of the
%                individuals in the population.
%    GGAP      - (optional) Rate of individuals to be selected
%                if omitted 1.0 is assumed
%    SUBPOP    - (optional) Number of subpopulations
%                if omitted 1 subpopulation is assumed
%
% Output parameters:
%    SelCh     - Matrix containing the selected individuals.

注意对于标注为(optional)的参数,在调用该函数时可以省略。程序将使用一函数给定的默认值进行计算。对于select函数,其调用哪种较基本的选择函数由调用select函数时的字串SEL_F给出,有效的字串取值即为较为基本的三个函数文件名`reins`,`rws`与’sus’。在select.m的第63行中MATLAB程序使用指定的函数进行运算,ChrIx=feval(SEL_F, FitnVSub, NSel)+(irun-1)*Nind;
以轮盘赌选择函数为例,对某一群体矩阵Chrom和相应的适应度向量FitnV,调用select函数可写作SelCh = select('rws', Chrom, FitnV)

有关该语句可以通过参阅Mathworks的feval的文档加以理解。计算函数 - MATLAB feval - MathWorks 中国

对种群的生成可以使用crtrp生成一实数值初始种群,或使用crtbp生成一二进制的种群。注意在生成实数值种群时,初始种群个体值的取值范围由FieldDR矩阵进行指定。

% Syntax:       Chrom = crtrp(Nind,FieldDR);
%
% Input parameters:
%    Nind      - A scalar containing the number of individuals in the new 
%                population.
%
%    FieldDR   - A matrix of size 2 by number of variables describing the
%                boundaries of each variable. It has the following structure:
%                [lower_bound;   (vector with lower bound for each veriable)
%                 upper_bound]   (vector with upper bound for each veriable)
%                [lower_bound_var_1  lower_bound_var_2 ... lower_bound_var_Nvar;
%                 upper_bound_var_1  upper_bound_var_2 ... upper_bound_var_Nvar]
%                example - each individuals consists of 4 variables:
%                FieldDR = [-100 -50 -30 -20;   % lower bound
%                            100  50  30  20]   % upper bound

该矩阵中第一行元素描述初始种群值的下界,第二行描述种群值上界,也可以分别使用上下界向量对矩阵进行赋值。上下界向量的元素个数指定了生成的初始种群个体数据的维数。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值