-
Notifications
You must be signed in to change notification settings - Fork 2
/
Network_Resilience.m
52 lines (45 loc) · 1.17 KB
/
Network_Resilience.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
function [l,e,c,comps,indices] = Network_Resilience(adjacency,method,user_indices)
% Resilience of a binary undirected network
%
% [l,e,c,comps,indices] = Network_Resilience(adjacency,method,user_indices)
%
% default: method = 'error'
%
% output:
% l characteristic path length
% e eficiency
% c clustering coeficient
% comps components
%
% by Jesus Perez-Ortega, Nov-2017
% modified June 2019
% Get the number of nodes
n = length(adjacency);
if nargin==1
method = 'error';
end
% Assign indices
switch method
case 'error'
indices = randperm(n);
case 'attack'
[~,indices] = sort(sum(adjacency),'descend');
case 'custom'
indices = user_indices;
end
% Remove neurons
all_nodes = 1:n;
for i=1:n-1
% Delete elements from matrix
id = setdiff(all_nodes,indices(1:i));
trimmed = adjacency(id,id);
% Characteristic path length and efficiency
D = distance_bin(trimmed);
[l(i), e(i)] = charpath(D);
% Clustering coefficient
clocal = clustering_coef_bu(trimmed);
c(i) = mean(clocal);
% Components
%comps(i) = max(get_components(trimmed))/(n-i);
comps(i) = max(get_components(trimmed));
end