bnp

Some older Bayesian nonparametrics research.
Log | Files | Refs | README | LICENSE

commit 90dae1fc7fc6718415b0d0238e7cd7c0c567d13b
parent c975daccadd9549baf4b693e55893c568899c468
Author: Jared Tobin <jared@jtobin.ca>
Date:   Tue, 23 Feb 2016 10:05:06 +1300

Add mixture model simulations.

Diffstat:
Mfinite-gaussian-mixture/src/fmm_multivariate_generative.r | 5-----
Afinite-gaussian-mixture/src/simulation.r | 18++++++++++++++++++
Afinite-gaussian-mixture/src/simulation_multivariate.r | 18++++++++++++++++++
3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/finite-gaussian-mixture/src/fmm_multivariate_generative.r b/finite-gaussian-mixture/src/fmm_multivariate_generative.r @@ -38,8 +38,3 @@ safe_rmvnorm = function(c, m, s) { if (c <= 0) return(numeric(0)) else rmvnorm(c, m, solve(s)) } - -previs = function(d) { - for (j in seq_along(d)) { d[[j]]$cluster = j } - do.call(rbind, d) - } diff --git a/finite-gaussian-mixture/src/simulation.r b/finite-gaussian-mixture/src/simulation.r @@ -0,0 +1,18 @@ +set.seed(42) + +require(ggplot2) +require(reshape2) + +source('fmm_generative.r') + +config = list( + k = 4 + , n = 10000 + ) + +d = model(config$k, config$n) +melted = melt(d) + +p = ggplot(melted, aes(value, colour = factor(L1), fill = factor(L1))) + + geom_density(alpha = 0.5) + diff --git a/finite-gaussian-mixture/src/simulation_multivariate.r b/finite-gaussian-mixture/src/simulation_multivariate.r @@ -0,0 +1,18 @@ +set.seed(42) + +require(ggplot2) +require(reshape2) + +source('fmm_multivariate_generative.r') + +config = list( + m = 2 + , k = 4 + , n = 10000 + ) + +d = model(config$m, config$k, config$n) +melted = melt(d, id.vars = c('x', 'y')) + +p = ggplot(melted, aes(x, y, colour = factor(L1))) + geom_point(alpha = 0.2) +