Skip to content

Commit 1a2decf

Browse files
committed
Make GMM tutorial a bit less demanding
1 parent 66aa564 commit 1a2decf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tutorials/gaussian-mixture-models/index.qmd

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ Random.seed!(3)
3838
3939
# Define Gaussian mixture model.
4040
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)
4343
4444
# We draw the data points.
45-
N = 60
45+
N = 30
4646
x = rand(mixturemodel, N);
4747
```
4848

@@ -112,7 +112,7 @@ model = gaussian_mixture_model(x);
112112
```
113113

114114
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$).
116116
We generate multiple chains in parallel using multi-threading.
117117

118118
```{julia}
@@ -145,7 +145,7 @@ let
145145
# μ[1] and μ[2] can switch places, so we sort the values first.
146146
chain = Array(chains[:, ["μ[1]", "μ[2]"], i])
147147
μ_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!"
149149
end
150150
end
151151
```
@@ -212,7 +212,7 @@ let
212212
# μ[1] and μ[2] can no longer switch places. Check that they've found the mean
213213
chain = Array(chains[:, ["μ[1]", "μ[2]"], i])
214214
μ_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!"
216216
end
217217
end
218218
```
@@ -350,7 +350,7 @@ let
350350
# μ[1] and μ[2] can no longer switch places. Check that they've found the mean
351351
chain = Array(chains[:, ["μ[1]", "μ[2]"], i])
352352
μ_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!"
354354
end
355355
end
356356
```

0 commit comments

Comments
 (0)