cross_validation_binomial_hurdle.stan 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. functions {
  2. #include "blocks/confusion_model_binomial_hurdle_fast.stan"
  3. }
  4. // TODO
  5. // use speech rates to set priors on truth_vocs
  6. data {
  7. int<lower=1> n_classes; // number of classes
  8. // speaker confusion data block
  9. int<lower=1> n_clips; // number of clips
  10. int<lower=1> n_groups; // number of groups
  11. int<lower=1> n_corpora;
  12. array [n_clips] int group;
  13. array [n_clips] int conf_corpus;
  14. array [n_clips,n_classes] int<lower=0> algo_total; // algo vocs attributed to specific speakers
  15. array [n_clips,n_classes] int<lower=0> truth_total;
  16. array [n_clips] real<lower=0> clip_duration;
  17. array [n_clips] real<lower=0> clip_age;
  18. int<lower=0> n_validation;
  19. // parallel processing
  20. int<lower=1> threads;
  21. }
  22. transformed data {
  23. array [n_groups,n_classes] int group_truth;
  24. for (i in 1:n_classes) {
  25. for (g in 1:n_groups) {
  26. group_truth[g,i] = 0;
  27. }
  28. for (c in 1:n_clips) {
  29. group_truth[group[c],i] += truth_total[c,i];
  30. }
  31. }
  32. }
  33. parameters {
  34. #include "blocks/confusion_model_parameters_binomial_hurdle.stan"
  35. }
  36. model {
  37. target += reduce_sum(
  38. confusion_model_lpdf, lambda, 1,
  39. n_classes, n_clips,
  40. algo_total, truth_total, group, clip_duration, clip_age,
  41. p
  42. );
  43. #include "blocks/confusion_model_priors_binomial_hurdle.stan"
  44. }
  45. generated quantities {
  46. array [n_groups,n_classes] int sim_vocs_given_lambda;
  47. array [n_groups,n_classes] int sim_vocs;
  48. for (g in 1:n_groups) {
  49. for (i in 1:n_classes) {
  50. array [n_classes] int n = binomial_rng(group_truth[g,:], lambda[g,:,i]);
  51. sim_vocs_given_lambda[g,i] = sum(n)+sum(binomial_rng(n, 1-p[:,i]));
  52. n = binomial_rng(group_truth[g,:], to_vector(beta_proportion_rng(mus[:,i], etas[:,i])));
  53. sim_vocs[g,i] = sum(n)+sum(binomial_rng(n, 1-p[:,i]));
  54. }
  55. }
  56. }