|
2 | 2 |
|
3 | 3 | ## 0.35.0
|
4 | 4 |
|
5 |
| -**Breaking** |
| 5 | +**Breaking changes** |
6 | 6 |
|
7 | 7 | ### `.~` right hand side must be a univariate distribution
|
8 | 8 |
|
@@ -119,14 +119,50 @@ This release removes the feature of `VarInfo` where it kept track of which varia
|
119 | 119 |
|
120 | 120 | This change also affects sampling in Turing.jl.
|
121 | 121 |
|
| 122 | +### `LogDensityFunction` argument order |
| 123 | +
|
| 124 | + - The method `LogDensityFunction(varinfo, model, context)` has been removed. |
| 125 | + The only accepted order is `LogDensityFunction(model, varinfo, context; adtype)`. |
| 126 | + (For an explanation of `adtype`, see below.) |
| 127 | + The varinfo and context arguments are both still optional. |
| 128 | +
|
122 | 129 | **Other changes**
|
123 | 130 |
|
| 131 | +### `LogDensityProblems` interface |
| 132 | +
|
124 | 133 | LogDensityProblemsAD is now removed as a dependency.
|
125 | 134 | Instead of constructing a `LogDensityProblemAD.ADgradient` object, we now directly use `DifferentiationInterface` to calculate the gradient of the log density with respect to model parameters.
|
126 | 135 |
|
127 |
| -In practice, this means that if you want to calculate the gradient for a model, you can do: |
| 136 | +Note that if you wish, you can still construct an `ADgradient` out of a `LogDensityFunction` object (there is nothing preventing this). |
| 137 | +
|
| 138 | +However, in this version, `LogDensityFunction` now takes an extra AD type argument. |
| 139 | +If this argument is not provided, the behaviour is exactly the same as before, i.e. you can calculate `logdensity` but not its gradient. |
| 140 | +However, if you do pass an AD type, that will allow you to calculate the gradient as well. |
| 141 | +You may thus find that it is easier to instead do this: |
| 142 | +
|
| 143 | +```julia |
| 144 | +@model f() = ... |
| 145 | +
|
| 146 | +ldf = LogDensityFunction(f(); adtype=AutoForwardDiff()) |
| 147 | +``` |
| 148 | +
|
| 149 | +This will return an object which satisfies the `LogDensityProblems` interface to first-order, i.e. you can now directly call both |
| 150 | +
|
| 151 | +``` |
| 152 | +LogDensityProblems.logdensity(ldf, params) |
| 153 | +LogDensityProblems.logdensity_and_gradient(ldf, params) |
| 154 | +``` |
| 155 | +
|
| 156 | +without having to construct a separate `ADgradient` object. |
128 | 157 |
|
129 |
| -TODO(penelopeysm): Finish this |
| 158 | +If you prefer, you can also use `setadtype` to tack on the AD type afterwards: |
| 159 | +
|
| 160 | +```julia |
| 161 | +@model f() = ... |
| 162 | +
|
| 163 | +ldf = LogDensityFunction(f()) # by default, no adtype set |
| 164 | +ldf_with_ad = setadtype(ldf, AutoForwardDiff()) |
| 165 | +``` |
130 | 166 |
|
131 | 167 | ## 0.34.2
|
132 | 168 |
|
|
0 commit comments