Skip to content

Commit

Permalink
Add title line and replay of trajectories
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasvillani committed Sep 18, 2023
1 parent 72a1e55 commit 138b4c6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions examples/particle-gibbs/script.jl
@@ -1,3 +1,4 @@
# # Particle Gibbs for non-linear models
using AdvancedPS
using Random
using Distributions
Expand Down Expand Up @@ -145,10 +146,13 @@ end
AdvancedPS.isdone(::NonLinearTimeSeries, step) = step > Tₘ

# We can now sample from the model using the PGAS sampler and collect the trajectories.
pg = AdvancedPS.PGAS(Nₚ)
chains = sample(model, pg, Nₛ);
particles = hcat([trajectory.model.f.X for trajectory in trajectories]...)
mean_trajectory = mean(particles; dims=2)
pgas = AdvancedPS.PGAS(Nₚ)
chains = sample(rng, model, pgas, Nₛ; progress=false);
trajectories = map(chains) do sample
replay(sample.trajectory)
end
particles = hcat([trajectory.model.f.X for trajectory in trajectories]...);
mean_trajectory = mean(particles; dims=2);

# The ancestor sampling has helped with the degeneracy problem and we now have a much more diverse set of trajectories, also at earlier time periods.
scatter(particles; label=false, opacity=0.01, color=:black, xlabel="t", ylabel="state")
Expand Down

0 comments on commit 138b4c6

Please sign in to comment.