plot_LLHperTrial.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. clear; clc
  2. load(fullfile(ottBari2020_root, 'Data', 'Modeling', 'ModelFits', 'cue_MLEfits.mat'));
  3. myColors = importColors_bb;
  4. VP_color = myColors.bluishGreen;
  5. % get relevant behavior models
  6. modelCriterion = 'AIC';
  7. plotFlag = false;
  8. models_of_interest_RPE = {'base_cue','base','curr_cue','curr','mean_cue','mean'};
  9. models_of_interest_V = {'base_cue','base','mean_cue','mean'};
  10. timePeriod = 'RD';
  11. bm_RD = select_RPEmods(os, timePeriod,'scoreToUse',modelCriterion,...
  12. 'plotModels_Flag',plotFlag,...
  13. 'particularModel',models_of_interest_RPE);
  14. timePeriod = 'cue';
  15. bm_cue = select_RPEmods(os, timePeriod,'scoreToUse',modelCriterion,...
  16. 'plotModels_Flag',plotFlag,...
  17. 'particularModel',models_of_interest_V);
  18. %% likelihood per trial
  19. timePeriod = 'RD'; % RD, cue
  20. LH = struct();
  21. switch timePeriod
  22. case 'RD'
  23. mods = models_of_interest_RPE;
  24. bm = bm_RD;
  25. mOfInt = 'mod_RD';
  26. case 'cue'
  27. mods = models_of_interest_V;
  28. bm = bm_cue;
  29. mOfInt = 'mod_cue';
  30. end
  31. % generate a blank LH structure
  32. for m1 = mods
  33. m1 = m1{:};
  34. for m2 = mods
  35. m2 = m2{:};
  36. LH.(m1).(m2) = [];
  37. end
  38. end
  39. % add for each neuron
  40. LH_cutoff = 10;
  41. for n = 1:length(os)
  42. nTrials = numel(os(n).spikeCount_RD);
  43. for m1 = mods
  44. m1 = m1{:};
  45. if bm.(['mask_' m1])(n) == 1 % if this is a neuron of interest
  46. for m2 = mods
  47. m2 = m2{:};
  48. tmp_LH = -os(n).(mOfInt).(m2).LH/nTrials;
  49. if tmp_LH < LH_cutoff
  50. LH.(m1).(m2) = [LH.(m1).(m2) tmp_LH];
  51. else
  52. LH.(m1).(m2) = [LH.(m1).(m2) NaN];
  53. end
  54. end
  55. end
  56. end
  57. end
  58. % fix names
  59. mods_forLabel = mods;
  60. mods_forLabel = strrep(mods_forLabel,'base_cue','RPE + Cue effect');
  61. mods_forLabel = strrep(mods_forLabel,'base','RPE');
  62. mods_forLabel = strrep(mods_forLabel,'curr_cue','Current outcome + Cue effect');
  63. mods_forLabel = strrep(mods_forLabel,'curr','Current outcome');
  64. mods_forLabel = strrep(mods_forLabel,'mean_cue','Unmodulated + Cue effect');
  65. mods_forLabel = strrep(mods_forLabel,'mean','Unmodulated');
  66. % plot it
  67. h_boxplot = figure;
  68. h_boxplot_rel = figure;
  69. n_plot = length(mods);
  70. for m1_ind = 1:length(mods)
  71. m1 = mods{m1_ind};
  72. box_mat = [];
  73. for m2_ind = 1:length(mods)
  74. m2 = mods{m2_ind};
  75. if ~isempty(LH.(m1).(m2))
  76. box_mat(:,m2_ind) = LH.(m1).(m2);
  77. end
  78. end
  79. figure(h_boxplot)
  80. set(h_boxplot, 'units', 'normalized', 'outerposition', [0 0 1 1]);
  81. h_sp_LH(m1_ind) = subplot(1,n_plot,m1_ind); hold on
  82. if size(box_mat, 1) > 5
  83. boxplot(box_mat,'BoxStyle','filled','PlotStyle','traditional','symbol','')
  84. set(gca,'tickdir','out','xtick',1:length(mods),'xticklabel',cellfun(@(i) [i ' model'],mods_forLabel,'UniformOutput',false),'xticklabelrotation',60)
  85. ylabel('LH/trial')
  86. title([mods_forLabel{m1_ind} ' neurons'],'interpreter','none')
  87. end
  88. % plot relative to mean model
  89. box_mat = [];
  90. for m2_ind = 1:length(mods) - 1 % all except the mean model
  91. m2 = mods{m2_ind};
  92. if ~isempty(LH.(m1).(m2))
  93. box_mat(:,m2_ind) = LH.(m1).(m2) - LH.(m1).mean;
  94. end
  95. end
  96. figure(h_boxplot_rel)
  97. set(h_boxplot_rel, 'units', 'normalized', 'outerposition', [0 0 1 1]);
  98. h_sp_LHrel(m1_ind) = subplot(1,n_plot,m1_ind); hold on
  99. if size(box_mat, 1) > 5
  100. boxplot(box_mat,'BoxStyle','filled','PlotStyle','traditional','symbol','')
  101. set(gca,'tickdir','out','xtick',1:length(mods)-1,'xticklabel',cellfun(@(i) [i ' model'],mods_forLabel(1:end-1),'UniformOutput',false),'xticklabelrotation',60)
  102. ylabel('\DeltaLH/trial (relative to Unmodulated model)')
  103. title([mods_forLabel{m1_ind} ' neurons'],'interpreter','none')
  104. plot([0.5 5.5],[0 0],'k:')
  105. end
  106. end
  107. ylim_LH = [-0.1 max([h_sp_LH.YLim])];
  108. ylim_LHrel = [min([h_sp_LHrel.YLim]) 0.1];
  109. figure(h_boxplot)
  110. for cp = h_sp_LH
  111. subplot(cp)
  112. % ylim(ylim_LH)
  113. ylim([-0.1 5.5])
  114. end
  115. figure(h_boxplot_rel)
  116. for cp = h_sp_LHrel
  117. subplot(cp)
  118. % ylim(ylim_LHrel)
  119. ylim([-0.9 0.1])
  120. end
  121. %%
  122. fprintf('RPE + Cue effect neurons [IQR]: %0.2f [%0.2f - %0.2f]\n', median(LH.base_cue.base_cue), prctile(LH.base_cue.base_cue, 25), prctile(LH.base_cue.base_cue, 75))
  123. fprintf('RPE neurons [IQR]: %0.2f [%0.2f - %0.2f]\n', median(LH.base.base), prctile(LH.base.base, 25), prctile(LH.base.base, 75))
  124. fprintf('Current outcome + Cue effect neurons [IQR]: %0.2f [%0.2f - %0.2f]\n', median(LH.curr_cue.curr_cue), prctile(LH.curr_cue.curr_cue, 25), prctile(LH.curr_cue.curr_cue, 75))
  125. fprintf('Current outcome neurons [IQR]: %0.2f [%0.2f - %0.2f]\n', median(LH.curr.curr), prctile(LH.curr.curr, 25), prctile(LH.curr.curr, 75))
  126. fprintf('Unmodulated neurons + Cue effect [IQR]: %0.2f [%0.2f - %0.2f]\n', median(LH.mean_cue.mean_cue), prctile(LH.mean_cue.mean_cue, 25), prctile(LH.mean_cue.mean_cue, 75))
  127. fprintf('Unmodulated neurons [IQR]: %0.2f [%0.2f - %0.2f]\n', median(LH.mean.mean), prctile(LH.mean.mean, 25), prctile(LH.mean.mean, 75))