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

📄 ver_ga.m

📁 遗传算法的matlab程序集(内有很多问题的具体解决程序)
💻 M
字号:
% Script file for checkinmg the verification RMS and correlation coefficient
% for multiple GA solutions generated by auto_ga
%

clear all
one_off=0;
%-----------------------------------------------------


load test.dat
npts=100;
[Q num_inp]=size(test);
num_inp=num_inp-1;
%  training data

u=test(1:npts,1:5);
y=test(1:npts,6);

%  verification dat

u_v=test(101:200,1:5);
y_v=test(101:200,6);

load_path='I:\matlab\bin\gp1\';
load_tag=[num2str(npts) '#'];
pop_size=25;
num_gen=100;
run_num=50;
Q=npts;
Q_v=100;
RMS_tol=0.20;
%num_inp=5;
% 
% least squares on linear model - to determine correlation threshold
%

   dato_L=[u ones( Q,1)];
   theta_L=inv(dato_L'*dato_L)*dato_L'*y;
   y_p_L = dato_L*theta_L;
   A=corrcoef([y_p_L y]);
   CC_L=abs(A(1,2));
   SSE=sum((y_p_L-y).^2);
   RMS_L=sqrt(SSE/Q);
   
  %RMS_tol = RMS_L
  
  % figure(1);
  % hold off
  % plot(y)
  % hold on
  % plot(y_p_L, 'g')
  % pause
%
% Initialise Inputs
%
for i=1:num_inp,
         eval(['u' num2str(i) '= u(:,' num2str(i) ');']);
end
%
% Training data
%

for K=1:run_num,
   disp(K)
   if one_off==0,
      Zz=[load_path load_tag num2str(K)];
      eval(['load ' Zz ])
   else    %one_off==1
      Zz=[load_path load_tag ];
      eval(['load ' Zz ])
   end 
  
   
   [save_pop_num,L]=size(save_pop);

   temp_pop=save_pop(save_pop_num,:);
   temp_fit=save_fit(save_pop_num);
   theta=save_theta(save_pop_num,:);
      
   out=['y_p = ' temp_pop ';'];

   temp_out = strrep(out,'*','.*');
   temp_out = strrep(temp_out,'/','./');
   out    = strrep(temp_out,'^','.^');

   
   eval(out);
   
   % Least squares to calculate theta values
   
   dato=[y_p ones( Q,1)];
   theta=inv(dato'*dato)*dato'*y;
   y_p = y_p*theta(1) + theta(2);
   %figure(1)
   %hold off
   %plot(y_p,'r')
   %hold on
   %plot(y)
   %pause
  
   A=corrcoef([y_p y]);
   CC(K,1)=abs(A(1,2));
   E=(y_p - y);
   SSE=sum(E.^2);
   RMS(K,1)=sqrt(SSE/Q);
   SDR(K,1)=abs(std(E));   
   res(1:Q,K)=E;
   Y_P(1:Q,K)=y_p;
   
   %figure(1);
   %clf
   %hold off
   %plot(y_p,'g')
   %hold on
   %plot(y,'r')
   %eval(['title('' ' num2str(RMS(K)) ' '')'])
   %subplot(212)
   %plot(y_p-y)
   %pause
      
   %simp_pop=simplo(temp_pop,theta'); 
   simp_pop=temp_pop;
   
   if K==1,
      win_pop=temp_pop;
      win_fit=temp_fit;
      win_theta=theta';
      win_simp_pop=simp_pop;
      win_e=E;
   else
      win_pop=str2mat(win_pop,temp_pop);
      win_fit=[win_fit;temp_fit];
      win_theta=[win_theta;theta'];
      win_simp=str2mat(win_simp,simp_pop);
      win_e=[win_e,E];
   end
end


%
% verification data
% 

%
% Initialise Inputs
%
for i=1:num_inp,
         eval(['u' num2str(i) '= u_v(:,' num2str(i) ');']);
end

for K=1:run_num,
  disp(K)
   out=['y_p_v = ' win_pop(K,:) ';'];
       
   temp_out = strrep(out,'*','.*');
   temp_out = strrep(temp_out,'/','./');
   out    = strrep(temp_out,'^','.^');
   
   eval(out);
   y_p_v = win_theta(K,1)*y_p_v + win_theta(K,2);
    
   A=corrcoef([y_p_v y_v]);
   CC_v(K,1)=abs(A(1,2));
   E_v=(y_p_v - y_v);
   SSE_v(K,1)=sum(E_v.^2);
   RMS_v(K,1)=sqrt(SSE_v(K,1)/Q_v);
   SDR_v(K,1)=abs(std(E_v));
   res_v(1:Q_v,K)=E_v;
   Y_P_v(1:Q_v,K)=y_p_v;
    
   %figure(1)
   %hold off
   %plot(y_p_v,'r')
   %hold on
   %plot(y_v,'g')
   %pause
end
   
%
% Find models that are better than RMS_tol on the verification set
%
I_tol=find(RMS_v<RMS_tol);
x=length(I_tol)
suc_pop=win_pop(I_tol,:);
suc_RMS=RMS(I_tol);
suc_RMS_v=RMS_v(I_tol);

prob_suc=x/length(RMS);

[x,I]=sort(RMS);
disp([CC RMS SDR CC_v RMS_v SDR_v])
%disp([CC(I(1:20)) RMS(I(1:20)) SDR(I(1:20)) CC_v(I(1:20)) RMS_v(I(1:20)) SDR_v(I(1:20))])
%disp(win_pop(I(1:20),:)) 
%disp(win_simp(I(1:20),:))

⌨️ 快捷键说明

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