Skip to content

Commit

Permalink
Fixes for constructor docstrings (#347)
Browse files Browse the repository at this point in the history
* docstring fixes for constructors

* fixed docs

* minor fix for docs

* Update Project.toml

---------

Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
  • Loading branch information
torfjelde and yebai authored Aug 12, 2023
1 parent eb9b2e0 commit 3b6351f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 36 deletions.
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.5.3"
version = "0.5.4"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,23 @@ In the previous examples, we built the sampler by manually specifying the integr
Moreover, there's some flexibility in how these samplers can be initialized.
For example, a user can initialize a NUTS (HMC and HMCDA) sampler with their own metrics and integrators.
This can be done as follows:
```julia
nuts = NUTS(δ, metric = :diagonal) #metric = DiagEuclideanMetric(D) (Default!)
nuts = NUTS(δ, metric = :unit) #metric = UnitEuclideanMetric(D)
nuts = NUTS(δ, metric = :dense) #metric = DenseEuclideanMetric(D)
# Provide your own AbstractMetric
metric = DiagEuclideanMetric(10)
nuts = NUTS(δ, metric = metric)
nuts = NUTS(δ, integrator = :leapfrog) #integrator = Leapfrog(ϵ) (Default!)
nuts = NUTS(δ, integrator = :jitteredleapfrog) #integrator = JitteredLeapfrog(ϵ, 0.1ϵ)
nuts = NUTS(δ, integrator = :temperedleapfrog) #integrator = TemperedLeapfrog(ϵ, 1.0)
# Provide your own AbstractIntegrator
integrator = JitteredLeapfrog(0.1, 0.2)
nuts = NUTS(δ, integrator = integrator)
```

```julia
nuts = NUTS(δ, metric = :diagonal) #metric = DiagEuclideanMetric(D) (Default!)
nuts = NUTS(δ, metric = :unit) #metric = UnitEuclideanMetric(D)
nuts = NUTS(δ, metric = :dense) #metric = DenseEuclideanMetric(D)
# Provide your own AbstractMetric
metric = DiagEuclideanMetric(10)
nuts = NUTS(δ, metric = metric)
nuts = NUTS(δ, integrator = :leapfrog) #integrator = Leapfrog(ϵ) (Default!)
nuts = NUTS(δ, integrator = :jitteredleapfrog) #integrator = JitteredLeapfrog(ϵ, 0.1ϵ)
nuts = NUTS(δ, integrator = :temperedleapfrog) #integrator = TemperedLeapfrog(ϵ, 1.0)
# Provide your own AbstractIntegrator
integrator = JitteredLeapfrog(0.1, 0.2)
nuts = NUTS(δ, integrator = integrator)
```

### GPU Sampling with CUDA

Expand Down
22 changes: 3 additions & 19 deletions src/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,13 @@ sampler_eltype(sampler::HMCSampler) = eltype(sampler.metric)
### NUTS ###
############
"""
NUTS(δ::Real; max_depth::Int=10, Δ_max::Real=1000, init_ϵ::Real=0, integrator = :leapfrog, metric = :diagonal)
NUTS(δ::Real; max_depth::Int=10, Δ_max::Real=1000, integrator = :leapfrog, metric = :diagonal)
No-U-Turn Sampler (NUTS) sampler.
# Fields
$(FIELDS)
# Usage:
```julia
NUTS(δ=0.65) # Use target accept ratio 0.65.
```
"""
struct NUTS{T<:Real,I<:Union{Symbol,AbstractIntegrator},M<:Union{Symbol,AbstractMetric}} <:
AbstractHMCSampler
Expand Down Expand Up @@ -113,12 +107,6 @@ Hamiltonian Monte Carlo sampler with static trajectory.
# Fields
$(FIELDS)
# Usage:
```julia
HMC(10, integrator = Leapfrog(0.05), metric = :diagonal)
```
"""
struct HMC{I<:Union{Symbol,AbstractIntegrator},M<:Union{Symbol,AbstractMetric}} <:
AbstractHMCSampler
Expand All @@ -140,19 +128,15 @@ sampler_eltype(sampler::HMC) = determine_sampler_eltype(sampler.metric, sampler.
### HMCDA ###
#############
"""
HMCDA(δ::Real, λ::Real; ϵ::Real=0, integrator = :leapfrog, metric = :diagonal)
HMCDA(δ::Real, λ::Real, integrator = :leapfrog, metric = :diagonal)
Hamiltonian Monte Carlo sampler with Dual Averaging algorithm.
# Fields
$(FIELDS)
# Usage:
```julia
HMCDA(δ=0.65, λ=0.3)
```
# Notes
For more information, please view the following paper ([arXiv link](https://arxiv.org/abs/1111.4246)):
Expand Down

2 comments on commit 3b6351f

@yebai
Copy link
Member

@yebai yebai commented on 3b6351f Aug 12, 2023

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/89506

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.5.4 -m "<description of version>" 3b6351f71d58db78aecbc4fccac332c9464aa46d
git push origin v0.5.4

Please sign in to comment.