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

📄 da_pcspe.m

📁 王小平《遗传算法——理论、应用与软件实现》随书光盘
💻 M
字号:
%
% da_pcspe.m
%
% Routine to produce an SPE plot.
%


%
% Draw some axes
%
da_front;
da_pcapb;
drawnow;

%
% Say it's calculating data
%
text1=uicontrol(w1,...
	'Style','text',...
	'Position',[230 300 150 15],...
	'String','Working. Please wait....',...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1]);


%
% Calculate the SPE and put it into b
%
x=pcincl(mcen(data),include_var,output_var);
[tx ty vx vy]=psplit(x,x,50);
clear x ty vy
b=spe(tx,vx,ceil((sum(include_var)-sum(output_var))/2));

%
% Check to see if this is the same size as the
% original data. If it's not, it's a rounding
% error so adjust it's size.
%
[D L]=size(b);
[D1 L1]=size(pcs);
pc=pcs;
b2=b;
if D ~= D1
	if D < D1
		pcs=pcs(1:D,:);
	else
		b=b(1:D1,:);
	end
end
[crap crap ps b2]=psplit(pcs,b,50);
figure(w1);
ax1=axes(...
	'Units','pixels',...
	'Position',[60 230 500 170],...
	'Box','on',...
	'Color',[0 0 0]);
delete(text1);
plot3(ps(:,2),ps(:,1),b2,'+');
clear crap ps b2;
set(ax1,'Xgrid','on');
set(ax1,'Zgrid','off');
set(ax1,'Ygrid','on');
view(20,20);
Xlabel('X-axis');
Ylabel('Y-axis');
Zlabel('Squared prediction error');

%
% Title for the graph
%
text1=da_text(w1,170,410,300,15,'Squared prediction error plot',[1 1 1],[1 0 0]);

old_sl4_value=0;
old_sl3_value=0;
sl3_value=1;
sl4_value=2;
%
% Draw slider for rotation
%
sl1=uicontrol(w1,...
	'Style','slider',...
	'Position',[450 130 100 20],...
	'Max',180,...
	'Min',0,...
	'Value',20,...
	'CallBack',[
		'set(sl1_current,''String'',ceil(get(sl1,''Value'')));',...
		'Zlabel(''Squared prediction error'');',...
		'Xlabel(''X-axis'');',...
		'Ylabel(''Y-axis'');',...
		'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));']);

sl1_current=uicontrol(w1,...
	'Style','text',...
	'Position',[520 150 20 15],...
	'String',num2str(ceil(get(sl1,'Value'))),...
	'ForeGroundColor',[1 1 1],...
	'BackGroundColor',[0 0 0]);

sl1_min=uicontrol(w1,...
	'Style','text',...
	'Position',[430 130 15 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','0');

sl1_max=uicontrol(w1,...
	'Style','text',...
	'Position',[560 130 20 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','180');

sl1_title=uicontrol(w1,...
	'Style','text',...
	'Position',[450 150 70 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','Rotation');

%
% Draw slider for elevation
%
sl2=uicontrol(w1,...
	'Style','slider',...
	'Position',[450 90 100 20],...
	'Max',180,...
	'Min',0,...
	'Value',20,...
	'CallBack',[
		'set(sl2_current,''String'',ceil(get(sl2,''Value'')));',...
		'Zlabel(''Squared prediction error'');',...
		'Xlabel(''X-axis'');',...
		'Ylabel(''Y-axis'');',...
		'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));']);

sl2_current=uicontrol(w1,...
	'Style','text',...
	'Position',[520 110 20 15],...
	'String',num2str(ceil(get(sl2,'Value'))),...
	'ForeGroundColor',[1 1 1],...
	'BackGroundColor',[0 0 0]);

sl2_min=uicontrol(w1,...
	'Style','text',...
	'Position',[430 90 15 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','0');

sl2_max=uicontrol(w1,...
	'Style','text',...
	'Position',[560 90 20 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','180');

sl2_title=uicontrol(w1,...
	'Style','text',...
	'Position',[450 110 70 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','Elevation');

%
% Slider for data splitting
%
sl5=uicontrol(w1,...
	'style','slider',...
	'position',[450,50,100,20],...
	'min',5,...
	'max',95,...
	'value',50,...
	'callback',[
		'set(sl5_current,''string'',num2str(ceil(get(sl5,''value''))));',...
		'x=pcincl(mcen(data),include_var,output_var);',...
		'[tx ty vx vy]=psplit(x,x,ceil(get(sl5,''value'')));',...
		'clear x ;',...
		'b=spe(tx,vx,ceil(get(sl6,''value'')));',...
		'[D L]=size(b);',...
		'[D1 L1]=size(pcs);',...
		'ps=pcs;',...
		'b2=b;',...
		'if D ~= D1;',...
			'if D < D1;',...
				'ps=pcs(1:D,:);',...
			'else;',...
				'b2=b(1:D1,:);',...
			'end;',...
		'end;',...
		'[crap crap ps b2]=psplit(pcs,b2,ceil(get(sl5,''value'')));',...
		'plot3(ps(:,ceil(get(sl4,''Value''))),ps(:,sl3_value),b2,''+'');',...
		'clear crap ps b2;',...
		'old_sl3_value=sl3_value;',...
		'set(ax1,''Xgrid'',''on'');',...
		'set(ax1,''Zgrid'',''off'');',...
		'set(ax1,''Ygrid'',''on'');',...
		'Zlabel(''Squared prediction error'');',...
		'Xlabel(''X-axis'');',...
		'Ylabel(''Y-axis'');',...
		'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));']);


sl5_current=da_text(w1,520,70,20,15,'50',[1 1 1],[0 0 0]);
sl5_min=da_text(w1,430,50,15,15,'0',[1 1 1],[0 0 0]);
sl5_max=da_text(w1,560,50,20,15,'100',[1 1 1],[0 0 0]);
sl5_title=da_text(w1,450,70,70,15,'%age split',[1 1 1],[0 0 0]);

%
% Slider to determine the number of PCs to use in calculating
% the SPE
%
[D L]=size(pcs);
sl6=uicontrol(w1,...
	'style','slider',...
	'position',[260 50 100 20],...
	'min',1,...
	'max',L,...
	'value',ceil((sum(include_var)-sum(output_var))/2),...
	'callback',[
		'set(sl6_current,''string'',num2str(ceil(get(sl6,''value''))));',...
		'x=pcincl(mcen(data),include_var,output_var);',...
		'[tx ty vx vy]=psplit(x,x,ceil(get(sl5,''value'')));',...
		'clear x ;',...
		'b=spe(tx,vx,ceil(get(sl6,''value'')));',...
		'[D L]=size(b);',...
		'[D1 L1]=size(pcs);',...
		'ps=pcs;',...
		'b2=b;',...
		'if D ~= D1;',...
			'if D < D1;',...
				'ps=pcs(1:D,:);',...
			'else;',...
				'b2=b(1:D1,:);',...
			'end;',...
		'end;',...
		'[crap crap ps b2]=psplit(pcs,b2,ceil(get(sl5,''value'')));',...
		'plot3(ps(:,ceil(get(sl4,''Value''))),ps(:,sl3_value),b2,''+'');',...
		'clear crap ps b2;',...
		'old_sl3_value=sl3_value;',...
		'set(ax1,''Xgrid'',''on'');',...
		'set(ax1,''Zgrid'',''off'');',...
		'set(ax1,''Ygrid'',''on'');',...
		'Zlabel(''Squared prediction error'');',...
		'Xlabel(''X-axis'');',...
		'Ylabel(''Y-axis'');',...
		'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));']);

sl6_min=da_text(w1,240,50,15,15,'1',[1 1 1],[0 0 0]);
sl6_max=da_text(w1,375,50,20,15,num2str(L),[1 1 1],[0 0 0]);
sl6_title=da_text(w1,260,70,80,15,'Num pcs:',[1 1 1],[0 0 0]);
sl6_current=da_text(w1,345,70,20,15,num2str(ceil(get(sl6,'value'))),[1 1 1],[0 0 0]);






%
% Slider to determine which pc to plot on the x-axis
%
sl3=uicontrol(w1,...
	'Style','slider',...
	'Position',[50 80 120 20],...
	'Max',num_pcs,...
	'Min',1,...
	'Value',1,...
	'CallBack',[
		'set(sl3_current,''String'',num2str(ceil(get(sl3,''Value''))));',...
		'sl3_value=ceil(get(sl3,''Value''));',...
		'if sl3_value ~= old_sl3_value;',...
			'plot3(pcs(:,ceil(get(sl4,''Value''))),pcs(:,sl3_value),b,''+'');',...
			'old_sl3_value=sl3_value;',...
			'set(ax1,''Xgrid'',''on'');',...
			'set(ax1,''Zgrid'',''off'');',...
			'set(ax1,''Ygrid'',''on'');',...
			'Zlabel(''Squared prediction error'');',...
			'Xlabel(''X-axis'');',...
			'Ylabel(''Y-axis'');',...
			'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));',...
		'end']);

sl3_current=uicontrol(w1,...
	'Style','text',...
	'Position',[160 100 20 15],...
	'String',num2str(ceil(get(sl3,'Value'))),...
	'ForeGroundColor',[1 1 1],...
	'BackGroundColor',[0 0 0]);

sl3_min=uicontrol(w1,...
	'Style','text',...
	'Position',[30 80 15 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','0');

sl3_max=uicontrol(w1,...
	'Style','text',...
	'Position',[180 80 20 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(num_pcs));

sl3_title=uicontrol(w1,...
	'Style','text',...
	'Position',[20 100 145 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','pc plotted on x-axis:');


%
% Slider to determine which principal component to plot on the
% y-axis
%
sl4=uicontrol(w1,...
	'Style','slider',...
	'Position',[50 130 120 20],...
	'Max',num_pcs,...
	'Min',1,...
	'Value',2,...
	'CallBack',[
		'set(sl4_current,''String'',num2str(ceil(get(sl4,''Value''))));',...
		'sl4_value=ceil(get(sl4,''Value''));',...
		'if sl4_value ~= old_sl4_value;',...
			'plot3(pcs(:,sl4_value),pcs(:,ceil(get(sl3,''Value''))),b,''+'');',...
			'old_sl4_value=sl4_value;',...
			'set(ax1,''Xgrid'',''on'');',...
			'set(ax1,''Zgrid'',''off'');',...
			'set(ax1,''Ygrid'',''on'');',...
			'Zlabel(''Squared prediction error'');',...
			'Xlabel(''X-axis'');',...
			'Ylabel(''Y-axis'');',...
			'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));',...
		'end']);

sl4_current=uicontrol(w1,...
	'Style','text',...
	'Position',[160 150 20 15],...
	'String',num2str(ceil(get(sl4,'Value'))),...
	'ForeGroundColor',[1 1 1],...
	'BackGroundColor',[0 0 0]);

sl4_min=uicontrol(w1,...
	'Style','text',...
	'Position',[30 80 15 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','0');

sl4_max=uicontrol(w1,...
	'Style','text',...
	'Position',[180 130 20 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String',num2str(num_pcs));

sl4_title=uicontrol(w1,...
	'Style','text',...
	'Position',[20 150 145 15],...
	'BackGroundColor',[0 0 0],...
	'ForeGroundColor',[1 1 1],...
	'String','pc plotted on y-axis:');

%
% Draw "snake" button
%
but2=uicontrol(w1,...
	'style','push',...
	'position',[500 10 100 20],...
	'string','Snake',...
	'callback',[...
		'[D L]=size(b);',...
		'[D1 L1]=size(pcs);',...
		'ps=pcs;',...
		'b2=b;',...
		'if D ~= D1;',...
			'if D < D1;',...
				'ps=pcs(1:D,:);',...
			'else;',...
				'b2=b(1:D1,:);',...
			'end;',...
		'end;',...
		'[crap crap ps b2]=psplit(pcs,b2,ceil(get(sl5,''value'')));',...
		'comet3a(ps(:,ceil(get(sl4,''value''))),ps(:,ceil(get(sl3,''value''))),b2);',...
		'cla;',...
		'plot3(ps(:,ceil(get(sl4,''value''))),ps(:,ceil(get(sl3,''Value''))),b2,''+'');',...
		'clear crap ps b2;',...
		'set(ax1,''Xgrid'',''on'');',...
		'set(ax1,''Zgrid'',''off'');',...
		'set(ax1,''Ygrid'',''on'');',...
		'view(ceil(get(sl1,''Value'')),ceil(get(sl2,''Value'')));',...
		'Xlabel(''X-axis'');',...
		'Ylabel(''Y-axis'');',...
		'Zlabel(''Squared prediction error'');']);

⌨️ 快捷键说明

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