forked from aiavenak/matlab_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matching_index_wu.m
72 lines (65 loc) · 2 KB
/
matching_index_wu.m
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function [Mall] = matching_index_wu(CIJ,i,j)
%MATCHING_IND Matching index
%
% [Mall] = matching_ind(CIJ);
%
% For any two nodes u and v, the matching index computes the amount of
% overlap in the connection patterns of u and v. Self-connections and
% u-v connections are ignored. The matching index is a symmetric
% quantity, similar to a correlation or a dot product.
%
% Input: CIJ, weighted undirected connection/adjacency matrix
%
% Output: Min, matching index for incoming connections
% Mout, matching index for outgoing connections
% Mall, matching index for all connections
%
% Notes:
% Does not use self- or cross connections for comparison.
% Does not use connections that are not present in BOTH u and v.
% All output matrices are calculated for upper triangular only.
%
%
% Olaf Sporns, Indiana University, 2002/2007/2008/2013
N = size(CIJ,1);
if nargin==1
% compare all connections
Mall = zeros(N,N);
for i=1:N-1
c1 = CIJ(:,i);
for j=i+1:N
%c1 = [CIJ(:,i)' CIJ(i,:)];
%c2 = [CIJ(:,j)' CIJ(j,:)];
c2 = CIJ(:,j);
use = ~(~c1&~c2);
use(i) = 0;
use(j) = 0;
ncon = sum(c1(use))+sum(c2(use));
if (ncon==0)
Mall(i,j) = 0; %%% 0
else
c1u = c1(use); c2u = c2(use);
ov = c1(use)&c2(use);
Mall(i,j) = sum(c1u(ov)+c2u(ov))/ncon;
end;
end;
end;
% make full matrix
Mall = Mall+Mall';
elseif nargin==3
c1 = CIJ(:,i);
c2 = CIJ(:,j);
use = ~(~c1&~c2);
use(i) = 0;
use(j) = 0;
ncon = sum(c1(use))+sum(c2(use));
if (ncon==0)
Mall = 0;
else
c1u = c1(use); c2u = c2(use);
ov = c1(use)&c2(use);
Mall = sum(c1u(ov)+c2u(ov))/ncon;
end;
else
error('invalid number of nargin!');
end