@@ -4,6 +4,10 @@ import DifferentiationInterface as DI
4
4
LogDensityFunction
5
5
6
6
A 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.
7
11
8
12
# Fields
9
13
$(FIELDS)
@@ -55,16 +59,6 @@ struct LogDensityFunction{V,M,C}
55
59
context:: C
56
60
end
57
61
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
-
68
62
function LogDensityFunction (
69
63
model:: Model ,
70
64
varinfo:: AbstractVarInfo = VarInfo (model),
@@ -94,11 +88,6 @@ function setmodel(f::DynamicPPL.LogDensityFunction, model::DynamicPPL.Model)
94
88
return Accessors. @set f. model = model
95
89
end
96
90
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
-
102
91
"""
103
92
getparams(f::LogDensityFunction)
104
93
122
111
LogDensityProblems. dimension (f:: LogDensityFunction ) = length (getparams (f))
123
112
124
113
# 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 }
126
134
ldf:: LogDensityFunction{V,M,C}
127
135
adtype:: TAD
128
136
prep:: DI.GradientPrep
0 commit comments