-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathharmonicnobelity.m
More file actions
38 lines (37 loc) · 884 Bytes
/
harmonicnobelity.m
File metadata and controls
38 lines (37 loc) · 884 Bytes
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
function hc = harmonicnobelity(G,select,s)
%hc = nobelity(G,select,s)
%
%hc is the harmonic average proximity of all nodes to selected nodes in G
%G is a graph
%select is a vector of zeros and ones
%if select is a vector of ones, hc is the harmonic centrality measure
%s is an optional string, in for incloseness, out for outcloseness
%(=default)
%
%22 March 2022, Richard S.J. Tol
n = size(G.Nodes,1);
dist = distances(G);
for i=1:n
if select(i)==0
if ~exist('s')
dist(:,i) = inf;
elseif s(1)=='o'
dist(:,i) = inf;
else
dist(i,:) = inf;
end
end
end
invdist = dist.^-1;
for i=1:n
invdist(i,i)=0;
end
if ~exist('s')
hc = (n-1)*sum(invdist,2);
elseif s(1)=='o'
hc = (n-1)*sum(invdist,2);
elseif s(1)=='i'
hc = (n-1)*sum(invdist,1)';
else
hc = 0;
end