Skip to content

Commit

Permalink
Merge branch 'master' into kx/mat-support
Browse files Browse the repository at this point in the history
  • Loading branch information
xukai92 committed Nov 5, 2019
2 parents 30cbfb4 + 680dec2 commit 3020de5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AdvancedHMC"
uuid = "0bf59076-c3b1-5ca4-86bd-e02cd72cde3d"
version = "0.2.9"
version = "0.2.11"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand All @@ -18,10 +18,10 @@ StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
julia = "1"
ArgCheck = "1"
InplaceOps = "0.3"
LazyArrays = "0.9,0.12"
Parameters = "0.10,0.11,0.12"
LazyArrays = "0.9, 0.10, 0.11, 0.12, 0.13"
Parameters = "0.10, 0.11, 0.12"
ProgressMeter = "1"
StatsBase = "0.31"
StatsBase = "0.31, 0.32"
StatsFuns = "0.8"

[extras]
Expand Down
10 changes: 7 additions & 3 deletions src/integrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,13 +84,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

0 comments on commit 3020de5

Please sign in to comment.