bnp

Some older Bayesian nonparametrics research.
git clone git://git.jtobin.io/bnp.git
Log | Files | Refs | README | LICENSE

crf.r (564B)


      1 BNP_DIR = "/Users/jtobin/projects/bnp"
      2 CRP_SRC = paste(BNP_DIR, "chinese-restaurant-process/src/crp.r", sep = "/")
      3 
      4 require(dplyr)
      5 source(CRP_SRC)
      6 
      7 frequencies = function(restaurant) {
      8   summarised =
      9     restaurant %>%
     10     group_by(table) %>%
     11     summarise(n = sum(customers)) %>%
     12     mutate(freq = n / sum(n))
     13   summarised$freq
     14   }
     15 
     16 # FIXME (jtobin): this is not correct
     17 crf = function(n, a, a1) {
     18   g0 = frequencies(crp(n, a))
     19   h0 = function() { sample(g0, size = 1) }
     20   g1 = frequencies(crp(n, a1))
     21   g2 = frequencies(crp(n, a1))
     22   list(g1 * g0, g2 * g0)
     23   }
     24