-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagerank.m~
184 lines (149 loc) · 3.9 KB
/
pagerank.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
%PageRank Simulation (Matlab version)
%Laboratório Nacional de Computação Científica - LNCC
%Oscar Neiva Eulálio Neto - Orientador: Marcos Garcia Todorov
clear
clc
close all
%Start get the running time in seconds
tic();
%Number of states
N = 4;
%Number of distributed matrix
NPn = N;
%Time horizon
T = 10;
%Time horizon monte carlo
itmax = 10;
%Parameter m of Mean-Square Error
m = 0.15; %m = 0.15
%Random vector
%x = rand(1,N);
%x = diag(x*ones(N,1))\x;
%Static vectors
x = [0 0 0 1]; %Simple PageRank
%Other vectors
y = x;
xd = x;
yd = x;
z = x;
zr = x;
w = zeros(T+1,N);
%Random Stochastic Matrix(line)
%P = rand(N);
%P = diag(P*ones(N,1))\P;
%Stochastic Matrix
P = [0 0 0 1; 0.5 0 0.5 0; 0 0 0 1; 0.5 0.5 0 0];
%Vector with ones
v1 = ones(1,N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Mean-Square Error Convergence
M = 2*m/(N-m*(N-2));
%Create a tridimentional matrix with zeros
PP = zeros(size(P,1),size(P,2),N);
%Insert values in the tridimensional matrix
for i=1:N
%Insert ones in the diagonals
PP(i,i,:) = 1;
%Copy lines to the distributed matrix
PP(i,:,i) = P(i,:);
end
for it=1:itmax
for k=1:T
%Generate one integer number to represent the random distributed matrix
Pn = ceil(rand*NPn);
%Power Metod
x(k+1,:) = x(k,:)*P;
%PageRank with teleportation model (not distributed)
y(k+1,:) = (1-M)*(x(k,:)*P) + (M/N)*v1;
%PageRank with distributed link matrices
xd(k+1,:) = xd(k,:) * PP(:,:,Pn);
%PageRank with distributed teleportation model
yd(k+1,:) = (1-M)*(xd(k,:)*PP(:,:,Pn)) + (M/NPn)*v1;
%PageRank with time average (not recursive)
z(k,:) = sum(yd)/(T+1);
%PageRank with time average (recursive)
zr(k+1,:) = (((k+1)/(k+2)) * zr(k,:)) + ((1/(k+2))*yd(k+1,:));
end
w = w + zr./itmax;
end
time = toc ();
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plot results
clf
figure(1);
%subplot(211);
plot(x,'Linewidth',2.0);
set(gca,'fontsize',20);
set(gca,'XLim',[1 T]);
set(gca,'YLim',[0 2/N]);
title('Power Method');
ylabel('Pages values');
xlabel('Time');
print('-depsc2','powermetod');
%!ps2pdf -dEPSCrop powermetod.eps powermetod.pdf
figure(2);
%subplot(212);
plot(y, 'Linewidth', 2.0);
set(gca,'fontsize',20);
set(gca,'XLim',[1 T]);
set(gca,'YLim',[0 2/N]);
title('Teleportation Model');
ylabel('Pages values');
xlabel('Time');
print('-depsc2','teleportation');
%!ps2pdf -dEPSCrop teleportation.eps teleportation.pdf
%figure(3);
%subplot(211);
%plot(xd, 'Linewidth', 1.0);
%set(gca,'fontsize',20);
%set(gca,'XLim',[1 T]);
%set(gca,'YLim',[0 2/N]);
%title('PageRank With Distributed Link Matrices');
%ylabel('Pages values');
%xlabel('Time');
%print('-depsc2','pagedistributed');
%!ps2pdf -dEPSCrop pagedistributed.eps pagedistributed.pdf
figure(4);
%subplot(212);
plot(yd, 'Linewidth', 2.0);
set(gca,'fontsize',20);
set(gca,'XLim',[1 T]);
set(gca,'YLim',[0 2/N]);
title('Teleportation Model With Distributed Link Matrices');
ylabel('Pages values');
xlabel('Time');
print('-depsc2','teledistributed');
%!ps2pdf -dEPSCrop teledistributed.eps teledistributed.pdf
%figure(5);
%subplot(7,2,9);
%plot(z);
%set(gca,'fontsize',20);
%set(gca,'XLim',[1 T]);
%set(gca,'YLim',[0 2/N]);
%title('Time Average (Not Recursive)');
%ylabel('Pages values');
%xlabel('Time');
%print('-depsc2','polyak','-F:30');
%!ps2pdf -dEPSCrop polyak.eps polyak.pdf
figure(6);
%subplot(211);
plot(zr, 'Linewidth', 2.0);
set(gca,'fontsize',20);
set(gca,'XLim',[1 T]);
set(gca,'YLim',[0 2/N]);
title('Time Average (Recursive)');
ylabel('Pages values');
xlabel('Time');
print('-depsc2','timerecursive');
%!ps2pdf -dEPSCrop timerecursive.eps timerecursive.pdf
figure(7);
%subplot(212);
plot(w, 'Linewidth', 2.0);
set(gca,'fontsize',20);
set(gca,'XLim',[1 itmax]);
set(gca,'YLim',[0 2/N]);
title('Monte Carlo Simulation');
ylabel('Pages values');
xlabel('Time');
print('-depsc2','montecarlo');
%!ps2pdf -dEPSCrop montecarlo.eps montecarlo.pdf