-
Notifications
You must be signed in to change notification settings - Fork 219
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
Use propagate!
instead of Libtask.consume
#1237
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1237 +/- ##
==========================================
- Coverage 66.40% 66.25% -0.16%
==========================================
Files 25 25
Lines 1289 1286 -3
==========================================
- Hits 856 852 -4
- Misses 433 434 +1
Continue to review full report at Codecov.
|
@test consume(pc) == log(1) | ||
# Propagate particles. | ||
propagate!(pc) | ||
@test getweights(pc) == weights |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused here. Shouldn't new weights be different from old weights, since no resampling is performed in propagate!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I forgot that there was no observation in the model. For the purpose of correctly testing propagate!
, maybe consider adding some likelihood in the test?
Thanks, @devmotion. It's a good idea to remove the dependency on
I think we had a step for subtracting the constant term in previous versions of the code, but I can't recall where that was, and when that was removed. |
I completely agree, probably it would be useful to implement and use an iterator interface for particles, so that one could use alternative particle implementations such as ordinary stateful iterators. IMO it's just not useful and unintuitive (due to the behaviour of |
I'll update the test in a separate PR. |
* Use `propagate!` instead of `Libtask.consume` * Fix tests
This PR removes Libtask in the propagation of
ParticleContainer
. Instead it introduces a functionpropagate!
that propagates all particles one step and returnstrue
if all particles are propagated to the final time step andfalse
otherwise (maybe one would rather want to use more explicit symbols instead of booleans?).I always had the same impression as @mohamed82008 (see #1233) that in particular for the propagation of the particle container one does not have to use Libtask. However, since
collect(::ParticleContainer)
returns the particles IMO it would be surprising if iterating over a particle container would propagate it. Moreover, since it seems there are no states that have to be tracked by the container (I even removedn_consume
andlogE
in the particle container), it felt more natural to add a method for propagation, similar toresample!
for the resampling step, than using a dedicated iterator forParticleContainer
.I didn't fully understand the existing implementation of the likelihood estimation (isn't the currently reported log evidence incorrect since
logZ
neglects the constant term-log(num_particles)
?), so I used the algorithm in http://www.it.uu.se/research/systems_and_control/education/2019/smc/schedule/lecture9.pdf (pages 5, 6, and 7) as a template - basically, now the implementation forSMC
andPG
should perform exactly the same sequence of propagation and resampling steps as noted there usingpropagate!
andresample!
.Aside from that, I'm slightly unhappy with the current implementation of
SMC
since it somehow misusesspl.state.average_logevidence
to save the log likelihood estimate of all particles that is computed insample_init!
, then uses it in every iteration ofstep!
in which theParticleTransition
s for every particle are created, and finally computes the "overall" log evidence inbundle_samples!
by settingspl.state.average_logevidence
to the mean of the log evidence values of these particles (i.e., the value thatspl.state.average_logevidence
was set to insample_init!
). It's also a bit annoying that for SMC aniteration
keyword argument is needed (IMO that should be part of the state, i.e., transition and not be part of the generic algorithm in AbstractMCMC since it seems only/mostly SMC uses it).