function LoopIS(nexptos,proposalt,N) 

% LOOPIS Runs the Importance Sampling 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 qfun in the limit range
        limit=[10,90];
        qfun=DefineFunction('quniform',limit);
        
      case 1,               %Gaussian qfun with mu mean and sigma std
        mu    = 43.5;
        sigma = 15;
        qfun=DefineFunction('qgaussian',mu,sigma);
 end
 
 hmN=length(N);
 fmean=zeros(50,hmN);
  for l=1:hmN
    N(l)               
    for k=1: nexptos
        disp(sprintf('Experiment:%d',k));             
        [samplesIS,weightsIS]=ImportanceSampling(N(l),pfun,qfun,draw);        
        fmean(k,l)=sum(samplesIS.*weightsIS);           
    end
end

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



 