function LoopWR(nexptos,proposalt,N) 

% LOOPWR Runs the Weighted Resampling algorithm mutiple times
%
% LoopIS(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 proposal in the limit range
        limit=[10,90];
        qfun=DefineFunction('quniform',limit);
        
      case 1,               %Gaussian proposal with mu mean and sigma std
        mu    = 43.5;
        sigma = 15;
        qfun=DefineFunction('qgaussian',mu,sigma);
 end
 
 hmN=length(N);
 fmean={};
 for l=1:hmN
    N(l)               
    [samplesIS,weightsIS]=ImportanceSampling(N(l),pfun,qfun,draw); 
    for k=1: nexptos
        disp(sprintf('Experiment:%d',k));
   
         resample=weightsIS;
         [samplesRE,weightsRE]=WeightedResampling(samplesIS,weightsIS,resample,draw);
         fmean{1}(k,l)=sum(samplesRE.*weightsRE);
           
         resample=quniform(0,samplesIS,[10 90]);
         [samplesRE,weightsRE]=WeightedResampling(samplesIS,weightsIS,resample,draw);
 
         fmean{2}(k,l)=sum(samplesRE.*weightsRE);
        
         resample=qgaussian(0,samplesIS,43.5,15);
         [samplesRE,weightsRE]=WeightedResampling(samplesIS,weightsIS,resample,draw);
         fmean{3}(k,l)=sum(samplesRE.*weightsRE);
                    
    end
end

save(sprintf('LoopWR%dData',proposalt),'fmean','pfun','qfun','N');



 