Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Aug 29, 2024
1 parent 07cc40b commit 65dd7f3
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions src/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,58 +563,3 @@ end
function AHMCAdaptor(::Hamiltonian, ::AHMC.AbstractMetric; kwargs...)
return AHMC.Adaptation.NoAdaptation()
end

##########################
# HMC State Constructors #
##########################

function HMCState(
rng::AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
vi::AbstractVarInfo;
kwargs...,
)
# Link everything if needed.
waslinked = islinked(vi, spl)
if !waslinked
vi = link!!(vi, spl, model)
end

# Get the initial log pdf and gradient functions.
∂logπ∂θ = gen_∂logπ∂θ(vi, spl, model)
logπ = Turing.LogDensityFunction(
vi,
model,
DynamicPPL.SamplingContext(rng, spl, DynamicPPL.leafcontext(model.context)),
)

# Get the metric type.
metricT = getmetricT(spl.alg)

# Create a Hamiltonian.
θ_init = Vector{Float64}(spl.state.vi[spl])
metric = metricT(length(θ_init))
h = AHMC.Hamiltonian(metric, logπ, ∂logπ∂θ)

# Find good eps if not provided one
if iszero(spl.alg.ϵ)
ϵ = AHMC.find_good_stepsize(rng, h, θ_init)
@info "Found initial step size" ϵ
else
ϵ = spl.alg.ϵ
end

# Generate a kernel.
kernel = make_ahmc_kernel(spl.alg, ϵ)

# Generate a phasepoint. Replaced during sample_init!
h, t = AHMC.sample_init(rng, h, θ_init) # this also ensure AHMC has the same dim as θ.

# Unlink everything, if it was indeed linked before.
if waslinked
vi = invlink!!(vi, spl, model)
end

return HMCState(vi, 0, 0, kernel.τ, h, AHMCAdaptor(spl.alg, metric; ϵ=ϵ), t.z)
end

0 comments on commit 65dd7f3

Please sign in to comment.