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.

fitnonlinearmodel_consolidate.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. function fitnonlinearmodel_consolidate(dir0)
  2. % function fitnonlinearmodel_consolidate(dir0)
  3. %
  4. % <dir0> is a directory containing results from fitnonlinearmodel.m
  5. %
  6. % load in all of the *.mat files in <dir0> and write
  7. % the consolidated results to <dir0>.mat.
  8. %
  9. % we assume that the full set of voxels have been analyzed
  10. % (in one or more chunks). only the primary outputs of
  11. % fitnonlinearmodel.m are saved to the new file; the auxiliary
  12. % outputs (that exist in individual .mat files) are not.
  13. %
  14. % note that we check to make sure that the total number of
  15. % voxels that are found in the .mat files is equal to the total
  16. % number of voxels specified in the original call to fitnonlinearmodel.m.
  17. % this ensures that all voxels have been analyzed!
  18. %
  19. % example:
  20. %
  21. % % first, set up the problem
  22. % x = randn(100,1);
  23. % y = bsxfun(@plus,2*x + 3,randn(100,20));
  24. % opt = struct( ...
  25. % 'outputdir','test', ...
  26. % 'stimulus',[x ones(100,1)], ...
  27. % 'data',y, ...
  28. % 'model',{{[1 1] [-Inf -Inf; Inf Inf] @(pp,dd) dd*pp'}});
  29. %
  30. % % next, do the fitting in chunks of 2
  31. % for p=1:10
  32. % fitnonlinearmodel(opt,2,p);
  33. % end
  34. %
  35. % % then, consolidate the results
  36. % fitnonlinearmodel_consolidate('test');
  37. %
  38. % % check the output
  39. % a = load('test.mat');
  40. % a
  41. % consolidate
  42. file0 = consolidatematdir(dir0,{'opt'}); % 'opt' may be big. let's specifically exclude it.
  43. % load
  44. a = load(file0);
  45. % what is the total number of voxels (so we can check)
  46. totalnumvxs = a.results(1).totalnumvxs;
  47. % assign to b, consolidating as we go
  48. clear b;
  49. varlist = {'params' 'trainperformance' 'testperformance' 'aggregatedtestperformance' 'testdata' 'modelpred' 'modelfit' 'numiters' 'resnorms'};
  50. dimlist = [3 2 2 2 2 2 3 2 2];
  51. for zz=1:length(varlist)
  52. if isfield(a.results(1),varlist{zz});
  53. % cat the results
  54. temp = cat(dimlist(zz),a.results.(varlist{zz}));
  55. % check if we have the full set of results. note that sometimes outputs can be empty.
  56. assert(isempty(temp) || size(temp,dimlist(zz)) == totalnumvxs, ...
  57. 'we did not find the full set of results!');
  58. % record
  59. b.(varlist{zz}) = temp;
  60. end
  61. end
  62. % save
  63. save(file0,'-struct','b');