commit a71a0f1d52f7500c859bc9d31247086bef715302
parent 804f7c2aac8401a4e1fb5ec153a025be49687a14
Author: Jared Tobin <jared@jtobin.ca>
Date: Wed, 16 Mar 2016 21:02:35 +1300
Misc work.
Diffstat:
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/finite-gaussian-mixture/src/fmm_multivariate_conditional_collapsed.r b/finite-gaussian-mixture/src/fmm_multivariate_conditional_collapsed.r
@@ -19,7 +19,6 @@ cluster_statistics = function(cluster, l, b, w) {
)
}
-# FIXME (jtobin): more efficient to cache sufficient statistics in gibbs loop
conditional_label_model = function(y, k, z, a, l, r, b, w) {
cluster_labels = seq(k)
rows = sample(seq(nrow(y)))
@@ -64,10 +63,9 @@ conditional_label_model = function(y, k, z, a, l, r, b, w) {
probs = scores * weight / sum(scores * weight)
new_label = sample(cluster_labels, size = 1, prob = probs)
- # MUTATION
- z[i] <- new_label
+ z[i] <<- new_label
new_stats = cluster_statistics(y[which(z == new_label),], l, b, w)
- sufficient_statistics[[new_label]] <- new_stats
+ sufficient_statistics[[new_label]] <<- new_stats
new_label
}
@@ -88,3 +86,5 @@ inverse_model = function(n, k, y, a, l, r, b, w) {
acc
}
+
+# FIXME something fucked up somewhere
diff --git a/finite-gaussian-mixture/src/sim_fmm_2d_conditional_collapsed.r b/finite-gaussian-mixture/src/sim_fmm_2d_conditional_collapsed.r
@@ -14,19 +14,19 @@ config = list(
, r = diag(0.05, dimension)
, b = 2
, w = diag(1, dimension)
- , n = 200
+ , n = 100
)
set.seed(222)
d = list(
- t(replicate(250, rnorm(2, c(5, 5))))
- , t(replicate(250, rnorm(2, c(-5, -5))))
- , t(replicate(500, rnorm(2))))
+ t(replicate(100, rnorm(2, c(5, 5))))
+ , t(replicate(100, rnorm(2, c(-5, -5))))
+ , t(replicate(200, rnorm(2))))
dn = lapply(d, function(j) { data.frame(x = j[,1], y = j[,2]) })
m = melt(dn, id.vars = c('x', 'y'))
-set.seed(990909)
+set.seed(222) #990909)
params = inverse_model(
config$n, config$k, m[, c('x', 'y')]