%%  un reseau RBF%%
 clear all;clc;load solar_data;
 YT=[YTR;YVL;YTST];
 YTM=mean(YT);
 D=mean((YT-YTM).^2)% to compute the NMSE 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nmin=1;nmax=5;v=70;
 for h=nmin:nmax;
          net=newrb(TR',YTR',0,v,h,h); %parametres estimation
          U=sim(net,VL');                  %validation 
          ERROR(h)=mean(((U)'-(YVL)).^2)/D;
 end
 
[ERR_Corresp,num_opt_hidd]=min(ERROR); % optimal number of noeuds
num_opt_hidd =num_opt_hidd+nmin-1;
% Test of network with TEST set
figure(3)
% X=nmin:nmax;
plot (ERROR)

net=newrb(TR',YTR',0,v,num_opt_hidd,num_opt_hidd); 
netTST=sim(net,TST');
NMSE_RBF=mean(((netTST)'-(YTST)).^2)/D
num_opt_hidd=num_opt_hidd

figure(4);plot(netTST,'b');hold on;plot(YTST,'r');
legend ('valeur prdite', 'valeur mesure')
return
 