📄 garun.m
字号:
%
% garun.m
%
% Runs the GA filter optimising program
%
%
% Clear the stuff out from the old screen
% clear slider text but line check
%
% Initialise the ga_win screen
% da_front
drawnow
%
% Draw a couple of graphs
%
ax1=axes(...
'Units','pixels',...
'Position',[60 200 500 200],...
'Box','on',...
'Color',[0 0 0],...
'Visible','on');
text(1)=da_text(w1,60,400,200,20,'Linear prediction of output:',[1 1 1],[0 0 0]);
ax2=axes(...
'Units','pixels',...
'Position',[60 40 230 100],...
'Box','on',...
'Color',[0 0 0],...
'Visible','on');
text(2)=da_text(w1,60,150,200,20,'Model error (SSE):',[1 1 1],[0 0 0]);
%
% Percentage done bars
%
box(1)=uicontrol(w1,...
'style','frame',...
'position',[370 40 200 30],...
'backgroundcolor',[0 0 0],...
'foregroundcolor',[1 1 1]);
box(2)=uicontrol(w1,...
'style','frame',...
'position',[380 45 1 20],...
'foregroundcolor',[0 0 1],...
'backgroundcolor',[0 0 1]);
box(3)=uicontrol(w1,...
'style','frame',...
'position',[370 80 200 30],...
'backgroundcolor',[0 0 0],...
'foregroundcolor',[1 1 1]);
box(4)=uicontrol(w1,...
'style','frame',...
'position',[380 85 1 20],...
'foregroundcolor',[0 0 1],...
'backgroundcolor',[0 0 1]);
text(3)=da_text(w1,300,83,70,20,'Decoded:',[1 1 1],[0 0 0]);
text(4)=da_text(w1,300,48,70,20,'Complete:',[1 1 1],[0 0 0]);
drawnow;
%
% Initialise the x and y data
%
if sum(output_var) > 1
[D L]=size(output_var);
for i = 1 : L
if output_var(i) == 1
y=data(:,i);
break;
end
end
else
y=data(:,output_var);
end
x=pcincl(data,include_var,output_var);
%
% Scale the data from 0-->1 if this has been selected
% if scale_data==1;
[x minx maxx]=mceng2(x);
[y miny maxy]=mceng2(y);
end
%
% Split the data
%
[x y vx vy]=psplit(x,y,tr_split);
%
% Initialise the genetic description
%
d=[];
[D vars]=size(x);
for i=1:vars
d=[d ; fil_min fil_res fil_max];
end
%
% Generate the population - with 20 members
%
[o d b]=decode(0,d,0);
bits=sum(b);
%chrom=newpop(members,bits);
chrom=zeros(members,bits);
results=[];
%
% Main generation loop
%
for i=1:max_gen
%
% Cross and mutate
%
for j = 1 : 2 :members
chrom(j,:)=mutate(chrom(j,:),0.02);
chrom(j+1,:)=mutate(chrom(j+1,:),0.02);
[chrom(j,:) chrom(j+1,:)]=crover(chrom(j,:),chrom(j+1,:),0.02);
end
%
% Select the best
%
[chrom coefs pin]=select7(chrom,d,x,y,box(2),box(4));
set(box(2),'position',[380 45 1 20]);
set(box(4),'position',[380 85 1 20]);
%
% Decode this popultaion and plot results
%
results(i,:)=[min(pin) mean(pin) max(pin)];
[D L]=size(coefs);
[D1 L1]=size(x);
[c,in]=min(pin);
f=coefs(in,:);
x2=fil(x,f);
x2=[ones(D1,1) x2];
c=pinv(x2'*x2)*x2'*y;
yest=x2*c;
[c2,in]=max(pin);
%
% Work out the validation results
%
vx2=fil(vx,f);
[D1 L1]=size(vx2);
vx2=[ones(D1,1) vx2];
yest_v=vx2*c;
axes(ax1);
if scale_data==1
plot([[resclg(y,miny,maxy) ; resclg(vy,miny,maxy)] [resclg(yest,miny,maxy) ;
resclg(yest_v,miny,maxy)]]);
else
plot([[y ; vy] [yest ; yest_v]]);
end
xlabel('Sample number');
ylabel('Actual & Predicted');
axes(ax2);
plot(results(:,1));
xlabel('Generation number');
ylabel('Error');
drawnow;
end
if save_data==1
if scale_data==0
sd=[[y ; vy] [x2 ; vx2]];
else
sd=[[resclg(y,miny,maxy) ; resclg(vy,miny,maxy)]
[resclg(x2(:,2:vars+1),minx,maxx) ; resclg(vx2(:,2:vars+1),minx,maxx)]];
end
eval(['save ' num2str(save_data_name) ' sd -ascii']);
end
%
% Display the filter constants and coefficients
%
disp('Filter Constants:');
f'
disp('Regression Coefficients:');
disp(c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -