commit 740a9c308b96fdc1f6a536064de2080467a69c60
parent 01fe12fa443c5d8a400bf05cdf7ad909f168766a
Author: Jared Tobin <jared@jtobin.ca>
Date: Sun, 14 Feb 2016 19:41:16 +1300
Some magrittring.
Diffstat:
2 files changed, 5 insertions(+), 11 deletions(-)
diff --git a/finite-gaussian-mixture/src/fmm_generative.r b/finite-gaussian-mixture/src/fmm_generative.r
@@ -1,6 +1,7 @@
set.seed(42)
require(gtools)
+require(magrittr)
mixing_model = function(k, a) drop(rdirichlet(1, (rep(a, k))))
label_model = function(n, p) drop(rmultinom(1, size = n, prob = p))
@@ -16,12 +17,9 @@ parameter_model = function(k, n) {
}
data_model = function(config) {
- sampler = function(y, m, s) rnorm(y, m, 1 / s) # FIXME this may not do what i expect
+ sampler = function(y, m, s) rnorm(y, m, 1 / s)
mapply(sampler, config[[1]], config[[2]], config[[3]])
}
-model = function(k, n) {
- config = parameter_model(k, n)
- data_model(config)
- }
+model = function(k, n) parameter_model(k, n) %>% data_model
diff --git a/finite-gaussian-mixture/src/fmm_multivariate_generative.r b/finite-gaussian-mixture/src/fmm_multivariate_generative.r
@@ -1,6 +1,7 @@
set.seed(42)
require(gtools)
+require(magrittr)
require(mvtnorm)
mixing_model = function(k, a) drop(rdirichlet(1, (rep(a, k))))
@@ -22,10 +23,7 @@ data_model = function(config) {
lapply(raw, frame)
}
-model = function(m, k, n) {
- config = parameter_model(m, k, n)
- data_model(config)
- }
+model = function(m, k, n) parameter_model(m, k, n) %>% data_model
# utilities
@@ -41,8 +39,6 @@ safe_rmvnorm = function(c, m, s) {
else rmvnorm(c, m, solve(s))
}
-# for vis, apply this and then
-# ggplot(foo, aes(x, y, colour = factor(cluster))) + geom_point(alpha = 0.2)
previs = function(d) {
for (j in seq_along(d)) { d[[j]]$cluster = j }
do.call(rbind, d)