Skip to content

Commit 1b1bad2

Browse files
committed
improve docs formatting
1 parent 59c80e2 commit 1b1bad2

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

src/modeling_library/mixture.jl

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ the corresponding argument is an i-dimensional array.
1717
1818
Example:
1919
20-
mixture_of_normals = HomogeneousMixture(normal, [0, 0])
20+
```julia
21+
mixture_of_normals = HomogeneousMixture(normal, [0, 0])
22+
```
2123
2224
The resulting distribution (e.g. `mixture_of_normals` above) can then be used like the built-in distribution values like `normal`.
2325
The distribution takes `n+1` arguments where `n` is the number of arguments taken by the base distribution.
@@ -28,24 +30,26 @@ If an argument to the base distribution is an `Array{T,N}` for some `N`, then th
2830
2931
Example:
3032
31-
mixture_of_normals = HomogeneousMixture(normal, [0, 0])
32-
mixture_of_mvnormals = HomogeneousMixture(mvnormal, [1, 2])
33-
34-
@gen function foo()
35-
# mixture of two normal distributions
36-
# with means -1.0 and 1.0
37-
# and standard deviations 0.1 and 10.0
38-
# the first normal distribution has weight 0.4; the second has weight 0.6
39-
x ~ mixture_of_normals([0.4, 0.6], [-1.0, 1.0], [0.1, 10.0])
40-
41-
# mixture of two multivariate normal distributions
42-
# with means: [0.0, 0.0] and [1.0, 1.0]
43-
# and covariance matrices: [1.0 0.0; 0.0 1.0] and [10.0 0.0; 0.0 10.0]
44-
# the first multivariate normal distribution has weight 0.4; the second has weight 0.6
45-
means = [0.0 1.0; 0.0 1.0] # or, cat([0.0, 0.0], [1.0, 1.0], dims=2)
46-
covs = cat([1.0 0.0; 0.0 1.0], [10.0 0.0; 0.0 10.0], dims=3)
47-
y ~ mixture_of_mvnormals([0.4, 0.6], means, covs)
48-
end
33+
```julia
34+
mixture_of_normals = HomogeneousMixture(normal, [0, 0])
35+
mixture_of_mvnormals = HomogeneousMixture(mvnormal, [1, 2])
36+
37+
@gen function foo()
38+
# mixture of two normal distributions
39+
# with means -1.0 and 1.0
40+
# and standard deviations 0.1 and 10.0
41+
# the first normal distribution has weight 0.4; the second has weight 0.6
42+
x ~ mixture_of_normals([0.4, 0.6], [-1.0, 1.0], [0.1, 10.0])
43+
44+
# mixture of two multivariate normal distributions
45+
# with means: [0.0, 0.0] and [1.0, 1.0]
46+
# and covariance matrices: [1.0 0.0; 0.0 1.0] and [10.0 0.0; 0.0 10.0]
47+
# the first multivariate normal distribution has weight 0.4; the second has weight 0.6
48+
means = [0.0 1.0; 0.0 1.0] # or, cat([0.0, 0.0], [1.0, 1.0], dims=2)
49+
covs = cat([1.0 0.0; 0.0 1.0], [10.0 0.0; 0.0 10.0], dims=3)
50+
y ~ mixture_of_mvnormals([0.4, 0.6], means, covs)
51+
end
52+
```
4953
"""
5054
struct HomogeneousMixture{T} <: Distribution{T}
5155
base_dist::Distribution{T}
@@ -137,21 +141,23 @@ The argument is the vector of base distributions, one for each mixture component
137141
Note that the base distributions must have the same output type.
138142
139143
Example:
140-
141-
uniform_beta_mixture = HeterogeneousMixture([uniform, beta])
144+
```julia
145+
uniform_beta_mixture = HeterogeneousMixture([uniform, beta])
146+
```
142147
143148
The resulting mixture distribution takes `n+1` arguments, where `n` is the sum of the number of arguments taken by each distribution in the list.
144149
The first argument to the mixture distribution is a vector of non-negative mixture weights, which must sum to 1.0.
145150
The remaining arguments are the arguments to each mixture component distribution, in order in which the distributions are passed into the constructor.
146151
147152
Example:
148-
149-
@gen function foo()
150-
# mixure of a uniform distribution on the interval [`lower`, `upper`]
151-
# and a beta distribution with alpha parameter `a` and beta parameter `b`
152-
# the uniform as weight 0.4 and the beta has weight 0.6
153-
x ~ uniform_beta_mixture([0.4, 0.6], lower, upper, a, b)
154-
end
153+
```julia
154+
@gen function foo()
155+
# mixure of a uniform distribution on the interval [`lower`, `upper`]
156+
# and a beta distribution with alpha parameter `a` and beta parameter `b`
157+
# the uniform as weight 0.4 and the beta has weight 0.6
158+
x ~ uniform_beta_mixture([0.4, 0.6], lower, upper, a, b)
159+
end
160+
```
155161
"""
156162
struct HeterogeneousMixture{T} <: Distribution{T}
157163
K::Int

0 commit comments

Comments
 (0)