|
82 | 82 | if arg.window % use window
|
83 | 83 | idx = arg.window*(i-1)+1:arg.window*i;
|
84 | 84 | yi = y(idx,:);
|
85 |
| - pi = pred(idx,:); |
| 85 | + predi = pred(idx,:); |
86 | 86 | nobs = numel(idx);
|
87 | 87 | else % use entire trial
|
88 | 88 | yi = y;
|
89 |
| - pi = pred; |
| 89 | + predi = pred; |
90 | 90 | nobs = yobs;
|
91 | 91 | end
|
92 | 92 |
|
93 | 93 | % Compute error
|
94 | 94 | switch arg.error
|
95 | 95 | case 'mse'
|
96 |
| - err(i,:) = sum(abs(yi - pi).^2,1)/nobs; |
| 96 | + err(i,:) = sum(abs(yi - predi).^2,1)/nobs; |
97 | 97 | case 'mae'
|
98 |
| - err(i,:) = sum(abs(yi - pi),1)/nobs; |
| 98 | + err(i,:) = sum(abs(yi - predi),1)/nobs; |
99 | 99 | end
|
100 | 100 |
|
101 | 101 | switch arg.corr
|
102 | 102 | case 'Spearman' % convert to rank values
|
103 | 103 | yi = num2rank(yi,nobs,yvar);
|
104 |
| - pi = num2rank(pi,nobs,pvar); |
| 104 | + predi = num2rank(predi,nobs,pvar); |
105 | 105 | end
|
106 | 106 |
|
107 |
| - % Compute standard deviation |
108 |
| - sumy = sum(yi,1); sump = sum(pi,1); |
109 |
| - sdyp = sqrt((sum(yi.^2,1) - (sumy.^2)/nobs) .* ... |
110 |
| - (sum(pi.^2,1) - (sump.^2)/nobs)); |
| 107 | + % Demean signals |
| 108 | + y0 = yi - sum(yi,1)/nobs; |
| 109 | + pred0 = predi - sum(predi,1)/nobs; |
111 | 110 |
|
112 |
| - % Compute correlation |
113 |
| - r(i,:) = (sum(yi.*pi,1) - sumy.*sump/nobs)./sdyp; |
| 111 | + % Compute correlation coefficient |
| 112 | + r(i,:) = sum(y0.*pred0)/sqrt(sum(y0.^2)*sum(pred0.^2)); |
114 | 113 |
|
115 | 114 | end
|
116 | 115 |
|
|
0 commit comments