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

Fixes for constructor docstrings #347

Merged
merged 4 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
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
Loading