Skip to content

Commit 3d47e8a

Browse files
committed
fix JET tests
1 parent dc8dc1c commit 3d47e8a

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/integrator.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ Leapfrog integrator with randomly "jittered" step size `ϵ` for every trajectory
8989
$(TYPEDFIELDS)
9090
9191
# Description
92-
This is the same as `LeapFrog`(@ref) but with a "jittered" step size. This means
93-
that at the beginning of each trajectory we sample a step size `ϵ` by adding or
94-
subtracting from the nominal/base step size `ϵ0` some random proportion of `ϵ0`,
92+
This is the same as `LeapFrog`(@ref) but with a "jittered" step size. This means
93+
that at the beginning of each trajectory we sample a step size `ϵ` by adding or
94+
subtracting from the nominal/base step size `ϵ0` some random proportion of `ϵ0`,
9595
with the proportion specified by `jitter`, i.e. `ϵ = ϵ0 - jitter * ϵ0 * rand()`.
9696
p
9797
Jittering might help alleviate issues related to poor interactions with a fixed step size:
98-
- In regions with high "curvature" the current choice of step size might mean over-shoot
99-
leading to almost all steps being rejected. Randomly sampling the step size at the
98+
- In regions with high "curvature" the current choice of step size might mean over-shoot
99+
leading to almost all steps being rejected. Randomly sampling the step size at the
100100
beginning of the trajectories can therefore increase the probability of escaping such
101101
high-curvature regions.
102102
- Exact periodicity of the simulated trajectories might occur, i.e. you might be so
@@ -168,7 +168,7 @@ $(TYPEDFIELDS)
168168
169169
# Description
170170
171-
Tempering can potentially allow greater exploration of the posterior, e.g.
171+
Tempering can potentially allow greater exploration of the posterior, e.g.
172172
in a multi-modal posterior jumps between the modes can be more likely to occur.
173173
"""
174174
struct TemperedLeapfrog{FT<:AbstractFloat,T<:AbstractScalarOrVec{FT}} <: AbstractLeapfrog{T}
@@ -226,9 +226,7 @@ function step(
226226
ϵ = fwd ? step_size(lf) : -step_size(lf)
227227
ϵ = ϵ'
228228

229-
if FullTraj
230-
res = Vector{P}(undef, n_steps)
231-
end
229+
res = FullTraj ? Vector{P}(undef, n_steps) : nothing
232230

233231
(; θ, r) = z
234232
(; value, gradient) = z.ℓπ
@@ -248,12 +246,12 @@ function step(
248246
# Create a new phase point by caching the logdensity and gradient
249247
z = phasepoint(h, θ, r; ℓπ=DualValue(value, gradient))
250248
# Update result
251-
if FullTraj
249+
if !isnothing(res)
252250
res[i] = z
253251
end
254252
if !isfinite(z)
255253
# Remove undef
256-
if FullTraj
254+
if !isnothing(res)
257255
resize!(res, i)
258256
end
259257
break

src/riemannian/integrator.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Generalized leapfrog integrator with fixed step size `ϵ`.
88
$(TYPEDFIELDS)
99
1010
11-
## References
11+
## References
1212
1313
1. Girolami, Mark, and Ben Calderhead. "Riemann manifold Langevin and Hamiltonian Monte Carlo methods." Journal of the Royal Statistical Society Series B: Statistical Methodology 73, no. 2 (2011): 123-214.
1414
"""
@@ -29,7 +29,7 @@ end
2929

3030
# TODO(Kai) make sure vectorization works
3131
# TODO(Kai) check if tempering is valid
32-
# TODO(Kai) abstract out the 3 main steps and merge with `step` in `integrator.jl`
32+
# TODO(Kai) abstract out the 3 main steps and merge with `step` in `integrator.jl`
3333
function step(
3434
lf::GeneralizedLeapfrog{T},
3535
h::Hamiltonian,
@@ -59,7 +59,7 @@ function step(
5959
#r = temper(lf, r, (i=i, is_half=true), n_steps)
6060
# eq (16) of Girolami & Calderhead (2011)
6161
r_half = r_init
62-
local cache
62+
local cache = nothing
6363
for j in 1:(lf.n)
6464
# Reuse cache for the first iteration
6565
if j == 1

0 commit comments

Comments
 (0)