|
1 | | -using Random, LinearAlgebra, ReverseDiff, ForwardDiff, VecTargets |
| 1 | +using Random, LinearAlgebra, ReverseDiff, ForwardDiff, MCMCLogDensityProblems |
2 | 2 |
|
3 | 3 | # Fisher information metric |
4 | 4 | function gen_∂G∂θ_rev(Vfunc, x; f=identity) |
5 | | - _Hfunc = VecTargets.gen_hess(Vfunc, ReverseDiff.track.(x)) |
| 5 | + _Hfunc = MCMCLogDensityProblems.gen_hess(Vfunc, ReverseDiff.track.(x)) |
6 | 6 | Hfunc = x -> _Hfunc(x)[3] |
7 | 7 | # QUES What's the best output format of this function? |
8 | 8 | return x -> ReverseDiff.jacobian(x -> f(Hfunc(x)), x) # default output shape [∂H∂x₁; ∂H∂x₂; ...] |
|
37 | 37 |
|
38 | 38 | function prepare_sample_target(hps, θ₀, ℓπ) |
39 | 39 | Vfunc = x -> -ℓπ(x) # potential energy is the negative log-probability |
40 | | - _Hfunc = VecTargets.gen_hess(Vfunc, θ₀) # x -> (value, gradient, hessian) |
| 40 | + _Hfunc = MCMCLogDensityProblems.gen_hess(Vfunc, θ₀) # x -> (value, gradient, hessian) |
41 | 41 | Hfunc = x -> copy.(_Hfunc(x)) # _Hfunc do in-place computation, copy to avoid bug |
42 | 42 |
|
43 | 43 | fstabilize = H -> H + hps.λ * I |
@@ -70,8 +70,8 @@ function prepare_sample(hps; rng=MersenneTwister(1110)) |
70 | 70 |
|
71 | 71 | θ₀ = rand(rng, dim(target)) |
72 | 72 |
|
73 | | - ℓπ = VecTargets.gen_logpdf(target) |
74 | | - ∂ℓπ∂θ = VecTargets.gen_logpdf_grad(target, θ₀) |
| 73 | + ℓπ = MCMCLogDensityProblems.gen_logpdf(target) |
| 74 | + ∂ℓπ∂θ = MCMCLogDensityProblems.gen_logpdf_grad(target, θ₀) |
75 | 75 |
|
76 | 76 | _, _, Gfunc, ∂G∂θfunc = prepare_sample_target(hps, θ₀, ℓπ) |
77 | 77 |
|
|
0 commit comments