-
Notifications
You must be signed in to change notification settings - Fork 230
Update DynamicPPL.jl version #1726
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
Changes from all commits
852a754
e926b0b
181ec0d
972334c
78e4b47
afb817f
08aa203
0af43d8
26dc3d0
e9d63d6
7fbe6eb
cf7383c
024f83d
4c1db31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ function AdvancedPS.reset_model(f::TracedModel) | |
| end | ||
|
|
||
| function AdvancedPS.reset_logprob!(f::TracedModel) | ||
| DynamicPPL.resetlogp!(f.varinfo) | ||
| DynamicPPL.resetlogp!!(f.varinfo) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also relies on the fact that it mutates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, but |
||
| return | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,8 +110,8 @@ function DynamicPPL.initialstep( | |
| # Reset the VarInfo. | ||
| reset_num_produce!(vi) | ||
| set_retained_vns_del_by_spl!(vi, spl) | ||
| resetlogp!(vi) | ||
| empty!(vi) | ||
| resetlogp!!(vi) | ||
| empty!!(vi) | ||
|
Comment on lines
+113
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the calls below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same response as above: these samplers aren't compatible with immutable |
||
|
|
||
| # Create a new set of particles. | ||
| particles = AdvancedPS.ParticleContainer( | ||
|
|
@@ -249,7 +249,7 @@ function DynamicPPL.initialstep( | |
| # Reset the VarInfo before new sweep | ||
| reset_num_produce!(vi) | ||
| set_retained_vns_del_by_spl!(vi, spl) | ||
| resetlogp!(vi) | ||
| resetlogp!!(vi) | ||
|
|
||
| # Create a new set of particles | ||
| num_particles = spl.alg.nparticles | ||
|
|
@@ -281,7 +281,7 @@ function AbstractMCMC.step( | |
| ) | ||
| # Reset the VarInfo before new sweep. | ||
| reset_num_produce!(vi) | ||
| resetlogp!(vi) | ||
| resetlogp!!(vi) | ||
|
|
||
| # Create reference particle for which the samples will be retained. | ||
| reference = AdvancedPS.forkr(AdvancedPS.Trace(model, spl, vi)) | ||
|
|
@@ -315,6 +315,8 @@ function AbstractMCMC.step( | |
| return transition, _vi | ||
| end | ||
|
|
||
| DynamicPPL.use_threadsafe_eval(::SamplingContext{<:Sampler{<:Union{PG,SMC}}}, ::AbstractVarInfo) = false | ||
|
|
||
| function DynamicPPL.assume( | ||
| rng, | ||
| spl::Sampler{<:Union{PG,SMC}}, | ||
|
|
@@ -326,7 +328,7 @@ function DynamicPPL.assume( | |
| if inspace(vn, spl) | ||
| if ~haskey(vi, vn) | ||
| r = rand(rng, dist) | ||
| push!(vi, vn, r, dist, spl) | ||
| push!!(vi, vn, r, dist, spl) | ||
| elseif is_flagged(vi, vn, "del") | ||
| unset_flag!(vi, vn, "del") | ||
| r = rand(rng, dist) | ||
|
|
@@ -342,17 +344,17 @@ function DynamicPPL.assume( | |
| r = vi[vn] | ||
| else | ||
| r = rand(rng, dist) | ||
| push!(vi, vn, r, dist, DynamicPPL.Selector(:invalid)) | ||
| push!!(vi, vn, r, dist, DynamicPPL.Selector(:invalid)) | ||
| end | ||
| lp = logpdf_with_trans(dist, r, istrans(vi, vn)) | ||
| acclogp!(vi, lp) | ||
| acclogp!!(vi, lp) | ||
| end | ||
| return r, 0 | ||
| return r, 0, vi | ||
| end | ||
|
|
||
| function DynamicPPL.observe(spl::Sampler{<:Union{PG,SMC}}, dist::Distribution, value, vi) | ||
| produce(logpdf(dist, value)) | ||
| return 0 | ||
| return 0, vi | ||
| end | ||
|
|
||
| # Convenient constructor | ||
|
|
||
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 guess ideally we would want a no-op here when
setlogp!!returns a new object - if we just callsetlogp!!with a SimpleVarInfo it would create a new VarInfo object even though it's never used. Maybe one could check ifvi === new_viand only callsetlogp!!if it istrue(assuming that in this casesetlogp!!would not return a new object)?But I guess this should be left for the SimpleVarInfo PR?
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.
Will this not be optimized away in the case where
viis immutable?I sort of assumed so. But I guess we might as well give the compiler a helping hand just to be sure.