|
2 | 2 |
|
3 | 3 | ## 0.35.0
|
4 | 4 |
|
5 |
| -**Breaking** |
| 5 | +**Breaking changes** |
6 | 6 |
|
7 | 7 | ### Remove indexing by samplers
|
8 | 8 |
|
@@ -49,14 +49,50 @@ This release removes the feature of `VarInfo` where it kept track of which varia
|
49 | 49 |
|
50 | 50 | This change also affects sampling in Turing.jl.
|
51 | 51 |
|
| 52 | +### `LogDensityFunction` argument order |
| 53 | +
|
| 54 | + - The method `LogDensityFunction(varinfo, model, context)` has been removed. |
| 55 | + The only accepted order is `LogDensityFunction(model, varinfo, context; adtype)`. |
| 56 | + (For an explanation of `adtype`, see below.) |
| 57 | + The varinfo and context arguments are both still optional. |
| 58 | +
|
52 | 59 | **Other changes**
|
53 | 60 |
|
| 61 | +### `LogDensityProblems` interface |
| 62 | +
|
54 | 63 | LogDensityProblemsAD is now removed as a dependency.
|
55 | 64 | 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.
|
56 | 65 |
|
57 |
| -In practice, this means that if you want to calculate the gradient for a model, you can do: |
| 66 | +Note that if you wish, you can still construct an `ADgradient` out of a `LogDensityFunction` object (there is nothing preventing this). |
| 67 | +
|
| 68 | +However, in this version, `LogDensityFunction` now takes an extra AD type argument. |
| 69 | +If this argument is not provided, the behaviour is exactly the same as before, i.e. you can calculate `logdensity` but not its gradient. |
| 70 | +However, if you do pass an AD type, that will allow you to calculate the gradient as well. |
| 71 | +You may thus find that it is easier to instead do this: |
| 72 | +
|
| 73 | +```julia |
| 74 | +@model f() = ... |
| 75 | +
|
| 76 | +ldf = LogDensityFunction(f(); adtype=AutoForwardDiff()) |
| 77 | +``` |
| 78 | +
|
| 79 | +This will return an object which satisfies the `LogDensityProblems` interface to first-order, i.e. you can now directly call both |
| 80 | +
|
| 81 | +``` |
| 82 | +LogDensityProblems.logdensity(ldf, params) |
| 83 | +LogDensityProblems.logdensity_and_gradient(ldf, params) |
| 84 | +``` |
| 85 | +
|
| 86 | +without having to construct a separate `ADgradient` object. |
| 87 | +
|
| 88 | +If you prefer, you can also use `setadtype` to tack on the AD type afterwards: |
| 89 | +
|
| 90 | +```julia |
| 91 | +@model f() = ... |
58 | 92 |
|
59 |
| -TODO(penelopeysm): Finish this |
| 93 | +ldf = LogDensityFunction(f()) # by default, no adtype set |
| 94 | +ldf_with_ad = setadtype(ldf, AutoForwardDiff()) |
| 95 | +``` |
60 | 96 |
|
61 | 97 | ## 0.34.2
|
62 | 98 |
|
|
0 commit comments