forked from ivanbrugere/matlab-networks-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumConnTriples.m
executable file
·41 lines (35 loc) · 1.09 KB
/
numConnTriples.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
%##################################################################
% Count the number of connected triples in a graph.
% Note: works for undirected graphs only
%
% INPUTs: adjacency matrix, nxn
% OUTPUTs: integer - number of connected triples
%
% Other routines used: kneighbors.m, loops3.m
% GB: last updated, October 4, 2012
%##################################################################
function c=numConnTriples(adj)
c=0; % initialize
for i=1:length(adj)
neigh=kneighbors(adj,i,1);
if length(neigh)<2; continue; end % handle leaves, no triple here
c=c+nchoosek(length(neigh),2);
end
c=c-2*loops3(adj); % due to the symmetry triangles repeat 3 times
% in the nchoosek count
% alternative
% def numConnTriples(L):
%
% % input: adjacency list
% % outputs: number of connected triples
%
% c=0; % initialize number of connected triples
% l3 = 0; % initialize number of loops of size 3
%
% for i=1:length(L)
% neigh = L{i}
% if length(neigh)<2: continue; end
% c = c + nchoosek(length(neigh),2);
% end
%
% c = c - 2*loops3(adjL2adj(L));