📄 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%figure(ga_win);clgset(ga_win,'position',[20 20 600 400],'name','Optimising filters...','color',[0 0 0]);drawnow%% Draw a couple of graphs%ax1=axes(... 'Units','pixels',... 'Position',[60 200 500 160],... 'Box','on',... 'Color',[0 0 0],... 'Visible','on');text(1)=da_text(ga_win,60,370,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(ga_win,60,150,200,20,'Model error (SSE):',[1 1 1],[0 0 0]);%% Percentage done bars%box(1)=uicontrol(ga_win,... 'style','frame',... 'position',[370 20 200 30],... 'backgroundcolor',[0 0 0],... 'foregroundcolor',[1 1 1]);box(2)=uicontrol(ga_win,... 'style','frame',... 'position',[380 25 1 20],... 'foregroundcolor',[0 0 1],... 'backgroundcolor',[0 0 1]);box(3)=uicontrol(ga_win,... 'style','frame',... 'position',[370 60 200 30],... 'backgroundcolor',[0 0 0],... 'foregroundcolor',[1 1 1]);box(4)=uicontrol(ga_win,... 'style','frame',... 'position',[380 65 1 20],... 'foregroundcolor',[0 0 1],... 'backgroundcolor',[0 0 1]);text(3)=da_text(ga_win,300,63,70,20,'Decoded:',[1 1 1],[0 0 0]);text(4)=da_text(ga_win,300,28,70,20,'Complete:',[1 1 1],[0 0 0]);drawnow;%% Load the data file%eval(['cd ' num2str(df_path1)]);eval(['load ' num2str(df_name1)]);[D L]=size(df_name1);eval(['data=' num2str(df_name1(:,1:L-4)) ';']);eval(['clear ' num2str(df_name1(:,1:L-4)) ';']);eval(['cd ' num2str(working_directory)]);%% Initialise the x and y data%[meas vars]=size(data);x_data=ones(1,vars);x_data(out_col)=0;x=data(:,x_data);y=data(:,out_col);clear data;%% 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%% Initialise the genetic description%d=[];for i=1:vars-1 d=[d ; 0 0.01 1];end%% Generate the population - with 20 members%[o d b]=decode(0,d,0);bits=sum(b);members=20;%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]=select4(chrom,d,x,y,box(2),box(4)); set(box(2),'position',[380 25 1 20]); set(box(4),'position',[380 65 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); c=pinv(x2'*x2)*x2'*y; yest=x2*c; [c2,in]=max(pin); axes(ax1); if scale_data==1 plot([resclg(y,miny,maxy) resclg(yest,miny,maxy)]); else plot([y yest]); end xlabel('Sample number'); ylabel('Actual & Predicted'); axes(ax2); plot(results(:,1)); xlabel('Generation number'); ylabel('Error'); drawnow;endif save_data==1 if scale_data==0 sd=[y x]; else sd=[resclg(y,miny,maxy) resclg(x,minx,maxx)]; end eval(['save ' num2str(save_data_name) ' sd -ascii']);end%% Display the filter constants and coefficients%disp('Filter Constants:');fdisp('Regression Coefficients:');disp(c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -