Skip to content

Commit 2d0292c

Browse files
committed
add some default implementations
1 parent 8d63557 commit 2d0292c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/AbstractMCMC.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,24 @@ struct MCMCSerial <: AbstractMCMCEnsemble end
8282

8383
"""
8484
getparams(model::AbstractModel, state)
85+
getparams(logdensity, state)
8586
getparams(state)
8687
8788
Retrieve the values of parameters from the sampler's `state` as a `Vector{<:Real}`.
8889
"""
8990
function getparams end
9091

92+
function getparams(logdensity, state)
93+
return getparams(_model(logdensity), state)
94+
end
95+
96+
function getparams(model::AbstractModel, state)
97+
return getparams(state)
98+
end
99+
91100
"""
92101
setparams!!(model::AbstractModel, state, params)
102+
setparams!!(logdensity, state, params)
93103
setparams!!(state, params)
94104
95105
Set the values of parameters in the sampler's `state` from a `Vector{<:Real}`.
@@ -103,9 +113,19 @@ and the vector representation of the parameter values.
103113
104114
Sometimes, to maintain the consistency of the log density and parameter values, a `model::AbstractModel`
105115
should be provided. This is useful for samplers that need to evaluate the log density at the new parameter values.
116+
If `model` is not an `AbstractMCMC.AbstractModel`, by default, it is assumed to be a log density function following
117+
the `LogDensityProblems.jl` interface, and will be wrapped with [`AbstractMCMC.LogDensityModel`](@ref).
106118
"""
107119
function setparams!! end
108120

121+
function setparams!!(logdensity, state, params)
122+
return setparams!!(_model(logdensity), state, params)
123+
end
124+
125+
function setparams!!(model::AbstractModel, state, params)
126+
return setparams!!(state, params)
127+
end
128+
109129
include("samplingstats.jl")
110130
include("logging.jl")
111131
include("interface.jl")

0 commit comments

Comments
 (0)