forked from musall/ridgeModel
-
Notifications
You must be signed in to change notification settings - Fork 9
/
modelCorr.m
18 lines (17 loc) · 756 Bytes
/
modelCorr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function [corrMat, varP1, varP2] = modelCorr(Vc,Vm,U)
%short code to compute the correlation between lowD data Vc and modeled
%lowD data Vm. Vc and Vm are temporal components, U is the spatial
%components. corrMat is a the correlation between Vc and Vm in each pixel.
Vc = reshape(Vc,size(Vc,1),[]);
Vm = reshape(Vm,size(Vm,1),[]);
if length(size(U)) == 3
U = arrayShrink(U, squeeze(isnan(U(:,:,1))));
end
covVc = cov(Vc'); % S x S
covVm = cov(Vm'); % S x S
cCovV = bsxfun(@minus, Vm, mean(Vm,2)) * Vc' / (size(Vc, 2) - 1); % S x S
covP = sum((U * cCovV) .* U, 2)'; % 1 x P
varP1 = sum((U * covVc) .* U, 2)'; % 1 x P
varP2 = sum((U * covVm) .* U, 2)'; % 1 x P
stdPxPy = varP1 .^ 0.5 .* varP2 .^ 0.5; % 1 x P
corrMat = gather((covP ./ stdPxPy)');