-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathringexamplegraphslocalization.m
More file actions
69 lines (59 loc) · 1.78 KB
/
ringexamplegraphslocalization.m
File metadata and controls
69 lines (59 loc) · 1.78 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
%% LOCALIZATION PHENOMENA FOR THE PAGERANK ALGORITHM
% Code by:
% S. Cipolla - Università di Padova, Dipartimento di Matematica
% F. Durastante - Consiglio Nazionale delle Ricerche, Istituto per le
% Applicazioni del Calcolo "M. Picone"
% F. Tudisco - Gran Sasso Science Institute
clear; clc; close all;
%% Parameters defininig the cycle
n = 100; % Number of nodes in the cycle
L = 40; % Node with the added link
c = 0.85; % Teleportation parameter
% Circulant adjacency matrix:
c0 = [0,1,zeros(1,n-3),1];
A = sparse(gallery('circul',c0));
I = speye(n,n);
e = ones(n,1);
G = digraph(A); % Base graph
Gadd = addedge(G,L,1,1); % Graph with added direct edge
Gadd.Edges.Weight = []; % Remove the weights
% Standard pagerank
D = 1./(Gadd.adjacency()*e);
D(D == inf) = 0;
D = spdiags(D,0,n,n);
P = D*Gadd.adjacency();
xGadd_pr = powerpr(P,c);
figure(1)
subplot(1,2,1);
%% Nonlocal pagerank for the graph with added edge
theta = linspace(0,2*pi,n).';
for alpha = [0.01,0.1,0.5,1,10]
W = Gadd.distances();
W = 1./(W.^alpha);
W(W == inf) = 0;
D = (1./(W*e));
D(D == inf) = 0;
D = spdiags(D,0,n,n);
P = D*W;
xGadd = (I - c*P.')\((1-c)*e);
xGadd = xGadd./norm(xGadd,1);
figure(1);
subplot(1,2,1);
hold on
plot(1:n,xGadd,'DisplayName',sprintf('\\alpha = %1.2f',alpha),'LineWidth',2);
hold off
end
hold on
plot(1:n,xGadd_pr,'k-.','DisplayName',sprintf('\\alpha = \\infty'),'LineWidth',2);
hold off
legend()
xlabel('Nodes');
ylabel('PageRank');
set(gca,'FontSize',15)
subplot(1,2,2);
h = plot(Gadd,'Layout','circle','LineWidth',1,'MarkerSize',4,'NodeLabel',{});
labelnode(h,[1 10:10:n],[1 10:10:n])
highlight(h,[1 40],'NodeColor','red');
xcoord = (h.XData).';
ycoord = (h.YData).';
axis square tight