bnp

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

commit 8f77d72e1df13ab75965a3ed1d97c86ce9585278
parent dce62753db135a1aa27dc4af62e59cd6f8d7555c
Author: Jared Tobin <jared@jtobin.ca>
Date:   Mon, 15 Feb 2016 15:16:02 +1300

Add stick breaking process.

Diffstat:
Astick-breaking-process/src/sbp.r | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/stick-breaking-process/src/sbp.r b/stick-breaking-process/src/sbp.r @@ -0,0 +1,17 @@ +sbp = function(n, a) { + bundle = list(0, numeric(0)) + for (j in seq(n)) { + bundle = snap(bundle[[1]], bundle[[2]], a) + } + bundle[[2]] + } + +snap = function(acc, bun, a) { + b = rbeta(1, 1, a) + stick = exp(log(b) + acc) + + nacc = log (1 - b) + acc + nbun = c(bun, stick) + list(nacc, nbun) + } +