bnp

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

commit d42d0b689baa0a50138e81d61f2382e478898c78
parent 457c5c5f07e1a5c9b8c5f33878cc46e4f6a71c34
Author: Jared Tobin <jared@jtobin.ca>
Date:   Wed, 24 Feb 2016 15:52:38 +1300

Add CRF skeleton.

Diffstat:
Achinese-restaurant-franchise/src/crf.r | 24++++++++++++++++++++++++
Mhierarchical-dirichlet-process/src/hdp.r | 1+
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/chinese-restaurant-franchise/src/crf.r b/chinese-restaurant-franchise/src/crf.r @@ -0,0 +1,24 @@ +BNP_DIR = "/Users/jtobin/projects/bnp" +CRP_SRC = paste(BNP_DIR, "chinese-restaurant-process/src/crp.r", sep = "/") + +require(dplyr) +source(CRP_SRC) + +frequencies = function(restaurant) { + summarised = + restaurant %>% + group_by(table) %>% + summarise(n = sum(customers)) %>% + mutate(freq = n / sum(n)) + summarised$freq + } + +# FIXME (jtobin): this is not correct +crf = function(n, a, a1) { + g0 = frequencies(crp(n, a)) + h0 = function() { sample(g0, size = 1) } + g1 = frequencies(crp(n, a1)) + g2 = frequencies(crp(n, a1)) + list(g1 * g0, g2 * g0) + } + diff --git a/hierarchical-dirichlet-process/src/hdp.r b/hierarchical-dirichlet-process/src/hdp.r @@ -3,6 +3,7 @@ DP_SRC = paste(BNP_DIR, "dirichlet-process/src/dp.r", sep = "/") source(DP_SRC) +# FIXME (jtobin): this may not be correct hdp = function(n, a, h, n1, n2, a1, a2) { g0 = dp(n, a, h) h0 = function() { sample(g0[[1]], size = 1) }