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.

analyzePRFcomputeGLMdenoiseregressors.m 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function noisereg = analyzePRFcomputeGLMdenoiseregressors(stimulus,data,tr)
  2. % function noisereg = analyzePRFcomputeGLMdenoiseregressors(stimulus,data,tr)
  3. %
  4. % <stimulus>,<data>,<tr> are from analyzePRF
  5. %
  6. % this is an internal function called by analyzePRF.m. this function constructs a
  7. % GLM design matrix based on <stimulus> and then uses GLMdenoisedata.m to determine
  8. % the optimal set of noise regressors. these regressors are returned in <noisereg>.
  9. %
  10. % in case you want to see the results of GLMdenoisedata.m, the figure output and
  11. % the results of GLMdenoisedata.m are saved to temporary files (as reported to the
  12. % command window).
  13. % internal constants
  14. corrthresh = .9; % used in determining which apertures are the same
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure out GLM design matrix
  16. % concatenate everything and drop the dummy column (X is pixels x frames)
  17. X = catcell(1,stimulus)';
  18. X(end,:) = [];
  19. % figure out where blanks are (logical vector, 1 x frames)
  20. blanks = all(X==0,1);
  21. % normalize each frame (in preparation for computing correlations)
  22. X = unitlength(X,1,[],0);
  23. X(:,blanks) = 0;
  24. % initialize the result (this will grow in size on-the-fly)
  25. glmdesign = zeros(size(X,2),0);
  26. % do the loop
  27. wh = find(~blanks);
  28. cnt = 1;
  29. while ~isempty(wh)
  30. ix = wh(1); % pick the first one to process
  31. corrs = X(:,ix)' * X; % compute correlation with all frames
  32. spots = find(corrs > corrthresh); % any frame with r > corrthresh counts as the same
  33. %%% fprintf('cnt=%d: numspots=%d\n',cnt,length(spots));
  34. glmdesign(spots,cnt) = 1; % add to design matrix
  35. X(:,spots) = 0; % blank out (since we're done with those columns)
  36. blanks(spots) = 1; % update the list of blanks
  37. wh = find(~blanks);
  38. cnt = cnt + 1;
  39. end
  40. % finally, un-concatenate the results
  41. glmdesign = splitmatrix(glmdesign,1,cellfun(@(x) size(x,1),stimulus));
  42. % clean up
  43. clear X;
  44. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% run GLMdenoise to get the noise regressors
  45. % what directory to save results to?
  46. glmdenoisedir = [tempname];
  47. assert(mkdir(glmdenoisedir));
  48. % call GLMdenoise
  49. fprintf('using GLMdenoise figure directory %s\n',[glmdenoisedir '/GLMdenoisefigures']);
  50. % prep
  51. hrfmodel = 'assume';
  52. hrfknobs = [];
  53. % run it
  54. results = GLMdenoisedata(glmdesign,data,tr,tr,hrfmodel,hrfknobs, ...
  55. struct('numboots',0), ...
  56. [glmdenoisedir '/GLMdenoisefigures']);
  57. % get the noise regressors
  58. noisereg = cellfun(@(x) x(:,1:results.pcnum),results.pcregressors,'UniformOutput',0);
  59. % save 'results' to a file
  60. file0 = [glmdenoisedir '/GLMdenoise.mat'];
  61. fprintf('saving GLMdenoise results to %s (in case you want them).\n',file0);
  62. results = rmfield(results,{'pcweights' 'models' 'modelse'}); % remove some boring fields
  63. save(file0,'results','noisereg','glmdesign');
  64. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% quick visualization
  65. for p=1:length(glmdesign)
  66. figureprep([100 100 700 700]); hold on;
  67. imagesc(glmdesign{p}); colormap(gray);
  68. axis image tight;
  69. set(gca,'YDir','reverse');
  70. title(sprintf('run %02d',p));
  71. figurewrite(sprintf('glmdesign%02d',p),[],[],glmdenoisedir);
  72. end