Skip to content

Commit 099167f

Browse files
committed
dust off docs
1 parent f77e9c0 commit 099167f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/src/index.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ which is added to the log likelihood to obtain the log posterior.
4646

4747
It is useful to define a *callable* that implements this, taking some vector `x` as an input and calculating the summary statistics, then, when called with a `NamedTuple` containing the parameters, evaluating to the log posterior.
4848

49-
```@example 1
49+
```@setup A
50+
using LogDensityProblems
51+
```
52+
53+
```@example A
5054
using Random; Random.seed!(1) # hide
5155
using Statistics
5256
@@ -76,7 +80,7 @@ nothing # hide
7680

7781
Let's try out the posterior calculation:
7882

79-
```@repl 1
83+
```@repl A
8084
problem((μ = 0.0, σ = 1.0))
8185
```
8286

@@ -90,13 +94,13 @@ In our example, we require ``\sigma > 0``, otherwise the problem is meaningless.
9094
!!! note
9195
Since version 1.0, TransformedLogDensity has been moved to the package TransformedLogDensities.
9296

93-
```@repl 1
97+
```@repl A
9498
using LogDensityProblems, TransformVariables, TransformedLogDensities
9599
ℓ = TransformedLogDensity(as((μ = asℝ, σ = asℝ₊)), problem)
96100
```
97101

98102
Then we can query the dimension of this problem, and evaluate the log density:
99-
```@repl 1
103+
```@repl A
100104
LogDensityProblems.dimension(ℓ)
101105
LogDensityProblems.logdensity(ℓ, zeros(2))
102106
```
@@ -108,7 +112,7 @@ LogDensityProblems.logdensity(ℓ, zeros(2))
108112

109113
If you prefer to implement the transformation yourself, you just have to define the following three methods for your problem: declare that it can evaluate log densities (but not their gradient, hence the `0` order), allow the dimension of the problem to be queried, and then finally code the density calculation with the transformation. (Note that using `TransformedLogDensities.TransformedLogDensity` takes care of all of these for you, as shown above).
110114

111-
```@example 1
115+
```@example A
112116
function LogDensityProblems.capabilities(::Type{<:NormalPosterior})
113117
LogDensityProblems.LogDensityOrder{0}()
114118
end
@@ -123,7 +127,7 @@ end
123127
nothing # hide
124128
```
125129

126-
```@repl 1
130+
```@repl A
127131
LogDensityProblems.logdensity(problem, zeros(2))
128132
```
129133

@@ -134,7 +138,7 @@ Here we use the exponential function to transform from ``\mathbb{R}`` to the pos
134138
Using either definition, you can transform to another object which is capable of evaluating the *gradient*, using automatic differentiation. For this, you need the [LogDensityProblemsAD.jl](https://github.com/tpapp/LogDensityProblemsAD.jl) package.
135139

136140
Now observe that we can obtain gradients, too:
137-
```@repl 1
141+
```@repl A
138142
import ForwardDiff
139143
using LogDensityProblemsAD
140144
∇ℓ = ADgradient(:ForwardDiff, ℓ)

0 commit comments

Comments
 (0)