commit 2642db77d9ff7cb7cbabaaf4430f9b93824634a9
parent 8f77d72e1df13ab75965a3ed1d97c86ce9585278
Author: Jared Tobin <jared@jtobin.ca>
Date: Mon, 15 Feb 2016 21:31:34 +1300
Add Pitman-Yor.
Diffstat:
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/pitman-yor/src/pitman_yor.r b/pitman-yor/src/pitman_yor.r
@@ -0,0 +1,16 @@
+
+pitman_yor = function(n, a, b) {
+ bundle = rbeta(1, 1 - a, b + a)
+ for (j in seq(n)) {
+ bundle = snap(bundle, a, b, j + 1)
+ }
+ bundle
+ }
+
+snap = function(acc, a, b, k) {
+ v = rbeta(1, 1 - a, b + k * a)
+ p = v * (1 - sum(acc))
+ c(acc, p)
+ }
+
+