Skip to content

Commit 9876a9b

Browse files
committed
More test fixes
1 parent bc1282b commit 9876a9b

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

src/mcmc/emcee.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function AbstractMCMC.step(
6565
end
6666

6767
# Compute initial transition and states.
68-
transition = map(Base.Fix1(Transition, model), vis)
68+
transition = [Transition(model, vi, vi[:], nothing) for vi in vis]
6969

7070
# TODO: Make compatible with immutable `AbstractVarInfo`.
7171
state = EmceeState(

src/mcmc/is.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ end
4343

4444
# Calculate evidence.
4545
function getlogevidence(samples::Vector{<:Transition}, ::Sampler{<:IS}, state)
46-
return logsumexp(map(x -> x.lp, samples)) - log(length(samples))
46+
return logsumexp(map(x -> x.loglikelihood, samples)) - log(length(samples))
4747
end
4848

4949
function DynamicPPL.assume(rng, ::Sampler{<:IS}, dist::Distribution, vn::VarName, vi)

src/mcmc/mh.jl

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,9 @@ function propose!!(
317317
),
318318
)
319319
trans, _ = AbstractMCMC.step(rng, densitymodel, mh_sampler, prev_trans)
320-
321-
# TODO: Make this compatible with immutable `VarInfo`.
322-
# Update the values in the VarInfo.
323-
# TODO(DPPL0.37/penelopeysm): This is obviously incorrect. We need to
324-
# re-evaluate the model.
320+
# trans.params isa NamedTuple
325321
set_namedtuple!(vi, trans.params)
326-
vi = DynamicPPL.setloglikelihood!!(vi, trans.lp)
327-
return DynamicPPL.setlogprior!!(vi, 0.0)
322+
return vi
328323
end
329324

330325
# Make a proposal if we DO have a covariance proposal matrix.
@@ -354,12 +349,8 @@ function propose!!(
354349
),
355350
)
356351
trans, _ = AbstractMCMC.step(rng, densitymodel, mh_sampler, prev_trans)
357-
358-
# TODO(DPPL0.37/penelopeysm): This is obviously incorrect. We need to
359-
# re-evaluate the model.
360-
vi = DynamicPPL.unflatten(vi, trans.params)
361-
vi = DynamicPPL.setloglikelihood!!(vi, trans.lp)
362-
return DynamicPPL.setlogprior!!(vi, 0.0)
352+
# trans.params isa AbstractVector
353+
return DynamicPPL.unflatten(vi, trans.params)
363354
end
364355

365356
function DynamicPPL.initialstep(
@@ -382,9 +373,9 @@ function AbstractMCMC.step(
382373
# Cases:
383374
# 1. A covariance proposal matrix
384375
# 2. A bunch of NamedTuples that specify the proposal space
385-
vi = propose!!(rng, vi, model, spl, spl.alg.proposals)
376+
new_vi = propose!!(rng, vi, model, spl, spl.alg.proposals)
386377

387-
return Transition(model, vi, vi[:], nothing), vi
378+
return Transition(model, new_vi, new_vi[:], nothing), new_vi
388379
end
389380

390381
####

src/mcmc/sghmc.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ function DynamicPPL.initialstep(
6767
# Compute initial sample and state.
6868
sample = Transition(model, vi, vi[:], nothing)
6969
= DynamicPPL.LogDensityFunction(
70-
model,
71-
vi,
72-
DynamicPPL.SamplingContext(spl, DynamicPPL.DefaultContext());
73-
adtype=spl.alg.adtype,
70+
model, DynamicPPL.getlogjoint_internal, vi; adtype=spl.alg.adtype
7471
)
7572
state = SGHMCState(ℓ, vi, zero(vi[:]))
7673

@@ -233,10 +230,7 @@ function DynamicPPL.initialstep(
233230
# Create first sample and state.
234231
sample = SGLDTransition(model, vi, zero(spl.alg.stepsize(0)))
235232
= DynamicPPL.LogDensityFunction(
236-
model,
237-
vi,
238-
DynamicPPL.SamplingContext(spl, DynamicPPL.DefaultContext());
239-
adtype=spl.alg.adtype,
233+
model, DynamicPPL.getlogjoint_internal, vi; adtype=spl.alg.adtype
240234
)
241235
state = SGLDState(ℓ, vi, 1)
242236

0 commit comments

Comments
 (0)