bnp

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

pitman_yor.r (255B)


      1 
      2 pitman_yor = function(n, a, b) {
      3   bundle = rbeta(1, 1 - a, b + a)
      4   for (j in seq(n)) {
      5     bundle = snap(bundle, a, b, j + 1)
      6   }
      7   bundle
      8   }
      9 
     10 snap = function(acc, a, b, k) {
     11   v = rbeta(1, 1 - a, b + k * a)
     12   p = v * (1 - sum(acc))
     13   c(acc, p)
     14   }
     15 
     16