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

📄 da_pcrgo.m

📁 王小平《遗传算法——理论、应用与软件实现》随书光盘
💻 M
字号:
%
% da_pcrgo.m
%
% Gets all the parameters for the principal
% components regression subprogramme
%

%
% Separate input and output variables
%

y=data(:,include_var & output_var);
x=pcincl(data,include_var,output_var);

%
% Scale the data
%

[y my sdy]=mcen(y);
[x mx sdx]=mcen(x);

%
% Split the data correctly		
%

%
% Check radio button 4 for the percentage partition
%

if get(pcr_rad4,'Value') == 1
	[tx ty vx vy]=psplit(x,y,get(pcr_rad4sl,'Value'));
end

%
% Check radio button 5 for the random partition
%

if get(pcr_rad5,'Value') == 1
	disp('Bollocks')
	[tx ty vx vy]=rsplit(x,y,get(pcr_rad5sl,'Value'));
end

%
% Check radio button 6 for the block splitting
%

if get(pcr_rad6,'Value') == 1
	[tx ty vx vy]=bsplit(x,y,ceil(get(pcr_rad6sl,'Value')));
end

%
% Check radio button 7 for alternate split
%

if get(pcr_rad7,'Value') == 1
	[tx ty vx vy]=asplit(x,y);
end


%
% Calculate the principal components, based on the training set
%

[pc c v]=pcomp(tx);
%[D L]=size(tx);
%[s c ssq res q tst]=pca(tx,0,0,L);


%
% Only interested in the coefficients here, so discard the
% transformed data and the variances
%

clear pc v

%
% Now call the relevant regression routine
%

%
% Check radio button 1 for the include number of components
%
if get(pcr_rad1,'Value')==1
	[py impact]=pcpred(vx,c,tx,ty,ceil(get(sl2,'Value')));
	num_comp=ceil(get(sl2,'Value'));
	% pcr_er=calcer(px,vy);
end


%
% Check radio button 3 for the "include optimum number of
% components" option
%
if get(pcr_rad3,'Value') == 1
	%
	% The totel number of pricinpal components is equal
	% to the number of original variables, Dent - 1
	%
	minerr=1e100;
	num_comp=0;
	
	for i = 1: (sum(include_var)-sum(output_var))

		[py,impact]=pcpred(vx,c,tx,ty,i);
		e=sse(py,vy);
		if e < minerr
			minerr=e;
			best_impact=impact;
			num_comp=i;
			best_py=py;
		end
	end
	py=best_py;
	impact=best_impact;
	clear best_impact best_py;
end


%
% Rescale the data
%
%tx=rescale(tx,mx,sdx);
ty=rescale(ty,my,sdy);

%vx=rescale(vx,mx,sdx);
vy=rescale(vy,my,sdy);

py=rescale(py,my,sdy);

%
% Print the results in the little blue box at the top of the screen
%


[D L]=size(vy);
e=((sse(vy(:,1),py(:,1)).^0.5)/D)/my(1);
c=corrcoef(vy(:,1),py(:,1));
c=c(2,1);
regv=impact;
%impact=impact';

text1=uicontrol(w1,...
	'Style','text',...
	'Position',[275 385 130 15],...
	'BackGroundColor',[0 0 1],...
	'ForeGroundColor',[1 1 1],...
	'String',['Error =  ' num2str(e)]);
text2=uicontrol(w1,...
	'Style','text',...
	'Position',[275 365 190 15],...
	'BackGroundColor',[0 0 1],...
	'ForeGroundColor',[1 1 1],...
	'String',['Number of components =  ' num2str(num_comp)]);
text3=uicontrol(w1,...
	'Style','text',...
	'Position',[410 385 130 15],...
	'BackGroundColor',[0 0 1],...
	'ForeGroundColor',[1 1 1],...
	'String',['Correlation =  ' num2str(c)]);

%
% More detail button
%
sl1_value=1;
pca_but2=uicontrol(w1,...
	'Style','push',...
	'Position',[380 10 100 20],...
	'String','More detail',...
	'CallBack',[...
		'py=py(:,sl1_value);',...
		'vy=vy(:,sl1_value);',...
		'da_det1;']);
[D L]=size(x);
clear x y regv

%
% Save model button
%
pca_but3=uicontrol(w1,...
	'style','push',...
	'position',[500 10 100 20],...
	'string','Save model',...
	'callback',[...
		'[D L]=size(tx);',...
		'out=svlin2('''',include_var,sdx,mx,sdy,my,impact,ones(L,1),zeros(L,1))']);

if sum(output_var & include_var) > 1
	set(text4,'visible','on');
	set(text5,'visible','on');
	set(sl1,'visible','on','enable','on');
	sl1_value=1;
	old_sl1_value=1;
	set(sl1,'value',1);
	set(text4,'string','Viewing output variable 1');
end

⌨️ 快捷键说明

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