⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gainit.m

📁 多元线性回归:MATLAB源程序多元线性回归
💻 M
字号:
%#									
%#  function [pop,rep]=gainit(xc,yc,chrom,maxvar,psel,cvgp)		
%#									
%#  AIM:	Random initiation and evaluation of the population.	
%#									
%#  PRINCIPLE:  After a string was randomly created, one checks:	
%#		C1) Whether no string yielding a better result is one	
%#		of his subsets (otherwise, the created string is killed	
%#		and does not enter population).				
%#		C2) After it is entered, whether it is not the subset	
%#		of a string yielding a worse result (otherwise, this	
%#		string is killed).					
%#									
%#  INPUT:								
%#	xc, yc	: (row x col) Calibration set, on which the GA is run	
%#	chrom	: Number of strings in the population			
%#	maxvar	: Maximum number of variables for selection		
%#	psel	: Probability of selection in the initiation		
%#	      	  (psel=maxvar/col)					
%#	cvgp	: Number of deletion groups for cross-validation	
%#									
%#  OUTPUT:								
%#	pop	: (chrom x col) Subsets of variables selected in each	
%#		  string (on the rows) in the initial population.	
%#		  A binary coding is used:				
%#		    0: the corresponding variable is not selected	
%#		    1: the corresponding variable is selected		
%#		  To obtain directly the subset number i:		
%#		    subset_i=find(pop(i,:)==1)				
%#	rep	: (chrom x 1) Vector containing the cross-validated	
%#		  response of the corresponding strings in the		
%#		  population.						
%#									
%#  SUBROUTINES:							
%#	mlrcv.m    : MLR model with cross-validation to compute the	
%#	             the prediction error.				
%#									
%#  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]=gainit(xc,yc,chrom,maxvar,psel,cvgp)

pop=[];
rep=[];
[row,col]=size(xc);
i=1;
while i<=chrom			% random generation of strings continues until chrom strings are created
   c=(rand(1,col)<=psel);	% c: new created string

   if sum(c)>0 & sum(c)<=maxvar 
   % the string should not contain more than 'maxvar' variables
	if i==1 % first created string
	   xx=xc(:,c);
	   [rr]=mlrcv(xx,yc,1,cvgp);	% evaluation of string c
	   rr=1/rr;
	   pop(i,:)=c;			% c is placed in the population
	   rep(i,1)=rr;			% its response is placed in rep
	end %i==1

	if i>1 % at least one string already in the population

	   %Check that the new string is not similar to existing one
	   b=0;
	   for j=1:i-1
		if pop(j,:)==c,b=1;end;
	   end
	   if b==0 % the new string is different from all members already in the population
		   % It is then evaluated
		xx=xc(:,c);
		[rr]=mlrcv(xx,yc,1,cvgp); % evaluation of the new string c
		rr=1/rr;
 		a=find(rep(1:i-1,:)>=rr);
		% vector containing the indexes of the strings from the population with a better response than c.

		% Check C1 (cf. PRINCIPLE)
		d=0;
		for k=1:length(a)
		   dc=c-pop(a(k),:);
		   if find(dc<0)==[] % pop(a(k),:) is a subset of c
			d=1;
		   end;
		end
		clear a dc

		% Check C2 (if condition C1 fulfilled)
		if d==0
		   pop(i,:)=c; rep(i,1)=rr; clear rr
		   % the string c is the ith string to enter
		   % the population

		   a=find(rep(1:i-1,1)<=rep(i,1));
		   % vector containing the indexes of the strings from the population with a worse response.

		   e=[];
		   for k=1:length(a)
			dc=pop(a(k),:)-pop(i,:);
			if find(dc<0)==[] % the new string, in pop(i,:) is a subset of the string pop(a(k),:)
			   e=[e;a(k)]
			   % vector containing the indexes of the strings yielding a worse response than pop(i,:),
			   % of which pop(i,:) is a subset. The additional variables of these strings are not
			   % informative: the strings are removed from the population.
			end
		   end
		   pop(e,:)=[];rep(e,:)=[];
		end %d==0
	   end %if b=0
	end %if i>1
   end %if sum(c)>

   % Now, possibly, a new string has entered the population
   % (ic C1 was fulfilled), and maybe other strings, which were
   % in the population have been removed. Therefore, one must
   % create new strings until the size of the population is equal to
   % 'chrom'.
 
   i=size(pop,1)+1;
end % while i<=
clear row col chrom psel i c b j z a d e k

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -