Skip to content

Conversation

@devmotion
Copy link
Member

This PR simplifies ParticleContainer a bit more by removing the model field which hasn't been used (and was actually misused in the tests by setting it to arbitrary functions). Moreover, it adds the additional tests promised in #1237 (comment).

When I added the tests I was a bit surprised actually that the implementation of propagate! (and consume before, that code was not modified in the recent PR) increases the unnormalized logarithmic weights of the particles with the values that are produced by the particles and not just sets them to these values (as I would have expected from the algorithm since, if I understand correctly, these values correspond to the log probability of the next "observation"). In the currently implemented samplers (SMC and PG) this does not matter though since the unnormalized weights are reset in the resample! step which is performed before every propagate! step. Nevertheless, I'm wondering what's the reason for the current implementation?

@codecov
Copy link

codecov bot commented Apr 27, 2020

Codecov Report

Merging #1242 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1242   +/-   ##
=======================================
  Coverage   66.25%   66.25%           
=======================================
  Files          25       25           
  Lines        1286     1286           
=======================================
  Hits          852      852           
  Misses        434      434           
Impacted Files Coverage Δ
src/core/container.jl 93.02% <100.00%> (ø)
src/inference/AdvancedSMC.jl 98.57% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32845f8...75785e6. Read the comment docs.

@yebai
Copy link
Member

yebai commented Apr 28, 2020

When I added the tests I was a bit surprised actually that the implementation of propagate! (and consume before, that code was not modified in the recent PR) increases the unnormalized logarithmic weights of the particles with the values that are produced by the particles and not just sets them to these values (as I would have expected from the algorithm since, if I understand correctly, these values correspond to the log probability of the next "observation"). In the currently implemented samplers (SMC and PG) this does not matter though since the unnormalized weights are reset in the resample! step which is performed before every propagate! step. Nevertheless, I'm wondering what's the reason for the current implementation?

IIRC, these are intended for supporting adaptive resampling, where the particle weights get accumulated for multiple time steps until the ESS falls below some threshold.

Copy link
Member

@yebai yebai left a comment

Choose a reason for hiding this comment

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

Looks great, many thanks @devmotion!

@test iszero(lz)
# Create particle container.
logps = [0.0, -1.0, -2.0]
particles = [Trace(fpc(logp), empty_model(), sampler, VarInfo()) for logp in logps]
Copy link
Member

Choose a reason for hiding this comment

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

This looks good. On a side note, it's strange that we still have the following two Trace constructors:

function Trace(f::Function, m::Model, spl::AbstractSampler, vi::AbstractVarInfo)
function Trace(m::Model, spl::AbstractSampler, vi::AbstractVarInfo)

maybe we can consider merging these two in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that's a bit strange indeed.

@yebai yebai merged commit 3e18ac2 into TuringLang:master Apr 28, 2020
@devmotion devmotion deleted the particles branch April 28, 2020 21:40
phipsgabler pushed a commit to phipsgabler/Turing.jl that referenced this pull request May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants