157
157
# Utility functions #
158
158
# ####################
159
159
160
+ # TODO (DPPL0.37/penelopeysm): This function should no longer be needed
161
+ # once InitContext is merged.
160
162
"""
161
163
set_namedtuple!(vi::VarInfo, nt::NamedTuple)
162
164
@@ -181,17 +183,15 @@ function set_namedtuple!(vi::DynamicPPL.VarInfoOrThreadSafeVarInfo, nt::NamedTup
181
183
end
182
184
end
183
185
184
- """
185
- MHLogDensityFunction
186
-
187
- A log density function for the MH sampler.
188
-
189
- This variant uses the `set_namedtuple!` function to update the `VarInfo`.
190
- """
191
- const MHLogDensityFunction{M<: Model ,S<: Sampler{<:MH} ,V<: AbstractVarInfo } =
192
- DynamicPPL. LogDensityFunction{M,V,AD} where {AD}
193
-
194
- function LogDensityProblems. logdensity (f:: MHLogDensityFunction , x:: NamedTuple )
186
+ # NOTE(penelopeysm): MH does not conform to the usual LogDensityProblems
187
+ # interface in that it gets evaluated with a NamedTuple. Hence we need this
188
+ # method just to deal with MH.
189
+ # TODO (DPPL0.37/penelopeysm): Check the extent to which this method is actually
190
+ # needed. If it's still needed, replace this with `init!!(f.model, f.varinfo,
191
+ # ParamsInit(x))`. Much less hacky than `set_namedtuple!` (hopefully...).
192
+ # In general, we should much prefer to either (1) conform to the
193
+ # LogDensityProblems interface or (2) use VarNames anyway.
194
+ function LogDensityProblems. logdensity (f:: LogDensityFunction , x:: NamedTuple )
195
195
vi = deepcopy (f. varinfo)
196
196
set_namedtuple! (vi, x)
197
197
vi_new = last (DynamicPPL. evaluate!! (f. model, vi, f. context))
0 commit comments