function LoopRS(nexptos,proposalt,N) 


% LOOPRS Runs the Rejection Sampling algorithm mutiple times
%
% LoopRS(nexptos,proposalt,N)
% nexptos: number of times
% proposalt=0: uniform proposal, proposalt=1 gaussian proposal
% N: array with number of samples

% APRENDIZAJE AUTOMÁTICO (G. Pajares y J. M. de la Cruz, Eds.)
% Editorial: RA-MA
% Capítulo 7 y 8: Monte Carlo I y II
% Autores: Eva Besada-Portas, Sergey M. Plis


%--------------------------------PARAMETROS------------------------------
 draw=0;                   % Draw results inside each method
 
 pfun=DefineFunction('pC'); %pfun funtion 
  
 switch(proposalt)
      case 0,               %Uniform qfun in the limit range
        limit=[10,90];
        qfun=DefineFunction('quniform',limit);
        M=7.5;              %M for rejection sampling
        
      case 1,               %Gaussian qfun with mu mean and sigma std
        mu    = 43.5;
        sigma = 15;
        qfun=DefineFunction('qgaussian',mu,sigma);
        M = 3.53;           %M for rejection sampling
 end
  
  
 hmN=length(N);
 fmean=zeros(50,hmN);hmRej=zeros(50,hmN);
 for l=1:hmN
    N(l)               
    for k=1: nexptos
        disp(sprintf('Experiment:%d',k));            
        [samplesRS,rejected]=RejectionSampling(N(l),pfun,qfun,M,draw);        
        fmean(k,l)=mean(samplesRS);
        hmRej(k,l)=length(rejected);
    end
end

save(sprintf('LoopRS%dData',proposalt),'fmean','hmRej','pfun','qfun','N','M');


