function s=ChainIndependenceSampler(sold,pfun,qfun)
   
%ChainIndependenceSampler   Step of the independence sample
%
% s=ChainIndependenceSampler(sold,pfun,qfun)
%
% sold: sample at t-1
% pfun: p function (see define fun)
% qfun: q function used to sample (see define fun)
% s: new sample

% 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


s=qfun.fun(1,1,qfun.param{:}); %sample
qs=qfun.fun(0,s,qfun.param{:});
qsold=qfun.fun(0,sold,qfun.param{:});  

w1 = pfun.fun(0,s,pfun.param{:})./qs;
w2 = pfun.fun(0,sold,pfun.param{:})./qsold;
if rand(1) > min(1,w1/w2),      
    s=sold;
end