bnp

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

commit 450b9cf54c378aec8688c6f1665e629796bfefb0
parent 1c9025686049bbd77c9664733c00ffc71a5a8a7d
Author: Jared Tobin <jared@jtobin.ca>
Date:   Fri, 11 Mar 2016 14:44:18 +1300

Add multivariate conditional simulation code.

Diffstat:
Mfinite-gaussian-mixture/src/fmm_multivariate_conditional.r | 36++++--------------------------------
Afinite-gaussian-mixture/src/simulation_multivariate_conditional.r | 38++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 32 deletions(-)

diff --git a/finite-gaussian-mixture/src/fmm_multivariate_conditional.r b/finite-gaussian-mixture/src/fmm_multivariate_conditional.r @@ -1,39 +1,9 @@ -# FIXME code can be improved via mapply(., simplify = F) require(dplyr) require(gtools) require(mvtnorm) -require(reshape2) # FIXME move to sim module source('fmm_multivariate_generative.r') -# FIXME (jtobin): move to simulation module -set.seed(9909) - -# FIXME (jtobin): move to simulation module -dimension = 2 - -# FIXME (jtobin): move to simulation module -config = list( - k = 3 - , m = dimension - , a = 1 - , l = rep(0, dimension) - , r = diag(0.05, dimension) - , b = 2 - , w = diag(1, dimension) - , n = 1000 - ) - -# FIXME (jtobin): move to simulation module -origin = list( - p = mixing_model(config$k, config$a) - , m = location_model(config$k, config$l, config$r) - , s = precision_model(config$k, config$b, config$w) - ) - -# FIXME (jtobin): move to simulation module -d = melt(model(config$m, config$k, config$n), id.vars = c('x', 'y')) - conditional_mixing_model = function(y, k, z, a) { labelled = cbind(y, L1 = z) counts = summarise(group_by(labelled, L1), count = n()) @@ -124,6 +94,7 @@ inverse_model = function(n, k, y, a, l, r, b, w) { p1 = conditional_mixing_model(y, k, z, a) m1 = conditional_location_model(y, z, s0, l, r) s1 = conditional_precision_model(y, z, m1, b, w) + # FIXME (jtobin): log scores # l = lmodel(y, z, p1, m1, s1) list(p = p1, m = m1, s = s1, z = z) # l = l) } @@ -143,10 +114,11 @@ inverse_model = function(n, k, y, a, l, r, b, w) { acc$p = rbind(acc$p, params$p) acc$m = mapply(rbind, acc$m, params$m, SIMPLIFY = F) - # NOTE (jtobin): not logging intermediate covariances - # might be desirable to log some reduced ellipse dims tho + # FIXME (jtobin): not logging intermediate covariances + # might be desirable to log some reduced ellipse dims acc$s = params$s acc$z = rbind(acc$z, params$z) + # FIXME (jtobin): log scores # acc$l = c(acc$l, params$l) } acc diff --git a/finite-gaussian-mixture/src/simulation_multivariate_conditional.r b/finite-gaussian-mixture/src/simulation_multivariate_conditional.r @@ -0,0 +1,38 @@ +set.seed(990909) + +require(ggplot2) +require(gridExtra) +require(reshape2) + +source('fmm_multivariate_conditional.r') + +dimension = 2 + +config = list( + k = 3 + , m = dimension + , a = 1 + , l = rep(0, dimension) + , r = diag(0.05, dimension) + , b = 2 + , w = diag(1, dimension) + , n = 1000 + ) + +origin = list( + p = mixing_model(config$k, config$a) + , m = location_model(config$k, config$l, config$r) + , s = precision_model(config$k, config$b, config$w) + ) + +d = melt(model(config$m, config$k, config$n), id.vars = c('x', 'y')) + +set.seed(990909) + +params = inverse_model( + config$n, config$k, d[, c('x', 'y')] + , config$a + , config$l, config$r + , config$b, config$w + ) +