#### #Example Particle Gibbs # # Example Video of Conditional SMC sampler for Particle Gibbs. # In this example, the red line is the conditioned path # Weights are always 1 for each path at each time-point (no-observation) # Dynamics are X_t=X_{t-1}+N(0,0.15^2) # X_1~N(1,0.3^2) # delay=1 N=10 T=10 Xcond=1+rnorm(T,0,0.2) plot(1:T,Xcond,xlab="Time",ylab="X_t",ylim=c(0,2),type="l",col=2,lwd=2) Xsam=c(Xcond[1],rnorm(N-1,1,0.3)) Path=matrix(0,nrow=N,ncol=T) Path[,1]=Xsam plot(c(1,T),c(0,2),xlab="Time",ylab="X_t",type="n") for(i in N:1){ points(1,Path[i,1],col=1+(i==1),cex=1,lwd=2+(i==1)) } Sys.sleep(delay) for(t in 2:T){ ##Prop Path[1,t]=Xcond[t] lines(c(t-1,t),Path[1,c(t-1,t)],lwd=3,col=2) index=sample(1:N,size=N-1,rep=T) points(t,Path[1,t],lwd=3,col=2) Sys.sleep(delay) ##Prop #lines(c(t-1,t),Path[1,c(t-1,t)],lwd=2,col=2) Path=Path[c(1,index),] for(i in 2:N){ Path[i,t]=rnorm(1,Path[i,t-1],0.15) lines(c(t-1,t),Path[i,c(t-1,t)],lwd=2,col=1+(i==1)) points(t,Path[i,t],lwd=2,col=1) } Sys.sleep(delay) } Sys.sleep(5*delay) for(j in 1:(t-1)){ for(i in N:1){ lines(c(j,j+1),Path[i,j+0:1],lwd=4,col=1+(i==1)) } }