dev_siblings_binomial_hurdle_fast.stan 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. functions {
  2. #include "blocks/confusion_model_binomial_hurdle_fast.stan"
  3. #include "blocks/confusion_inverse_model_binomial_hurdle.stan"
  4. #include "blocks/behavior_model_truth.stan"
  5. }
  6. // TODO
  7. // use speech rates to set priors on truth_vocs
  8. data {
  9. int<lower=1> n_classes; // number of classes
  10. // analysis data block
  11. int<lower=1> n_recs;
  12. int<lower=1> n_children;
  13. array[n_recs] int<lower=1> children;
  14. array[n_recs] real<lower=1> age;
  15. array[n_recs] int<lower=-1> siblings;
  16. array[n_recs, n_classes] int<lower=0> vocs;
  17. array[n_children] int<lower=1> corpus;
  18. real<lower=0> recs_duration;
  19. // speaker confusion data block
  20. int<lower=1> n_clips; // number of clips
  21. int<lower=1> n_groups; // number of groups
  22. int<lower=1> n_corpora;
  23. array [n_clips] int group;
  24. array [n_clips] int conf_corpus;
  25. array [n_clips,n_classes] int<lower=0> algo_total; // algo vocs attributed to specific speakers
  26. array [n_clips,n_classes] int<lower=0> truth_total;
  27. array [n_clips] real<lower=0> clip_duration;
  28. array [n_clips] real<lower=0> clip_age;
  29. int<lower=0> n_validation;
  30. // actual speech rates
  31. int<lower=1> n_rates;
  32. int<lower=1> n_speech_rate_children;
  33. array [n_rates,n_classes] int<lower=0> speech_rates;
  34. array [n_rates] int group_corpus;
  35. array [n_rates] real<lower=0> durations;
  36. array [n_rates] real<lower=0> speech_rate_age;
  37. array [n_rates] int<lower=-1> speech_rate_siblings;
  38. array [n_rates] int<lower=1,upper=n_speech_rate_children> speech_rate_child;
  39. // parallel processing
  40. int<lower=1> threads;
  41. }
  42. transformed data {
  43. vector<lower=0>[n_groups] recording_age;
  44. array[n_speech_rate_children] int<lower=1> speech_rate_child_corpus;
  45. array[n_children] int<lower=-1> child_siblings;
  46. array[n_speech_rate_children] int<lower=-1> speech_rate_child_siblings;
  47. int no_siblings = 0;
  48. int has_siblings = 0;
  49. for (c in 1:n_clips) {
  50. recording_age[group[c]] = clip_age[c];
  51. }
  52. for (k in 1:n_rates) {
  53. speech_rate_child_corpus[speech_rate_child[k]] = group_corpus[k];
  54. }
  55. for (k in 1:n_recs) {
  56. child_siblings[children[k]] = siblings[k];
  57. }
  58. for (c in 1:n_children) {
  59. if (child_siblings[c] == 0) {
  60. no_siblings += 1;
  61. }
  62. else if (child_siblings[c] > 0) {
  63. has_siblings += 1;
  64. }
  65. }
  66. for (k in 1:n_rates) {
  67. speech_rate_child_siblings[speech_rate_child[k]] = speech_rate_siblings[k];
  68. }
  69. }
  70. parameters {
  71. matrix<lower=0>[n_children,n_classes-1] mu_child_level;
  72. vector [n_children] child_dev_age;
  73. matrix<lower=0> [n_recs, n_classes] truth_vocs;
  74. array [n_recs] matrix<lower=0,upper=1>[n_classes,n_classes] actual_confusion_baseline;
  75. // confusion parameters
  76. #include "blocks/confusion_model_parameters_binomial_hurdle.stan"
  77. // behavior model parameters
  78. #include "blocks/behavior_model_parameters.stan"
  79. // parameters specific to human annotations
  80. #include "blocks/human_annotations_parameters.stan"
  81. }
  82. model {
  83. // inverse confusion model
  84. target += reduce_sum(
  85. inverse_model_lpdf, actual_confusion_baseline, 1,
  86. n_recs, n_classes, recs_duration,
  87. vocs, age,
  88. truth_vocs, mus, etas, p//, mus_fp, etas_fp
  89. );
  90. // contribution of full recordings to the model of behavior
  91. #include "blocks/behavior_observations_model.stan"
  92. target += reduce_sum(
  93. confusion_model_lpdf, lambda, 1,
  94. n_classes, n_clips,
  95. algo_total, truth_total, group, clip_duration, clip_age,
  96. p//, lambda_fp
  97. );
  98. // priors on the nuisance parameters of the confusion model
  99. #include "blocks/confusion_model_priors_binomial_hurdle.stan"
  100. // priors on the hierarchical model of speech behavior
  101. #include "blocks/behavior_model_priors.stan"
  102. // human annotations contribution
  103. #include "blocks/human_annotations.stan"
  104. }