commit 66a9a5706a992e5bf0e8e0579d56cdaf143f883d
parent e636ba1ac2f0c1b5bdbc1239ec88f0997a12fe4b
Author: Jared Tobin <jared@jtobin.ca>
Date: Sun, 21 Feb 2016 13:12:26 +1300
Add CRP simulation.
Diffstat:
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/chinese-restaurant-process/src/simulation_crp.r b/chinese-restaurant-process/src/simulation_crp.r
@@ -0,0 +1,25 @@
+require(dplyr)
+require(ggplot2)
+require(reshape2)
+
+source('crp.r')
+
+design = expand.grid(epochs = 100, n = 1000, a = c(1, 10, 100))
+
+simulate = function(epochs, n, a) replicate(epochs, list(crp(n, a)))
+
+experiment = apply(
+ design
+ , MARGIN = 1
+ , function(row) { simulate(row[1], row[2], row[3]) }
+ )
+
+results = melt(experiment, id.vars = 'table')
+by_concentration = group_by(results, table = table, settings = factor(L1))
+summarised = summarise(by_concentration, customers = mean(value))
+
+log_log_plot =
+ ggplot(summarised, aes(table, customers, fill = settings, colour = settings)) +
+ geom_point(alpha = 0.8) +
+ scale_x_log10() + scale_y_log10()
+