Skip to content

Commit

Permalink
Make SGHMC more flexible (#1586)
Browse files Browse the repository at this point in the history
Co-authored-by: David Widmann <[email protected]>
  • Loading branch information
haozhangphd and devmotion authored Apr 20, 2021
1 parent 21f464c commit 46c0589
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.15.17"
version = "0.15.18"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
8 changes: 4 additions & 4 deletions src/contrib/inference/sghmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function SGHMC{AD}(
return SGHMC{AD,space,typeof(_learning_rate)}(_learning_rate, _momentum_decay)
end

struct SGHMCState{V<:AbstractVarInfo}
struct SGHMCState{V<:AbstractVarInfo, T<:AbstractVector{<:Real}}
vi::V
velocity::Vector{Float64}
velocity::T
end

function DynamicPPL.initialstep(
Expand Down Expand Up @@ -84,7 +84,7 @@ function AbstractMCMC.step(
θ .+= v
η = spl.alg.learning_rate
α = spl.alg.momentum_decay
newv = (1 - α) .* v .+ η .* grad .+ sqrt(2 * η * α) .* randn(rng, length(v))
newv = (1 - α) .* v .+ η .* grad .+ sqrt(2 * η * α) .* randn(rng, eltype(v), length(v))

# Save new variables and recompute log density.
vi[spl] = θ
Expand Down Expand Up @@ -229,7 +229,7 @@ function AbstractMCMC.step(
_, grad = gradient_logp(θ, vi, model, spl)
step = state.step
stepsize = spl.alg.stepsize(step)
θ .+= (stepsize / 2) .* grad .+ sqrt(stepsize) .* randn(rng, length(θ))
θ .+= (stepsize / 2) .* grad .+ sqrt(stepsize) .* randn(rng, eltype(θ), length(θ))

# Save new variables and recompute log density.
vi[spl] = θ
Expand Down

2 comments on commit 46c0589

@devmotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/34799

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.15.18 -m "<description of version>" 46c05895d7e51028211a856c78b1cca60838c5d4
git push origin v0.15.18

Please sign in to comment.