@@ -4,6 +4,10 @@ import DifferentiationInterface as DI
44 LogDensityFunction
55
66A callable representing a log density function of a `model`.
7+ `DynamicPPL.LogDensityFunction` implements the LogDensityProblems.jl interface,
8+ but only to 0th-order, i.e. it is only possible to calculate the log density,
9+ and not its gradient. If you need to calculate the gradient as well, you have
10+ to construct a [`DynamicPPL.LogDensityFunctionWithGrad`](@ref) object.
711
812# Fields
913$(FIELDS)
@@ -55,16 +59,6 @@ struct LogDensityFunction{V,M,C}
5559 context:: C
5660end
5761
58- # TODO : Deprecate.
59- function LogDensityFunction (
60- varinfo:: AbstractVarInfo ,
61- model:: Model ,
62- sampler:: AbstractSampler ,
63- context:: AbstractContext ,
64- )
65- return LogDensityFunction (varinfo, model, SamplingContext (sampler, context))
66- end
67-
6862function LogDensityFunction (
6963 model:: Model ,
7064 varinfo:: AbstractVarInfo = VarInfo (model),
@@ -94,11 +88,6 @@ function setmodel(f::DynamicPPL.LogDensityFunction, model::DynamicPPL.Model)
9488 return Accessors. @set f. model = model
9589end
9690
97- # HACK: heavy usage of `AbstractSampler` for, well, _everything_, is being phased out. In the mean time
98- # we need to define these annoying methods to ensure that we stay compatible with everything.
99- getsampler (f:: LogDensityFunction ) = getsampler (getcontext (f))
100- hassampler (f:: LogDensityFunction ) = hassampler (getcontext (f))
101-
10291"""
10392 getparams(f::LogDensityFunction)
10493
122111LogDensityProblems. dimension (f:: LogDensityFunction ) = length (getparams (f))
123112
124113# LogDensityProblems interface: gradient (1st order)
125- struct LogDensityFunctionWithGrad{V,M,C,TAD}
114+ """
115+ LogDensityFunctionWithGrad(ldf::DynamicPPL.LogDensityFunction, adtype::ADTypes.AbstractADType)
116+
117+ A callable representing a log density function of a `model`.
118+ `DynamicPPL.LogDensityFunctionWithGrad` implements the LogDensityProblems.jl
119+ interface to 1st-order, meaning that you can both calculate the log density
120+ using
121+
122+ LogDensityProblems.logdensity(f, x)
123+
124+ and its gradient using
125+
126+ LogDensityProblems.logdensity_and_gradient(f, x)
127+
128+ where `f` is a `LogDensityFunctionWithGrad` object and `x` is a vector of parameters.
129+
130+ # Fields
131+ $(FIELDS)
132+ """
133+ struct LogDensityFunctionWithGrad{V,M,C,TAD<: ADTypes.AbstractADType }
126134 ldf:: LogDensityFunction{V,M,C}
127135 adtype:: TAD
128136 prep:: DI.GradientPrep
0 commit comments