Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paste some adjustment in there #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ end
mutable struct MCHMCSampler <: AbstractMCMC.AbstractSampler
nadapt::Int
TEV::Real
TAP::Real # this isn't type stable
adaptive::Bool
tune_eps::Bool
tune_L::Bool
Expand All @@ -32,12 +33,13 @@ end
"""
MCHMC(
nadapt::Int,
TEV::Real;
TEV::Real,
TAP::Real;
kwargs...
)
Constructor for the MicroCanonical HMC (q=0 Hamiltonian) sampler
"""
function MCHMC(nadapt::Int, TEV::Real;
function MCHMC(nadapt::Int, TEV::Real, TAP::Real;
integrator="LF",
adaptive=false,
tune_eps=true,
Expand All @@ -57,7 +59,7 @@ function MCHMC(nadapt::Int, TEV::Real;
println(string("integrator = ", integrator, "is not a valid option."))
end

return MCHMCSampler(nadapt, TEV, adaptive, tune_eps, tune_L, tune_sigma, hyperparameters, hamiltonian_dynamics)
return MCHMCSampler(nadapt, TEV, TAP, adaptive, tune_eps, tune_L, tune_sigma, hyperparameters, hamiltonian_dynamics)
end

function Random_unit_vector(rng::AbstractRNG, x::AbstractVector{T}; _normalize = true) where {T}
Expand Down Expand Up @@ -166,6 +168,7 @@ function Step(
gamma = sampler.hyperparameters.gamma

TEV = sampler.TEV
TAP = sampler.TAP

# Hamiltonian step
xx, uu, ll, gg, kinetic_change = sampler.hamiltonian_dynamics(sampler, state)
Expand All @@ -189,6 +192,17 @@ function Step(
sampler.hyperparameters.eps = eps
end

x, u, l, g, dE = state.x, state.u, state.l, state.g, state.dE
accept = log(rand()) < dEE
xx = @.(accept * xx + (1 - accept) * x)
ll = @.(accept * ll + (1 - accept) * l)
gg = @.(accept * gg + (1 - accept) * g)
dEE = @.(accept * dEE + (1 - accept) * dE)

uuu = @.(accept * uuu + (1 - accept) * u)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we reject, try to refresh momentum and then lower the stepsize!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Take L177 and put it here




state = MCHMCState(rng, state.i + 1, xx, uuu, ll, gg, dEE, Weps, Feps, state.h)
transition = Transition(state, inv_transform)
return transition, state
Expand Down
Loading