bnp

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

simulation_crp.r (867B)


      1 require(dplyr)
      2 require(ggplot2)
      3 require(reshape2)
      4 
      5 source('crp.r')
      6 
      7 design = expand.grid(epochs = 100, n = 1000, a = c(1, 10, 100))
      8 
      9 simulate = function(epochs, n, a) replicate(epochs, list(crp(n, a)))
     10 
     11 experiment = apply(
     12     design
     13   , MARGIN = 1
     14   , function(row) { simulate(row[1], row[2], row[3]) }
     15   )
     16 
     17 results          = melt(experiment, id.vars = 'table')
     18 by_concentration = group_by(results, table = table, settings = factor(L1))
     19 
     20 log_log_plot =
     21   ggplot(by_concentration, aes(table, value, fill = settings, colour = settings)) +
     22   geom_jitter(width = 0.5, height = 0.45, alpha = 0.2) +
     23   scale_x_log10() + scale_y_log10()
     24 
     25 summarised = summarise(by_concentration, customers = mean(value))
     26 
     27 mean_log_log_plot =
     28   ggplot(summarised, aes(table, customers, fill = settings, colour = settings)) +
     29   geom_point(alpha = 0.8) +
     30   scale_x_log10() + scale_y_log10()
     31