From b3aa67d7f78abe314a2d41b8754e08989c700b52 Mon Sep 17 00:00:00 2001 From: Kai Xu Date: Mon, 4 Nov 2019 02:03:28 +0000 Subject: [PATCH] Make integer constraint flexible (#126) * add a note * fix type def --- src/integrator.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/integrator.jl b/src/integrator.jl index 6517b9ac..18620c54 100644 --- a/src/integrator.jl +++ b/src/integrator.jl @@ -2,13 +2,17 @@ #### Numerical methods for simulating Hamiltonian trajectory. #### +# TODO: The type `<:Tuple{Integer,Bool}` is introduced to address +# https://github.com/TuringLang/Turing.jl/pull/941#issuecomment-549191813 +# We might want to simplify it to `Tuple{Int,Bool}` when we figured out +# why the it behaves unexpected on Windos 32. abstract type AbstractIntegrator end abstract type AbstractLeapfrog{T} <: AbstractIntegrator end jitter(::AbstractRNG, ::AbstractLeapfrog, ϵ) = ϵ -temper(lf::AbstractLeapfrog, r, ::NamedTuple{(:i, :is_half),Tuple{Int,Bool}}, ::Int) = r +temper(lf::AbstractLeapfrog, r, ::NamedTuple{(:i, :is_half),<:Tuple{Integer,Bool}}, ::Int) = r function step( rng::AbstractRNG, @@ -79,13 +83,13 @@ function Base.show(io::IO, l::TemperedLeapfrog) end """ - temper(lf::TemperedLeapfrog, r, step::NamedTuple{(:i, :is_half),Tuple{Int,Bool}}, n_steps::Int) + temper(lf::TemperedLeapfrog, r, step::NamedTuple{(:i, :is_half),<:Tuple{Integer,Bool}}, n_steps::Int) Tempering step. `step` is a named tuple with - `i` being the current leapfrog iteration and - `is_half` indicating whether or not it's (the first) half momentum/tempering step """ -function temper(lf::TemperedLeapfrog, r, step::NamedTuple{(:i, :is_half),Tuple{Int,Bool}}, n_steps::Int) +function temper(lf::TemperedLeapfrog, r, step::NamedTuple{(:i, :is_half),<:Tuple{Integer,Bool}}, n_steps::Int) i_temper = 2(step.i - 1) + 1 + step.is_half # counter for half temper steps return i_temper <= n_steps ? r * sqrt(lf.α) : r / sqrt(lf.α) end