diff --git a/previews/PR106/.documenter-siteinfo.json b/previews/PR106/.documenter-siteinfo.json index eac6936..50c6329 100644 --- a/previews/PR106/.documenter-siteinfo.json +++ b/previews/PR106/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.11.2","generation_timestamp":"2024-12-06T14:28:25","documenter_version":"1.8.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.11.2","generation_timestamp":"2024-12-06T14:28:42","documenter_version":"1.8.0"}} \ No newline at end of file diff --git a/previews/PR106/api/index.html b/previews/PR106/api/index.html index b6a7b55..aee78b3 100644 --- a/previews/PR106/api/index.html +++ b/previews/PR106/api/index.html @@ -2,8 +2,8 @@ AdvancedMH.jl · AdvancedMH

AdvancedMH.jl

Documentation for AdvancedMH.jl

Structs

AdvancedMH.MetropolisHastingsType
MetropolisHastings{D}

MetropolisHastings has one field, proposal. proposal is a Proposal, NamedTuple of Proposal, or Array{Proposal} in the shape of your data. For example, if you wanted the sampler to return a NamedTuple with shape

x = (a = 1.0, b=3.8)

The proposal would be

proposal = (a=StaticProposal(Normal(0,1)), b=StaticProposal(Normal(0,1)))

Other allowed proposals are

p1 = StaticProposal(Normal(0,1))
 p2 = StaticProposal([Normal(0,1), InverseGamma(2,3)])
 p3 = StaticProposal((a=Normal(0,1), b=InverseGamma(2,3)))
-p4 = StaticProposal((x=1.0) -> Normal(x, 1))

The sampler is constructed using

spl = MetropolisHastings(proposal)

When using MetropolisHastings with the function sample, the following keyword arguments are allowed:

  • initial_params defines the initial parameterization for your model. If

none is given, the initial parameters will be drawn from the sampler's proposals.

  • param_names is a vector of strings to be assigned to parameters. This is only

used if chain_type=Chains.

  • chain_type is the type of chain you would like returned to you. Supported

types are chain_type=Chains if MCMCChains is imported, or chain_type=StructArray if StructArrays is imported.

source

Functions

AdvancedMH.DensityModelType
DensityModel{F} <: AbstractModel

DensityModel wraps around a self-contained log-liklihood function logdensity.

Example:

l(x) = logpdf(Normal(), x)
-DensityModel(l)
source

Samplers

AdvancedMH.RobustAdaptiveMetropolis.RAMType
RAM

Robust Adaptive Metropolis-Hastings (RAM).

This is a simple implementation of the RAM algorithm described in [VIH12].

Fields

  • α: target acceptance rate. Default: 0.234.

  • γ: negative exponent of the adaptation decay rate. Default: 0.6.

  • S: initial lower-triangular Cholesky factor. Default: nothing.

  • eigenvalue_lower_bound: lower bound on eigenvalues of the adapted Cholesky factor. Default: 0.0.

  • eigenvalue_upper_bound: upper bound on eigenvalues of the adapted Cholesky factor. Default: Inf.

Examples

The following demonstrates how to implement a simple Gaussian model and sample from it using the RAM algorithm.

julia> using AdvancedMH, Random, Distributions, MCMCChains, LogDensityProblems, LinearAlgebra
+p4 = StaticProposal((x=1.0) -> Normal(x, 1))

The sampler is constructed using

spl = MetropolisHastings(proposal)

When using MetropolisHastings with the function sample, the following keyword arguments are allowed:

  • initial_params defines the initial parameterization for your model. If

none is given, the initial parameters will be drawn from the sampler's proposals.

  • param_names is a vector of strings to be assigned to parameters. This is only

used if chain_type=Chains.

  • chain_type is the type of chain you would like returned to you. Supported

types are chain_type=Chains if MCMCChains is imported, or chain_type=StructArray if StructArrays is imported.

source

Functions

AdvancedMH.DensityModelType
DensityModel{F} <: AbstractModel

DensityModel wraps around a self-contained log-liklihood function logdensity.

Example:

l(x) = logpdf(Normal(), x)
+DensityModel(l)
source

Samplers

AdvancedMH.RobustAdaptiveMetropolis.RAMType
RAM

Robust Adaptive Metropolis-Hastings (RAM).

This is a simple implementation of the RAM algorithm described in [VIH12].

Fields

  • α: target acceptance rate. Default: 0.234.

  • γ: negative exponent of the adaptation decay rate. Default: 0.6.

  • S: initial lower-triangular Cholesky factor. Default: nothing.

  • eigenvalue_lower_bound: lower bound on eigenvalues of the adapted Cholesky factor. Default: 0.0.

  • eigenvalue_upper_bound: upper bound on eigenvalues of the adapted Cholesky factor. Default: Inf.

Examples

The following demonstrates how to implement a simple Gaussian model and sample from it using the RAM algorithm.

julia> using AdvancedMH, Random, Distributions, MCMCChains, LogDensityProblems, LinearAlgebra
 
 julia> # Define a Gaussian with zero mean and some covariance.
        struct Gaussian{A}
@@ -38,4 +38,4 @@
        chain = sample(model, RAM(), 10_000; chain_type=Chains, num_warmup, progress=false, initial_params=zeros(2));
 
 julia> norm(cov(Array(chain)) - [1.0 0.5; 0.5 1.0]) < 0.2
-true

It's also possible to restrict the eigenvalues to avoid either too small or too large values. See p. 13 in [VIH12].

``jldoctest ram-gaussian julia> chain = sample( model, RAM(eigenvaluelowerbound=0.1, eigenvalueupperbound=2.0), 10000; chaintype=Chains, numwarmup, progress=false, initialparams=zeros(2) );

julia> norm(cov(Array(chain)) - [1.0 0.5; 0.5 1.0]) < 0.2 true ````

References

source
  • VIH12Vihola (2012) Robust adaptive Metropolis algorithm with coerced acceptance rate, Statistics and computing.
+true

It's also possible to restrict the eigenvalues to avoid either too small or too large values. See p. 13 in [VIH12].

``jldoctest ram-gaussian julia> chain = sample( model, RAM(eigenvaluelowerbound=0.1, eigenvalueupperbound=2.0), 10000; chaintype=Chains, numwarmup, progress=false, initialparams=zeros(2) );

julia> norm(cov(Array(chain)) - [1.0 0.5; 0.5 1.0]) < 0.2 true ````

References

source