Example 2: Inspect the model fits obtained by analyzePRF
Contents
Download dataset (if necessary) and add analyzePRF to the MATLAB path
setup;
Load and analyze the data (this follows the example1.m script)
if isempty(gcp)
parpool;
end
load('exampledataset.mat');
data = tseriesinterp(data,2,1,2);
results = analyzePRF(stimulus,data,1,struct('seedmode',[0 1],'display','off'));
*** analyzePRF: started at 28-Mar-2023 08:43:26. ***
converting stimulus (run 1) to sparse.
converting stimulus (run 2) to sparse.
converting stimulus (run 3) to sparse.
converting stimulus (run 4) to sparse.
using the following maximum polynomial degrees: [3 3 3 3]
*** fitnonlinearmodel: started at 28-Mar-2023 08:43:26. ***
*** fitnonlinearmodel: loading data. ***
*** fitnonlinearmodel: outputdir = , chunksize = 10, chunknum = 1
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [52.578 74.662 6.263 91.286 0.500 ].
for model 2 of 2, the seed is [52.578 74.662 6.263 91.286 0.500 ].
the estimated parameters are [52.479 74.169 8.451 103.298 0.690 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [55.614 80.765 12.825 -5.985 0.500 ].
for model 2 of 2, the seed is [55.614 80.765 12.825 -5.985 0.500 ].
the estimated parameters are [55.614 80.765 12.825 -5.985 0.500 ].
seed 1 was best. final estimated parameters are [52.479 74.169 8.451 103.298 0.690 ].
trainperformance is 68.24. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [49.930 57.225 8.953 21.124 0.500 ].
for model 2 of 2, the seed is [49.930 57.225 8.953 21.124 0.500 ].
the estimated parameters are [49.734 61.859 6.828 16.422 0.143 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [49.931 57.221 8.945 21.123 0.500 ].
for model 2 of 2, the seed is [49.931 57.221 8.945 21.123 0.500 ].
the estimated parameters are [49.734 61.859 6.828 16.422 0.143 ].
seed 2 was best. final estimated parameters are [49.734 61.859 6.828 16.422 0.143 ].
trainperformance is 32.53. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [49.283 59.081 12.871 22.731 0.500 ].
for model 2 of 2, the seed is [49.283 59.081 12.871 22.731 0.500 ].
the estimated parameters are [48.086 67.773 -1.208 17.512 -0.120 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [49.283 59.079 12.868 22.731 0.500 ].
for model 2 of 2, the seed is [49.283 59.079 12.868 22.731 0.500 ].
the estimated parameters are [48.085 67.775 -1.125 17.511 -0.120 ].
seed 1 was best. final estimated parameters are [48.086 67.773 -1.208 17.512 -0.120 ].
trainperformance is 27.54. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [54.763 65.409 7.189 64.523 0.500 ].
for model 2 of 2, the seed is [54.763 65.409 7.189 64.523 0.500 ].
the estimated parameters are [55.453 67.443 2.085 50.435 0.057 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [54.760 65.406 -7.197 64.537 0.500 ].
for model 2 of 2, the seed is [54.760 65.406 -7.197 64.537 0.500 ].
the estimated parameters are [55.453 67.443 -2.085 50.435 0.057 ].
seed 1 was best. final estimated parameters are [55.453 67.443 2.085 50.435 0.057 ].
trainperformance is 66.62. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [285.313 193.906 38.321 718243.602 0.500 ].
for model 2 of 2, the seed is [285.313 193.906 38.321 718243.602 0.500 ].
the estimated parameters are [289.652 196.516 19.484 718243.602 0.143 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [285.313 193.906 -38.321 718244.396 0.500 ].
for model 2 of 2, the seed is [285.313 193.906 -38.321 718244.396 0.500 ].
the estimated parameters are [289.652 196.516 -19.484 718244.396 0.143 ].
seed 2 was best. final estimated parameters are [289.652 196.516 -19.484 718244.396 0.143 ].
trainperformance is 25.72. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [8.229 99.015 -7.631 458.063 0.500 ].
for model 2 of 2, the seed is [8.229 99.015 -7.631 458.063 0.500 ].
the estimated parameters are [18.547 87.142 -2.304 73.010 0.184 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [35.481 65.449 -0.750 -33.759 0.500 ].
for model 2 of 2, the seed is [35.481 65.449 -0.750 -33.759 0.500 ].
the estimated parameters are [35.481 65.449 -0.750 -33.759 0.500 ].
seed 1 was best. final estimated parameters are [18.547 87.142 -2.304 73.010 0.184 ].
trainperformance is 67.28. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [43.926 79.551 26.698 97.164 0.500 ].
for model 2 of 2, the seed is [43.926 79.551 26.698 97.164 0.500 ].
the estimated parameters are [46.075 134.227 18.850 80.423 0.049 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [43.926 79.551 26.692 97.152 0.500 ].
for model 2 of 2, the seed is [43.926 79.551 26.692 97.152 0.500 ].
the estimated parameters are [46.075 134.227 18.850 80.423 0.049 ].
seed 1 was best. final estimated parameters are [46.075 134.227 18.850 80.423 0.049 ].
trainperformance is 52.42. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [55.814 62.798 11.298 25.208 0.500 ].
for model 2 of 2, the seed is [55.814 62.798 11.298 25.208 0.500 ].
the estimated parameters are [69.940 83.701 -1.553 24.823 -0.099 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [52.800 52.801 -0.149 23.507 0.500 ].
for model 2 of 2, the seed is [52.800 52.801 -0.149 23.507 0.500 ].
the estimated parameters are [52.805 52.804 -0.135 23.507 5.051 ].
seed 1 was best. final estimated parameters are [69.940 83.701 -1.553 24.823 -0.099 ].
trainperformance is 9.90. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [49.970 50.119 -0.251 23.055 0.500 ].
for model 2 of 2, the seed is [49.970 50.119 -0.251 23.055 0.500 ].
the estimated parameters are [49.995 50.006 -0.027 23.130 0.065 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [49.060 50.978 -0.133 14.787 0.500 ].
for model 2 of 2, the seed is [49.060 50.978 -0.133 14.787 0.500 ].
the estimated parameters are [49.031 50.989 -0.043 14.788 0.230 ].
seed 2 was best. final estimated parameters are [49.031 50.989 -0.043 14.788 0.230 ].
trainperformance is 22.19. testperformance is NaN.
aggregatedtestperformance is NaN.
starting resampling case 1 of 1.
trying seed 1 of 2.
for model 1 of 2, the seed is [50.500 50.500 17.678 10.000 0.500 ].
the estimated parameters are [50.427 50.551 -0.440 12.972 0.500 ].
for model 2 of 2, the seed is [50.427 50.551 -0.440 12.972 0.500 ].
the estimated parameters are [50.455 50.535 -0.248 18.342 0.191 ].
trying seed 2 of 2.
for model 1 of 2, the seed is [50.500 50.500 1.768 10.000 0.500 ].
the estimated parameters are [50.427 50.551 -0.443 13.030 0.500 ].
for model 2 of 2, the seed is [50.427 50.551 -0.443 13.030 0.500 ].
the estimated parameters are [50.455 50.535 -0.248 18.343 0.191 ].
seed 2 was best. final estimated parameters are [50.455 50.535 -0.248 18.343 0.191 ].
trainperformance is 14.22. testperformance is NaN.
aggregatedtestperformance is NaN.
*** fitnonlinearmodel: ended at 28-Mar-2023 08:43:46 (0.3 minutes). ***
saving results to /private/var/folders/bh/zdz8wgzs3cs6lwkkljzydb_00000gn/T/tpe16b46ba_c006_4929_9d21_d6e8bcc8397a.mat (just in case).
*** analyzePRF: ended at 28-Mar-2023 08:43:46 (0.3 minutes). ***
Perform some setup
res = [100 100];
resmx = 100;
hrf = results.options.hrf;
degs = results.options.maxpolydeg;
[d,xx,yy] = makegaussian2d(resmx,2,2,2,2);
stimulusPP = {};
for p=1:length(stimulus)
stimulusPP{p} = squish(stimulus{p},2)';
stimulusPP{p} = [stimulusPP{p} p*ones(size(stimulusPP{p},1),1)];
end
modelfun = @(pp,dd) conv2run(posrect(pp(4)) * (dd*[vflatten(placematrix(zeros(res),makegaussian2d(resmx,pp(1),pp(2),abs(pp(3)),abs(pp(3)),xx,yy,0,0) / (2*pi*abs(pp(3))^2))); 0]) .^ posrect(pp(5)),hrf,dd(:,prod(res)+1));
polymatrix = {};
for p=1:length(degs)
polymatrix{p} = projectionmatrix(constructpolynomialmatrix(size(data{p},2),0:degs(p)));
end
Inspect the data and the model fit
vx = 2;
datats = {};
modelts = {};
for p=1:length(data)
datats{p} = polymatrix{p}*data{p}(vx,:)';
modelts{p} = polymatrix{p}*modelfun(results.params(1,:,vx),stimulusPP{p});
end
figure; hold on;
set(gcf,'Units','points','Position',[100 100 1000 100]);
plot(cat(1,datats{:}),'r-');
plot(cat(1,modelts{:}),'b-');
straightline(300*(1:4)+.5,'v','g-');
xlabel('Time (s)');
ylabel('BOLD signal');
ax = axis;
axis([.5 1200+.5 ax(3:4)]);
title('Time-series data');