📄 checkson.m
字号:
%#
%# function [ns]=checkson(newson,pop,chrom,xc,yc,cvgp,maxvar)
%#
%# AIM: Checks whether the two strings obtained after
%# cross-over and mutation obey the constraints
%# of the GA.
%#
%# PRINCIPLE: The children strings must obey a few constraints:
%# - they must have at least 1 variable.
%# - they must have at most maxvar variables.
%# - they must be different from each other, and from
%# any other member of the population.
%#
%# INPUT:
%# newson : (2 x col) the two children strings to test.
%# pop : (chrom x col) the actual population of strings.
%# chrom : the number of strings in the population.
%# xc, yc : (row x col) calibration set, on which the GA is run.
%# cvgp : Number of deletion groups for cross-validation.
%# maxvar : Maximum number of variables for selection.
%#
%# OUTPUT:
%# ns : (0,1,or 2 x col) matrix containing the children
%# strings which satisfy the constraints of the GA.
%#
%# SUBROUTINES:
%# stepson.m Performs a stepwise elimination if one string
%# contains more than 'maxvar' variables.
%#
%# AUTHOR: Delphine Jouan-Rimbaud
%# Copyright(c) 1997 for ChemoAC
%# FABI, Vrije Universiteit Brussel
%# Laarbeeklaan 103 1090 Jette
%#
%# VERSION: 1.1 (28/02/1998)
%#
%# TEST: Frederic Despagne
%#
function [ns]=checkson(newson,pop,chrom,xc,yc,cvgp,maxvar);
ns=newson;
if sum(newson(2,:)) > sum(newson(1,:))
ns(1,:)=newson(2,:);
ns(2,:)=newson(1,:);
end
% the strings are re-arranged, so that the one containing
% the highest number of variables is the first one in ns.
sumns1=sum(ns(1,:)); % Number of variables in the first string of ns
sumns2=sum(ns(2,:)); % Number of variables in the second string of ns
sumtot=sumns1+sumns2; % Total number of variables in the two strings.
% According to the requirements of the GA, sumtot should not exceed 2 x maxvar
if sumtot <= 2*maxvar
if sum(ns(1,:)) > maxvar
% In the original algorithm of Leardi, if the number of variables in
% ns(1,:) exceeds maxvar, the string is not evaluated, but is killed.
% In order not to lose what could be some important information, the
% following is done:
% Some variables of ns1 are transferred to ns2. This is possible, as
% there are fewer than 'maxvar' variables in ns(2,:).
% This step is a kind of cross-over, and avoids to discard blindly a potentially informative subset.
nb1=sum(ns(1,:))-maxvar; % Number of variables in excess
dns=ns(1,:)-ns(2,:);
f1=find(dns==1) ; % variables of ns(1,:) which are not selected in ns(2,:)
lf1=length(f1);
r1=randperm(lf1);
f1=f1(r1);
ns(1,f1(1:nb1))=zeros(1,nb1);
ns(2,f1(1:nb1))=ones(1,nb1);
% one randomly eliminates 'nb1' variables from ns(1,:),
% and places them into ns(2,:).
end
ns1=ns(1,:);
ns2=ns(2,:);
if ns1==ns2 % The two children strings cannot be equal.
% If they are, the less informative variable is removed from one string.
% This is done in STEPSON.M
[string1]=stepson(ns1,xc,yc,cvgp,1);
ns1=string1; clear string1
end
end
if sumtot > 2*maxvar
% In this case, one cannot transfer all variables in excess
% from one string to the other one.
% The less informative variables are removed from the string,
% until 'maxvar' variables remain.
ns1=ns(1,:); ns2=ns(2,:);
if sumns1 > maxvar
nb_iter=sumns1-maxvar; % Number of variables in excess, which will be removed from ns1.
[string1]=stepson(ns(1,:),xc,yc,cvgp,nb_iter);
ns1=string1; clear string1
end
if sumns2 > maxvar
nb_iter=sumns2-maxvar; % Number of variables in excess, which will be removed from ns2.
[string2]=stepson(ns(2,:),xc,yc,cvgp,nb_iter);
ns2=string2; clear string2
end
if ns1==ns2 % the two children strings cannot be equal.
% if they are, the less informative variable is removed from one string.
[string1]=stepson(ns1,xc,yc,cvgp,1);
ns1=string1; clear string1
end
end
if ns1==zeros(1,length(ns1)), ns1=[]; end
if ns2==zeros(1,length(ns1)), ns2=[]; end
% If one of the two strings is empty, it is replaced by the empty vector.
% Now, it is checked that none of the "surviving" string(s) is (are) similar to one string already in the population.
% Otherwise, this child string is discarded.
if ns1~=[],
j=0;
while j<chrom
j=j+1;
if pop(j,:)==ns1
ns1=[];
j=chrom+1;
end
end
end
if ns2~=[],
j=0;
while j<chrom
j=j+1;
if pop(j,:)==ns2
ns2=[];
j=chrom+1;
end
end
end
ns=[ns1;ns2];
% Contains 0, 1, or 2 strings, which obey the requirements of the GA.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -