ssa_rebound_fig6_timing.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. %% timing experiment results
  2. % distributions showing rebound strength, shading significant units (for
  3. % each song)
  4. % summary data showing rebound strength doesn't correlate with surprise
  5. % (for each song)
  6. % sorted imagescs showing that rebounds do get more common as timescale
  7. % increases
  8. %% prep
  9. clear
  10. close all
  11. pipeline_out = 'D:\timing_expmts\multibird_summary_timing.mat';
  12. %% load multibird summary
  13. load(pipeline_out)
  14. % motif and bout lengths
  15. %% rbd strength per unit
  16. % for each unit, for each song, rebound is significant if it is significantly greater than 0
  17. % ie, if AVG - 1.65(STD) of rebound is greater than 0, rbd is significant
  18. %
  19. tmr = total_motif_resp;
  20. tmr_norm = tmr ./ max(tmr, [], 1);
  21. % habtest1 = 125.5;
  22. % testhab2 = 870.5;
  23. % habtest2 = 995.5;
  24. % testhab3 = 1735.5;
  25. % habtest3 = 1860.5;
  26. key_motifs = [1 125;
  27. 871 995;
  28. 1736 1860];
  29. rbds_by_song = zeros(sum(num_goods),3);
  30. sig_by_song = zeros(sum(num_goods),3);
  31. rbd_frac = zeros(sum(num_goods),3);
  32. sig_frac = zeros(sum(num_goods),3);
  33. for song_idx = 1:3
  34. this_m1_ids = key_motifs(song_idx,1):5:(key_motifs(song_idx,2));
  35. this_m5_ids = key_motifs(song_idx,1)+4:5:(key_motifs(song_idx,2));
  36. this_rbds = tmr(this_m1_ids(2:end),:) - ...
  37. tmr(this_m5_ids(1:end-1),:); % if rebound exists, this number will be positive
  38. avg_rbds = mean(this_rbds,1); % for each unit
  39. std_rbds = std(this_rbds,0,1); % for each unit
  40. sig_rbds = find((avg_rbds - 1.65*(std_rbds)) > 0);
  41. this_rbds_norm = tmr_norm(this_m1_ids(2:end),:) - ...
  42. tmr_norm(this_m5_ids(1:end-1),:); % if rebound exists, this number will be positive
  43. avg_rbds_frac = mean(this_rbds_norm,1); % for each unit
  44. std_rbds = std(this_rbds_norm,0,1); % for each unit
  45. sig_rbds_norm = find((avg_rbds_frac - 1.65*(std_rbds)) > 0);
  46. rbds_by_song(:, song_idx) = avg_rbds;
  47. sig_by_song(sig_rbds, song_idx) = 1;
  48. rbd_frac(:, song_idx) = avg_rbds_frac;
  49. sig_frac(sig_rbds_norm, song_idx) = 1;
  50. end
  51. %% plot and shade significant rebounds
  52. % bin_edges = -0.5:0.025:0.5;
  53. bin_edges = -18:3:30; % happen to know that these are bounds
  54. for song_idx = 1:3
  55. this_sig = find(sig_by_song(:,song_idx));
  56. figure(8181)
  57. subplot(1,3,song_idx)
  58. histogram(rbds_by_song(:,song_idx),'BinEdges', bin_edges)
  59. hold on;
  60. histogram(rbds_by_song(this_sig,song_idx),'BinEdges', bin_edges)
  61. hold off;
  62. xlabel('Rebound (Hz)')
  63. ylabel('Number of neurons')
  64. title(['Rebounds, Song ' num2str(song_idx)])
  65. end
  66. h5 = figure(8181);
  67. print(['figure_pieces/fig6_timing_rbdDist_raw'], '-dsvg', '-r300')
  68. saveas(h5, ['figure_pieces/fig6_timing_rbdDist_raw.fig'])
  69. %% plot and shade significant rebounds
  70. % bin_edges = -0.5:0.025:0.5;
  71. bin_edges = -0.5:0.05:0.5; % happen to know that these are bounds
  72. for song_idx = 1:3
  73. this_sig = find(sig_frac(:,song_idx));
  74. figure(8182)
  75. subplot(1,3,song_idx)
  76. histogram(rbd_frac(:,song_idx),'BinEdges', bin_edges)
  77. hold on;
  78. histogram(rbd_frac(this_sig,song_idx),'BinEdges', bin_edges)
  79. hold off;
  80. xlabel('Rebound (prop. of max.)')
  81. ylabel('Number of neurons')
  82. title(['Rebounds, Song ' num2str(song_idx)])
  83. end
  84. h5 = figure(8182);
  85. print(['figure_pieces/fig6_timing_rbdDist_frac'], '-dsvg', '-r300')
  86. saveas(h5, ['figure_pieces/fig6_timing_rbdDist_frac.fig'])
  87. %% summary showing rebounds aren't function of surprise
  88. % for each song (just 2 and 3), for each "sig rbd unit", plot normalized
  89. % rebound (maybe plot each unit)
  90. % need IBIs - can get without going back bc we have motifInfo
  91. % habtest1 = 125.5;
  92. % testhab2 = 870.5;
  93. % habtest2 = 995.5;
  94. % testhab3 = 1735.5;
  95. % habtest3 = 1860.5;
  96. key_motifs = [126 870;
  97. 996 1735;
  98. 1861 2595];
  99. % exclude standard IBIs to clean up plot (they're very common)
  100. std_ibis = [0.098 0.102; % song 1 doesn't matter, no sig rbds
  101. 0.995 1.005;
  102. 9.99 10.01];
  103. for song_idx = 1:3
  104. m1s = key_motifs(song_idx,1):5:key_motifs(song_idx,2);
  105. m5s = key_motifs(song_idx,1)+4:5:key_motifs(song_idx,2);
  106. bout_starts = cell2mat(motifInfo(m1s,1));
  107. bout_ends = cell2mat(motifInfo(m5s,3));
  108. these_IBIs = bout_starts(2:end) - bout_ends(1:end-1);
  109. these_IBIs = these_IBIs - 0.03; % final correction due to IMI
  110. this_rbds = tmr_norm(m1s(2:end),:) - ...
  111. tmr_norm(m5s(1:end-1),:); % if rebound exists, this number will be positive
  112. if song_idx == 1 % no sig rebounds during song 1, so plot all
  113. sig_rbds = this_rbds;
  114. this_sig = length(this_rbds);
  115. else
  116. this_sig = find(sig_by_song(:,song_idx));
  117. sig_rbds = this_rbds(:,this_sig);
  118. end
  119. this_y = mean(sig_rbds,2); % average across units
  120. this_err = std(sig_rbds, [], 2) ./ sqrt(length(this_sig)); % avging across neurons
  121. this_std_low = std_ibis(song_idx,1);
  122. this_std_high = std_ibis(song_idx,2);
  123. [std_IBIs] = find(...
  124. (these_IBIs > this_std_low) & (these_IBIs < this_std_high));
  125. dev_IBIs = setdiff(1:length(these_IBIs),std_IBIs);
  126. true_std = mean(these_IBIs(std_IBIs));
  127. std_y = mean(this_y(std_IBIs));
  128. std_err = std(this_y(std_IBIs)) ./ sqrt(length(std_IBIs));
  129. figure(12223)
  130. subplot(3,1,song_idx)
  131. errorbar(these_IBIs(dev_IBIs), this_y(dev_IBIs), 2*this_err(dev_IBIs), 'o')
  132. hold on;
  133. errorbar(true_std, std_y, 2*std_err, 'ro')
  134. hold off;
  135. title(['Dev Rebounds by IBI, Song ' num2str(song_idx)])
  136. xlabel('Inter-bout Interval')
  137. ylabel('Rebound (prop. of max.)')
  138. set(gca, 'FontSize', 12)
  139. end
  140. h5 = figure(12223);
  141. h5.Position = [100 100 600 800];
  142. print(['figure_pieces/fig6_timing_summary_frac'], '-dsvg', '-r300')
  143. saveas(h5, ['figure_pieces/fig6_timing_summary_frac.fig'])
  144. %% imagescs
  145. % just plot all motif response data sorted by rebound strength
  146. key_motifs = [1 125;
  147. 871 995;
  148. 1736 1860];
  149. tmr_norm = total_motif_resp ./ max(tmr, [], 1);
  150. for song_idx = 1:3
  151. this_rbds = rbds_by_song(:,song_idx);
  152. [~,rbd_sort] = sort(this_rbds,'descend');
  153. song_start = key_motifs(song_idx,1);
  154. song_end = key_motifs(song_idx,2);
  155. figure(8383)
  156. subplot(3,1,song_idx)
  157. imagesc(tmr_norm(song_start:song_end,rbd_sort)')
  158. title(['Motif Responses, Song ' num2str(song_idx)])
  159. xlabel('Motif Number')
  160. ylabel('Unit ID')
  161. end
  162. h5 = figure(8383);
  163. print(['figure_pieces/fig6__timing_rbd_imagesc'], '-dsvg', '-r300')
  164. saveas(h5, ['figure_pieces/fig6_timing_rbd_imagesc.fig'])