Skip to content

Commit 422fc68

Browse files
committed
Use typed varinfo for Prior
1 parent 806c82d commit 422fc68

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

HISTORY.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# 0.40.0
22

3-
[...]
3+
TODO
4+
5+
- DynamicPPL 0.37 stuff
6+
7+
- pMCMC and Gibbs?
8+
- Prior is faster
49

510
# 0.39.9
611

src/mcmc/prior.jl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ struct Prior <: InferenceAlgorithm end
88
function AbstractMCMC.step(
99
rng::Random.AbstractRNG,
1010
model::DynamicPPL.Model,
11-
sampler::DynamicPPL.Sampler{<:Prior},
12-
state=nothing;
11+
sampler::DynamicPPL.Sampler{<:Prior};
1312
kwargs...,
1413
)
1514
# TODO(DPPL0.38/penelopeysm): replace with init!!
@@ -26,5 +25,27 @@ function AbstractMCMC.step(
2625
),
2726
)
2827
_, vi = DynamicPPL.evaluate!!(sampling_model, vi)
29-
return Transition(model, vi, nothing; reevaluate=false), nothing
28+
vi = DynamicPPL.typed_varinfo(vi)
29+
return Transition(model, vi, nothing; reevaluate=false), vi
30+
end
31+
32+
function AbstractMCMC.step(
33+
rng::Random.AbstractRNG,
34+
model::DynamicPPL.Model,
35+
sampler::DynamicPPL.Sampler{<:Prior},
36+
vi::AbstractVarInfo;
37+
kwargs...,
38+
)
39+
# TODO(DPPL0.38/penelopeysm): replace the entire thing with init!!
40+
# `vi` is a VarInfo from the previous step so already has all the
41+
# right accumulators and stuff. The only thing we need to change is
42+
# to make sure that the old values are overwritten...
43+
for vn in keys(vi)
44+
DynamicPPL.set_flag!(vi, vn, "del")
45+
end
46+
sampling_model = DynamicPPL.contextualize(
47+
model, DynamicPPL.SamplingContext(rng, DynamicPPL.SampleFromPrior(), model.context)
48+
)
49+
_, vi = DynamicPPL.evaluate!!(sampling_model, vi)
50+
return Transition(model, vi, nothing; reevaluate=false), vi
3051
end

0 commit comments

Comments
 (0)