Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs in the docs for the nonlinear example #80

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions examples/particle-gibbs/script.jl
Original file line number Diff line number Diff line change
@@ -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]...);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been (without using the suggestion tool, since I messed up everything last time):

particles = hcat([trajectory.model.f.X for trajectory in chains]...); # pulling it from the chains directly

and you should be able to remove the replay part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would need to read up on the replay idea here, but replacing

trajectories = map(chains) do sample replay(sample.trajectory) end particles = hcat([trajectory.model.f.X for trajectory in trajectories]...);

with

particles = hcat([trajectory.model.f.X for trajectory in chains]...); # pulling it from the chains directly

gives me the error:

ERROR: type PGSample has no field model

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes this issue

particles = hcat([chain.trajectory.model.X for chain in pgas_chains]...)

but seems to hit another one with the way we copy models around. I'll open an issue and look into it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can keep the (possibly redundant) replay part for now and merge my PR? That would be better than the severely broken version merged at the moment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, since the fix pretty much requires #75 to be merged first

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