Skip to content

Commit c7090ba

Browse files
nsicchaJ-Price-3
authored andcommitted
fix JET tests (#479)
1 parent 473cc93 commit c7090ba

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/integrator.jl

Lines changed: 9 additions & 12 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,10 +226,7 @@ function step(
226226
ϵ = fwd ? step_size(lf) : -step_size(lf)
227227
ϵ = ϵ'
228228

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

234231
(; θ, r) = z
235232
(; value, gradient) = z.ℓπ
@@ -249,12 +246,12 @@ function step(
249246
# Create a new phase point by caching the logdensity and gradient
250247
z = phasepoint(h, θ, r; ℓπ=DualValue(value, gradient))
251248
# Update result
252-
if FullTraj
249+
if !isnothing(res)
253250
res[i] = z
254251
end
255252
if !isfinite(z)
256253
# Remove undef
257-
if FullTraj
254+
if !isnothing(res)
258255
resize!(res, i)
259256
end
260257
break

src/riemannian/integrator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Generalized leapfrog integrator with fixed step size `ϵ`.
1111
$(TYPEDFIELDS)
1212
1313
14-
## References
14+
## References
1515
1616
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.
1717
"""
@@ -77,7 +77,7 @@ end
7777

7878
# TODO(Kai) make sure vectorization works
7979
# TODO(Kai) check if tempering is valid
80-
# TODO(Kai) abstract out the 3 main steps and merge with `step` in `integrator.jl`
80+
# TODO(Kai) abstract out the 3 main steps and merge with `step` in `integrator.jl`
8181
function step(
8282
lf::GeneralizedLeapfrog{T},
8383
h::Hamiltonian{<:DenseRiemannianMetric},

0 commit comments

Comments
 (0)