You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to use the MALA sampler with a DensityModel, I encountered a MethodError indicating ambiguity in the propose function. This error occurs when running the example code provided in the README.md of the AdvancedMH.jl package.
Steps to Reproduce
Install the required packages:
using Pkg
Pkg.add(["AdvancedMH", "Distributions", "MCMCChains", "ForwardDiff", "StructArrays", "LinearAlgebra"])
Run the following code:
using AdvancedMH
using Distributions
using MCMCChains
using ForwardDiff
using StructArrays
using LinearAlgebra
# Generate a set of data from the posterior we want to estimate.
data =rand(Normal(0, 1), 30)
# Define the components of a basic model.insupport(θ) = θ[2] >=0dist(θ) =Normal(θ[1], θ[2])
density(θ) =insupport(θ) ?sum(logpdf.(dist(θ), data)) :-Inf# Construct a DensityModel.
model =DensityModel(density)
# Set up the sampler with a multivariate Gaussian proposal.
σ² =0.01
spl =MALA(x ->MvNormal((σ² /2) .* x, σ² * I))
# Sample from the posterior.
chain =sample(model, spl, 100000; initial_params=ones(2), chain_type=StructArray, param_names=["μ", "σ"])
This code is taken directly from the README.md of the AdvancedMH.jl package. It seems that there might be an incompatibility between the current implementations of propose for MALA and DensityModel.
I also tried initializing the sampler with spl = MALA(MvNormal(2, sqrt(σ²))) or spl = MALA(σ²) instead of spl = MALA(x -> MvNormal((σ² / 2) .* x, σ² * I)), but this resulted in the same error.
Possible Solution
As suggested in the error message, defining a method for propose(::Random.AbstractRNG, ::MALA, ::Union{AbstractMCMC.LogDensityModel, DensityModel}) might resolve this ambiguity.
I would greatly appreciate any assistance in resolving this issue or guidance on how to properly use the MALA sampler with a DensityModel. Thank you for your time and effort in maintaining this package.
The text was updated successfully, but these errors were encountered:
Hm, this seems to be fixed in AdvancedMH 0.8.2, you have AdvancedMH 0.7.4. Can you try updating? If that doesn't work, we may have some dependency issues to resolve.
Description
When trying to use the MALA sampler with a DensityModel, I encountered a MethodError indicating ambiguity in the
propose
function. This error occurs when running the example code provided in the README.md of the AdvancedMH.jl package.Steps to Reproduce
Install the required packages:
Run the following code:
Error Message
Environment Information
v"1.10.4"
v0.7.4
v0.25.109
v6.0.6
v0.10.36
v0.6.18
Additional Context
This code is taken directly from the README.md of the AdvancedMH.jl package. It seems that there might be an incompatibility between the current implementations of
propose
forMALA
andDensityModel
.I also tried initializing the sampler with
spl = MALA(MvNormal(2, sqrt(σ²)))
orspl = MALA(σ²)
instead ofspl = MALA(x -> MvNormal((σ² / 2) .* x, σ² * I))
, but this resulted in the same error.Possible Solution
As suggested in the error message, defining a method for
propose(::Random.AbstractRNG, ::MALA, ::Union{AbstractMCMC.LogDensityModel, DensityModel})
might resolve this ambiguity.I would greatly appreciate any assistance in resolving this issue or guidance on how to properly use the MALA sampler with a DensityModel. Thank you for your time and effort in maintaining this package.
The text was updated successfully, but these errors were encountered: