Skip to content

Commit 98e70c2

Browse files
committed
Even more fixes
1 parent 66a8544 commit 98e70c2

File tree

4 files changed

+4
-41
lines changed

4 files changed

+4
-41
lines changed

ext/TuringDynamicHMCExt.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ function DynamicPPL.initialstep(
7575

7676
# Update the variables.
7777
vi = DynamicPPL.unflatten(vi, Q.q)
78-
vi = DynamicPPL.setlogp!!(vi, Q.ℓq)
78+
# TODO(DPPL0.37/penelopeysm): This is obviously incorrect. Fix this.
79+
vi = DynamicPPL.setloglikelihood!!(vi, Q.ℓq)
80+
vi = DynamicPPL.setlogprior!!(vi, 0.0)
7981

8082
# Create first sample and state.
8183
sample = Turing.Inference.Transition(model, vi)

src/mcmc/mh.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ end
194194
function LogDensityProblems.logdensity(f::LogDensityFunction, x::NamedTuple)
195195
vi = deepcopy(f.varinfo)
196196
set_namedtuple!(vi, x)
197-
vi_new = last(DynamicPPL.evaluate!!(f.model, vi, f.context))
197+
vi_new = last(DynamicPPL.evaluate!!(f.model, vi))
198198
lj = f.getlogdensity(vi_new)
199199
return lj
200200
end

test/mcmc/hmc.jl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,6 @@ using Turing
171171
@test Array(res1) == Array(res2) == Array(res3)
172172
end
173173

174-
# TODO(mhauru) Do we give up being able to sample from only prior/likelihood like this,
175-
# or do we implement some way to pass `whichlogprob=:LogPrior` through `sample`?
176-
@testset "prior" begin
177-
# NOTE: Used to use `InverseGamma(2, 3)` but this has infinite variance
178-
# which means that it's _very_ difficult to find a good tolerance in the test below:)
179-
prior_dist = truncated(Normal(3, 1); lower=0)
180-
181-
@model function demo_hmc_prior()
182-
s ~ prior_dist
183-
return m ~ Normal(0, sqrt(s))
184-
end
185-
alg = NUTS(1000, 0.8)
186-
gdemo_default_prior = DynamicPPL.contextualize(
187-
demo_hmc_prior(), DynamicPPL.PriorContext()
188-
)
189-
chain = sample(gdemo_default_prior, alg, 5_000; initial_params=[3.0, 0.0])
190-
check_numerical(chain, [:s, :m], [mean(prior_dist), 0]; atol=0.2)
191-
end
192-
193174
@testset "warning for difficult init params" begin
194175
attempt = 0
195176
@model function demo_warn_initial_params()

test/mcmc/mh.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -262,26 +262,6 @@ GKernel(var) = (x) -> Normal(x, sqrt.(var))
262262
@test !DynamicPPL.islinked(vi)
263263
end
264264

265-
# TODO(mhauru) Do we give up being able to sample from only prior/likelihood like this,
266-
# or do we implement some way to pass `whichlogprob=:LogPrior` through `sample`?
267-
@testset "prior" begin
268-
alg = MH()
269-
gdemo_default_prior = DynamicPPL.contextualize(
270-
gdemo_default, DynamicPPL.PriorContext()
271-
)
272-
burnin = 10_000
273-
n = 10_000
274-
chain = sample(
275-
StableRNG(seed),
276-
gdemo_default_prior,
277-
alg,
278-
n;
279-
discard_initial=burnin,
280-
thinning=10,
281-
)
282-
check_numerical(chain, [:s, :m], [mean(InverseGamma(2, 3)), 0]; atol=0.3)
283-
end
284-
285265
@testset "`filldist` proposal (issue #2180)" begin
286266
@model demo_filldist_issue2180() = x ~ MvNormal(zeros(3), I)
287267
chain = sample(

0 commit comments

Comments
 (0)