-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrsa_varianceLDC.m
More file actions
executable file
·47 lines (42 loc) · 1.86 KB
/
rsa_varianceLDC.m
File metadata and controls
executable file
·47 lines (42 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function V=rsa_varianceLDC(d,C,Sig,nPart,nVox);
% function V=rsa_varianceLDC(d,C,Sig,nPart,nVox);
% returns predicted variance-covariance of a set of LDC distances, which are
% assumed to caluclated using rsa.distanceLDC.
% INPUT:
% d/G: d: (nDist x 1) or (1 x nDist) vector of expected distances,
% these are assumed to be in a squareform(pdist) order
% G: A nCond x nCond second momement matrix of the patterns
% C: Contrast matrix that gives rise to the distances (nDist x
% nCond). If empty, it assumes that all pairwise distances are caluclated
% this uses optimised code.
% Sig: Variance-covariance matrix of noise in each fold of the
% original coefficicents (nCond x nCond), or scalar, assuming Sig = eye(nCond)*sig
% Noise is also assumed to be independent across voxels
% nPart: Number of independent partitions
% nVox: (effective) number of voxels
% OUTPUT:
% V: Variance-covariance matrix of the distances, a (DxD) matrix
% (c) 2015 Joern Diedrichsen (joern.diedrichsen@googlemail.com)
% Don't check input sizes too avoid overhead
nFolds = nPart*(nPart-1); % Number of pairs of partitions
% Infer the original G to get variance-covariance of the distances
[m,n]=size(d);
if (m==n) % Square matrix: Second moment
G=d;
else
G = squareform(-0.5*d); % Vector: distances
end;
nCond = size(G,1);
% Get the within-fold variance-covariance matrix of distances
if (isscalar(Sig))
Sig = eye(nCond).*Sig;
end;
if (isempty(C))
dG = rsa.stat.pairCACt(G); % Predicted variance-covariance of the signals
dSig = rsa.stat.pairCACt(Sig);
else
dG = C*G*C';
dSig = C*Sig*C';
end;
% Now Calculate the variance-covatiance matrix of the distances
V=(4*(dG.*dSig)/nPart + 2*(dSig.*dSig)/nFolds)/nVox;