# generate data from a mixture model with five components # this gives us a sense of the model source("mixture-vb.R") d <- generate.data(1000, 5, c(0,0), 250) # here's a function to plot the data and its decomposition plot.mixture(d$locs, d$z, d$obs) # when we're analyzing data, we only see the observations # decomposing it is the goal of posterior inference plot.data(d$obs) # run variational inference res <- mixt.gauss.vb(d$obs, 5, c(0,0), 250, make.movie=T) # plot the inferred decomposition decomp <- inferred.decomp(res$var.mu, res$var.sigma, res$var.z) plot.mixture(decomp$locs, decomp$z, d$obs) # plot the inferred predictive distribution pred <- inferred.pred(res$var.mu, res$var.sigma, res$var.z) plot.pred.and.obs(pred, d$obs) # plot the trajectory of the inferred decomposition for (i in 1:length(res$movie)) { print(res$movie[[i]]); Sys.sleep(1); } # assess the affect of initialization res <- lapply(1:25, function (i) mixt.gauss.vb(d$obs, 5, c(0,0), 100, make.movie=F)) laply(res, function (x) x$elbo[length(x$elbo)])