You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: developers/transforms/distributions/index.qmd
+8-6Lines changed: 8 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ histogram(samples, bins=50)
36
36
```
37
37
38
38
(Calling `Normal()` without any arguments, as we do here, gives us a normal distribution with mean 0 and standard deviation 1.)
39
-
If you want to know the probability of observing any of the samples, you can use `logpdf`:
39
+
If you want to know the log probability density of observing any of the samples, you can use `logpdf`:
40
40
41
41
```{julia}
42
42
println("sample: $(samples[1])")
@@ -53,6 +53,8 @@ so we could also have calculated this manually using:
53
53
log(1 / sqrt(2π) * exp(-samples[1]^2 / 2))
54
54
```
55
55
56
+
(or more efficiently, `-(samples[1]^2 + log2π) / 2`, where `log2π` is from the [IrrationalConstants.jl package](https://github.com/JuliaMath/IrrationalConstants.jl)).
57
+
56
58
## Sampling from a transformed distribution
57
59
58
60
Say that $x$ is distributed according to `Normal()`, and we want to draw samples of $y = \exp(x)$.
@@ -115,7 +117,7 @@ If we think about the normal distribution as a continuous curve, what the probab
115
117
116
118
$$\int_a^b p(x) \, \mathrm{d}x.$$
117
119
118
-
For example, if $(a, b) = (-\infty, \infty)$, then the probability of drawing a sample from the entire distribution is 1.
120
+
For example, if $(a, b) = (-\infty, \infty)$, then the probability of drawing a sample between $a$ and $b$ is 1.
119
121
120
122
Let's say that the probability density function of the log-normal distribution is $q(y)$.
121
123
Then, the area under the curve between the two points $\exp(a)$ and $\exp(b)$ is:
The same process can be applied to _any_ kind of transformation.
168
+
The same process can be applied to any kind of (invertible) transformation.
167
169
If we have some transformation from $x$ to $y$, and the probability density functions of $x$ and $y$ are $p(x)$ and $q(y)$ respectively, then we have a general formula that:
0 commit comments