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: tutorials/gaussian-mixture-models/index.qmd
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -38,11 +38,11 @@ Random.seed!(3)
38
38
39
39
# Define Gaussian mixture model.
40
40
w = [0.5, 0.5]
41
-
μ = [-3.5, 0.5]
42
-
mixturemodel = MixtureModel([MvNormal(Fill(μₖ, 2), I) for μₖ in μ], w)
41
+
μ = [-2.0, 2.0]
42
+
mixturemodel = MixtureModel([MvNormal(Fill(μₖ, 2), 0.2 * I) for μₖ in μ], w)
43
43
44
44
# We draw the data points.
45
-
N = 60
45
+
N = 30
46
46
x = rand(mixturemodel, N);
47
47
```
48
48
@@ -112,7 +112,7 @@ model = gaussian_mixture_model(x);
112
112
```
113
113
114
114
We run a MCMC simulation to obtain an approximation of the posterior distribution of the parameters $\mu$ and $w$ and assignments $k$.
115
-
We use a `Gibbs` sampler that combines a [particle Gibbs](https://www.stats.ox.ac.uk/%7Edoucet/andrieu_doucet_holenstein_PMCMC.pdf) sampler for the discrete parameters (assignments $k$) and a Hamiltonian Monte Carlo sampler for the continuous parameters ($\mu$ and $w$).
115
+
We use a `Gibbs` sampler that combines a [particle Gibbs](https://www.stats.ox.ac.uk/%8Edoucet/andrieu_doucet_holenstein_PMCMC.pdf) sampler for the discrete parameters (assignments $k$) and a Hamiltonian Monte Carlo sampler for the continuous parameters ($\mu$ and $w$).
116
116
We generate multiple chains in parallel using multi-threading.
117
117
118
118
```{julia}
@@ -145,7 +145,7 @@ let
145
145
# μ[1] and μ[2] can switch places, so we sort the values first.
146
146
chain = Array(chains[:, ["μ[1]", "μ[2]"], i])
147
147
μ_mean = vec(mean(chain; dims=1))
148
-
@assert isapprox(sort(μ_mean), μ; rtol=0.1) "Difference between estimated mean of μ ($(sort(μ_mean))) and data-generating μ ($μ) unexpectedly large!"
148
+
@assert isapprox(sort(μ_mean), μ; atol=0.5) "Difference between estimated mean of μ ($(sort(μ_mean))) and data-generating μ ($μ) unexpectedly large!"
149
149
end
150
150
end
151
151
```
@@ -212,7 +212,7 @@ let
212
212
# μ[1] and μ[2] can no longer switch places. Check that they've found the mean
213
213
chain = Array(chains[:, ["μ[1]", "μ[2]"], i])
214
214
μ_mean = vec(mean(chain; dims=1))
215
-
@assert isapprox(sort(μ_mean), μ; rtol=0.4) "Difference between estimated mean of μ ($(sort(μ_mean))) and data-generating μ ($μ) unexpectedly large!"
215
+
@assert isapprox(sort(μ_mean), μ; atol=0.5) "Difference between estimated mean of μ ($(sort(μ_mean))) and data-generating μ ($μ) unexpectedly large!"
216
216
end
217
217
end
218
218
```
@@ -350,7 +350,7 @@ let
350
350
# μ[1] and μ[2] can no longer switch places. Check that they've found the mean
351
351
chain = Array(chains[:, ["μ[1]", "μ[2]"], i])
352
352
μ_mean = vec(mean(chain; dims=1))
353
-
@assert isapprox(sort(μ_mean), μ; rtol=0.4) "Difference between estimated mean of μ ($(sort(μ_mean))) and data-generating μ ($μ) unexpectedly large!"
353
+
@assert isapprox(sort(μ_mean), μ; atol=0.5) "Difference between estimated mean of μ ($(sort(μ_mean))) and data-generating μ ($μ) unexpectedly large!"
0 commit comments