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

Update no-U-turn criteria and added some unit tests #91

Merged
merged 51 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
231b36e
add mv gass test for preconditioner #25
xukai92 Aug 16, 2019
4db2ebd
implement an interface to support multiple termination criteria
xukai92 Aug 16, 2019
0743e1a
add some unit tests for different metrics
xukai92 Aug 16, 2019
bd2ba31
bugfix
xukai92 Aug 16, 2019
d6aeedc
tiny up comments
xukai92 Aug 16, 2019
519688d
add test for tree sampler
xukai92 Aug 16, 2019
46d0b6d
add generalised u-turn (buggy)
xukai92 Aug 17, 2019
6c511a9
refactor transition using FullBinaryTree
xukai92 Aug 17, 2019
59035f4
add test for termination criteria
xukai92 Aug 17, 2019
ab52bcd
add test for termination
xukai92 Aug 17, 2019
32ea1e7
warn full binary tree is not tested
xukai92 Aug 17, 2019
4df7b03
fix u-turn bug and improve numerical stability
xukai92 Aug 17, 2019
054487a
change default to generalised
xukai92 Aug 17, 2019
2d69b5a
clean up isturn
xukai92 Aug 18, 2019
560f8c9
fix typo
xukai92 Aug 18, 2019
3374cba
fix the tree depth shift bug
xukai92 Aug 18, 2019
bc9b55e
remove old tests
xukai92 Aug 18, 2019
5054081
remove symbol iniitalisation of NUTS
xukai92 Aug 18, 2019
a31f9ca
implement show for different NUTS types
xukai92 Aug 18, 2019
acad240
rename isturn to isterminated
xukai92 Aug 18, 2019
c09c8bb
move termination out of tree
xukai92 Aug 18, 2019
a41d453
simplify new interface
xukai92 Aug 18, 2019
1c24459
seperate zcand and sampler from tree
xukai92 Aug 18, 2019
0c48a25
remove non-necessary energy argument
xukai92 Aug 18, 2019
d347342
fix typo
xukai92 Aug 18, 2019
0e7f13e
fix broken tests
xukai92 Aug 18, 2019
a69f8ad
add test for no U-turn
xukai92 Aug 18, 2019
6ab2d9c
update interface and test for full binary tree
xukai92 Aug 18, 2019
8baf321
improve test script
xukai92 Aug 18, 2019
4215b40
fix u-turn and improve tests
xukai92 Aug 18, 2019
2bde38f
clean up code
xukai92 Aug 19, 2019
bf287f9
disable test for original no-U-turn
xukai92 Aug 19, 2019
f84c3aa
fix original u-turn logic and test
xukai92 Aug 19, 2019
aaa24b0
update demo and inc version number
xukai92 Aug 19, 2019
0fa523e
renmae XTreeSampler to XTrajectorySampler
xukai92 Aug 19, 2019
f3eab50
logu -> ℓu
xukai92 Aug 19, 2019
4036eee
logw -> ℓw
xukai92 Aug 19, 2019
35dff6d
update comments
xukai92 Aug 19, 2019
e66f628
NoUTurn -> ClassicNoUTurn
xukai92 Aug 19, 2019
c4e4b44
update type signature for GeneralisedNoUTurn
xukai92 Aug 19, 2019
39dd7c5
remove unused type in isterminated
xukai92 Aug 19, 2019
30c40a5
improve naming in isterminated for ClassicNoUTurn
xukai92 Aug 19, 2019
89ba82b
t -> tree
xukai92 Aug 19, 2019
866c901
improve code of mh_accept for multinomial sampling
xukai92 Aug 19, 2019
345cdec
FullBinaryTree -> BinaryTree
xukai92 Aug 19, 2019
b62e322
remove duplicate word for
xukai92 Aug 19, 2019
134e43b
fix type bug
xukai92 Aug 19, 2019
e07520e
fix unchanged tree sampler names
xukai92 Aug 19, 2019
0a09e1a
fix unchanged tree sampler names
xukai92 Aug 19, 2019
bd7af6b
α -> sum_α
xukai92 Aug 19, 2019
15c254d
?TrajctorySampler -> ?
xukai92 Aug 19, 2019
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
2 changes: 1 addition & 1 deletion 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.2"
version = "0.2.3"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ using Distributions: logpdf, MvNormal
using DiffResults: GradientResult, value, gradient
using ForwardDiff: gradient!

const D = 10
const target = MvNormal(zeros(D), ones(D))
D = 10
target = MvNormal(zeros(D), ones(D))
ℓπ(θ) = logpdf(target, θ)

function ∂ℓπ∂θ(θ)
Expand All @@ -28,17 +28,17 @@ end
using AdvancedHMC

# Sampling parameter settings
n_samples = 100_000
n_adapts = 2_000
n_samples, n_adapts = 10_000, 2_000

# Draw a random starting points
θ_init = randn(D)

# Define metric space, Hamiltonian, sampling method and adaptor
metric = DiagEuclideanMetric(D)
h = Hamiltonian(metric, ℓπ, ∂ℓπ∂θ)
prop = NUTS(Leapfrog(find_good_eps(h, θ_init)))
adaptor = StanHMCAdaptor(n_adapts, Preconditioner(metric), NesterovDualAveraging(0.8, prop.integrator.ϵ))
int = Leapfrog(find_good_eps(h, θ_init))
prop = NUTS{MultinomialTrajectorySampler,GeneralisedNoUTurn}(int)
adaptor = StanHMCAdaptor(n_adapts, Preconditioner(metric), NesterovDualAveraging(0.8, int.ϵ))

# Draw samples via simulating Hamiltonian dynamics
# - `samples` will store the samples
Expand Down
2 changes: 1 addition & 1 deletion src/AdvancedHMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export Hamiltonian
include("integrator.jl")
export Leapfrog
include("trajectory.jl")
export StaticTrajectory, find_good_eps, HMCDA, NUTS
export StaticTrajectory, find_good_eps, HMCDA, NUTS, SliceTrajectorySampler, MultinomialTrajectorySampler, NoUTurn, GeneralisedNoUTurn

include("diagnosis.jl")
include("sampler.jl")
Expand Down
2 changes: 2 additions & 0 deletions src/hamiltonian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ function neg_energy(
return -dot(r, h.metric._temp) / 2
end

energy(args...) = -neg_energy(args...)

####
#### Momentum refreshment
####
Expand Down
Loading