📄 checksub.m
字号:
%#
%# function [pop,rep]=checksub(newson,evson,pop,rep,chrom);
%#
%# AIM: Checks whether children strings can enter the
%# population, and replace a string yielding a worse
%# response.
%#
%# PRINCIPLE: A child string can enter the population provided that
%# none of its subsets already present in the population
%# yields a better response (otherwise, the additional
%# variables in the children string carry no relevant
%# information for the model).
%# A child string entering the population replaces the
%# worse non protected string.
%# Once a child is in the population, it must be checked
%# that it is not a subset of strings already in the
%# population, and yielding worse responses (as the
%# additional variables contained in this string bring no
%# relevant information to the model). Such worse subsets
%# are replaced by null vectors (in order to keep the
%# population size constant).
%#
%# INPUT:
%# newson : new child string to check
%# evson : its associated response
%# pop : the actual population, in which 'newson' might enter
%# rep : the responses of the strings in the population
%# chrom: : the population size
%#
%# OUTPUT:
%# pop : the population, after some new children strings
%# have entered it, and replaced worse strings.
%# rep : the response of the strings in the new population.
%#
%# 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 [pop,rep]=checksub(newson,evson,pop,rep,chrom);
[row,col]=size(pop);
[rep,index]=sort(rep); % the responses are arranged in increasing order.
pop=pop(index,:); % the strings are sorted in increasing value of response
clear index
rep=flipud(rep); % the strings are arranged in decreasing order of response.
pop=flipud(pop); % the strings are sorted in decreasing value of response.
n=max(find(rep>=evson));% strings from the population with a better response than the child string.
if n==[], n=0; end;
if n~=row % The position of newson in the sorted population would be n+1
b=0;
for k=1:n
dc=newson-pop(k,:);
if find(dc<0)==[],b=1;end;
end
% If b==1, at least one chrom. between 1 and n is a subset of newson, so newson is killed
if b==1,newson=[];evson=[];end;
clear dc
if b==0, % newson can enter the population. One must check that it is not subset of chrom. between
% n+1 and chrom
e=[];
for k=n+1:chrom
dc=pop(k,:)-newson;
if find(dc<0)==[],e=[e;k];end
end
% k is the index of string of which newson is the subset.
% This string being worse than newson, it is killed, and replaced by the null vector.
clear dc
if length(e)>=1,
pop(e,:)=[];rep(e)=[];
pop=[pop;newson;zeros(length(e)-1,col)];
rep=[rep;evson;zeros(length(e)-1,1)];
end %if length(e)>=1
protect=[];
if length(e)==0,
% newson is not subset of any string with a worse response.
% It enters in the population, and replaces the worse non-protected string.
% A string including n variables is protected when it gives the best response
% among all the strings including AT MOST n variables.
pop=[pop(1:n,:);newson;pop(n+1:chrom,:)];
rep=[rep(1:n);evson;rep(n+1:chrom)];
protect(1,1)=1; % the best string is protected.
nb_var=sum(pop(1,:));
for j=2:chrom+1
if rep(j)<rep(j-1)
if sum(pop(j,:))<nb_var & sum(pop(j,:))>=1
protect(j,1)=1; % string j is protected
nb_var=sum(pop(j,:));
else
protect(j,1)=0; % string j is NOT protected
end
end
if rep(j)==rep(j-1)
if sum(pop(j,:))<nb_var & sum(pop(j,:))>=1
protect(j,1)=1; % string j is protected
protect(j-1,1)=0; % string j-1 is NOT protected
nb_var=sum(pop(j,:));
else
protect(j,1)=0; % string j is NOT protected
end
end
end % for j=2:chrom+1
f=find(protect==0); % non-protected strings
if f~=[]
lf=length(f);
pop(f(lf),:)=[]; % the worse non-protected string is eliminated
rep(f(lf),:)=[];
else %if f==[], % if no strings are protected
pop(chrom+1,:)=[]; % the worse string is eliminated
rep(chrom+1)=[];
end
end %if length(e)==0
end %if b==0
end % if n~=row
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -