Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

norm_MUA.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. %%% normalize & average MUA - THINGS dataset
  2. % 2022 P. Papale fecit
  3. clear all
  4. addpath(genpath('\_code\code_utils_v2\'));
  5. % constants
  6. monkey = 'monkeyN';
  7. datadir_gen = '\';
  8. % chns to region
  9. if monkey == 'monkeyN'
  10. rois = ones([1 1024]); % V1
  11. rois(513:768) = 2; % V4
  12. rois(769:end) = 3; % IT
  13. else
  14. rois = ones([1 1024]); % V1
  15. rois(513:832) = 3; % IT
  16. rois(833:end) = 2; % V4
  17. end
  18. % window of responses
  19. time_int{1} = 25:125; %V1
  20. time_int{2} = 50:150; %V4
  21. time_int{3} = 75:175; %IT
  22. %
  23. filename = [datadir_gen,monkey,'\THINGS_MUA_trials.mat'];
  24. load(filename)
  25. load([datadir_gen,monkey,'\logs_\1024chns_mapping_20220105.mat'])
  26. % ALLMAT: [#trial #train_pic #test_pic #pic_rep #ncount #day]
  27. days = max(ALLMAT(:,end));
  28. train_idx = ALLMAT(:,2)>0;
  29. test_idx = ALLMAT(:,3)>0;
  30. % get some basic SNR and latency estimates
  31. baseT = tb <= 0;
  32. for chn = 1:1024
  33. for day = 1:days
  34. clear day_norm_pool norm_pool base temp_mua noise signal maxsignal
  35. day_norm_pool = ALLMAT(:,end)==day & ALLMAT(:,5)==1;
  36. norm_pool = ALLMUA(:,day_norm_pool,:);
  37. base = nanmean(nanmean(norm_pool(chn,:,baseT),3),2);
  38. temp_mua = squeeze(norm_pool(chn,:,:))-base;
  39. noise = nanstd(nanmean(temp_mua(:,baseT),2));
  40. signal = smooth(squeeze(nanmean(temp_mua(:,tb>0))),25,'lowess');
  41. maxsignal = max(signal);
  42. SNR(chn,day) = maxsignal/noise;
  43. lats(chn,day) = latencyfit4AM(squeeze(nanmean(temp_mua)),tb/1000,1,0)*1000;
  44. end
  45. clear base test_MUA_trials temp_mua noise signal idx_ maxsignal
  46. base = nanmean(nanmean(ALLMUA(chn,:,baseT),3),2);
  47. test_MUA_trials = squeeze(ALLMUA(chn,test_idx,:));
  48. for i = 1:100
  49. f = find(test_trials == test_trials_idx(i));
  50. temp_reps = test_MUA_trials(f,:);
  51. test_MUA(i,:) = nanmean(temp_reps);
  52. end
  53. temp_mua = squeeze(ALLMUA(chn,:,:))-base;
  54. noise = nanstd(nanmean(temp_mua(:,baseT),2));
  55. signal = squeeze(nanmean(test_MUA(:,tb>0),2));
  56. idx_ = find(signal==max(signal));
  57. maxsignal = max(smooth(squeeze(test_MUA(idx_,tb>0)),25,'lowess'));
  58. SNR_max(chn) = maxsignal/noise;
  59. chn
  60. end
  61. SNR = SNR(mapping,:);
  62. SNR_max = SNR_max(mapping,:);
  63. lats = lats(mapping,:);
  64. % normalize and average (in time) MUA data:
  65. % we normalize the data on a daily basis by taking the mean and std of
  66. % the test trials of each day
  67. normMUA = nan([size(ALLMUA,1) size(ALLMUA,2)]);
  68. for chn = 1:length(rois)
  69. temp_chn_all = [];
  70. for day = 1:days
  71. clear day_norm_pool norm_pool
  72. day_norm_pool = test_idx & ALLMAT(:,end)==day;
  73. norm_pool = ALLMUA(:,day_norm_pool,:);
  74. day_trials = ALLMAT(:,end)==day;
  75. clear norm_mean norm_std temp_chn
  76. gt = tb > time_int{rois(chn)}(1) & tb <= time_int{rois(chn)}(end);
  77. norm_mean = nanmean(norm_pool(chn,:,gt),'all');
  78. norm_std = nanstd(norm_pool(chn,:,gt),[],'all');
  79. temp_chn = nanmean(squeeze(ALLMUA(chn,day_trials,gt)),2);
  80. temp_chn = (temp_chn-norm_mean)./norm_std;
  81. temp_chn_all = [temp_chn_all; temp_chn];
  82. end
  83. normMUA(chn,:) = temp_chn_all;
  84. end
  85. normMUA = normMUA(mapping,:);
  86. % get and sort train MUA data
  87. train_trials = ALLMAT(train_idx,2);
  88. [~,train_sorted] = sort(train_trials);
  89. train_MUA = normMUA(:,train_idx);
  90. train_MUA = train_MUA(:,train_sorted,:);
  91. % get test MUA data, average repetitions and sort
  92. test_trials = ALLMAT(test_idx,3);
  93. test_trials_idx = unique(test_trials);
  94. [~,test_sorted] = sort(test_trials_idx);
  95. test_MUA_trials = normMUA(:,test_idx);
  96. for i = 1:length(test_trials_idx)
  97. clear f temp_reps
  98. f = find(test_trials == test_trials_idx(i));
  99. temp_reps = test_MUA_trials(:,f);
  100. test_MUA(:,i) = nanmean(temp_reps,2);
  101. for j = 1:length(f)
  102. test_MUA_reps(:,i,j) = test_MUA_trials(:,f(j));
  103. end
  104. end
  105. test_MUA = test_MUA(:,test_sorted);
  106. % compute reliability and oracle correlation of response across repetitions
  107. for chn = 1:size(test_MUA_reps,1)
  108. clear temp_chn temp_oracle
  109. temp_chn = squeeze(test_MUA_reps(chn,:,:));
  110. reliab(chn,:) = (1-pdist(temp_chn','correlation'));
  111. for i = 1:size(test_MUA_reps,3)
  112. temp_oracle(i) = corr(temp_chn(:,i),nanmean(temp_chn(:,setdiff(1:size(test_MUA_reps,3),i)),2));
  113. end
  114. oracle(chn) = nanmean(temp_oracle);
  115. end
  116. filename = [datadir_gen,monkey,'\THINGS_normMUA.mat'];
  117. save(filename,'test_MUA','train_MUA','SNR','lats','reliab','oracle','test_MUA_reps','tb','SNR_max','-v7.3')
  118. pause(5)
  119. filename = [datadir_gen,monkey,'\THINGS_normMUA_all.mat'];
  120. save(filename,'normMUA','ALLMAT','tb','-v7.3')
  121. pause(5)