what is r. in the pagerank algorithm
Mostrar comentarios más antiguos
I was reading Matlabs Pagerank algorithm and I was hoping that someone can clarify what the r. is within the equation. I have all the other elements just not sure what r.
Thank you!
Respuestas (1)
Askic V
el 10 de Abr. de 2023
Hi Kellie,
you probably mean on the following equation:
r = (1-P)/n + P*(A'*(r./d) + s/n);
% r is a vector of PageRank scores.
% P is a scalar damping factor (usually 0.85), which is the probability that a random surfer clicks on a link on the current page, instead of continuing on another random page.
% A' is the transpose of the adjacency matrix of the graph.
% d is a vector containing the out-degree of each node in the graph. d is set to 1 for nodes with no outgoing edges.
% n is the scalar number of nodes in the graph.
% s is the scalar sum of the PageRank scores for pages with no links.
So, this equation updates the vector of Pagerank scores based on the current value of vector r and other parameters.
Specifically,
r./d
is an element-wise division, which means that each element of r is divided with its corresponding element in vector d (the vector d contains same number of elements like vector r).
5 comentarios
Kellie
el 11 de Abr. de 2023
Kellie
el 11 de Abr. de 2023
No problem @Kellie
This is how I would implement it:
clear all;
clc;
% Example from the documentation
s = [1 1 2 2 3 3 3 4 5];
t = [2 5 3 4 4 5 6 1 1];
names = {'http://www.example.com/alpha', 'http://www.example.com/beta', ...
'http://www.example.com/gamma', 'http://www.example.com/delta', ...
'http://www.example.com/epsilon', 'http://www.example.com/zeta'};
G = digraph(s,t,[],names);
P = 0.85; % P is a scalar damping factor (usually 0.85)
pr = centrality(G,'pagerank','FollowProbability', P)
plot(G,'Layout','layered', ...
'NodeLabel',{'1','2','3','4','5','6'})
n = 6; % Number of nodes
d = outdegree(G); % d is a vector containing the out-degree of each node
A = adjacency(G); % A is the adjacency matrix of the graph
r = ones(6,1); % initial values
s = 0; % s is the scalar sum of the PageRank scores for pages with no links
for i = 1:n
if isempty(outedges(G,i))
s = s+1;
end
end
% s should be 1 after this step because of node 6
for i = 1:100 % repeat certain number of times until converge to final values
r = (1-P)/n + P*(A'*(r./d) + s/n);
end
r = r/sum(r) % sum must be equal to 1
Kellie
el 11 de Abr. de 2023
Askic V
el 11 de Abr. de 2023
Matrix A is an adjacency matrix of a graph G.
Please have a look at this link: https://en.wikipedia.org/wiki/Adjacency_matrix
If you want to create a directed graph based on the adjacency matrix, then you simply use the following syntax:
G2 = digraph(A)
In the example code above, matrix A is simply:
A =
0 1 0 0 1 0
0 0 1 1 0 0
0 0 0 1 1 1
1 0 0 0 0 0
1 0 0 0 0 0
0 0 0 0 0 0
If A(i,j) is 1 that means there is a directed connection from i to j.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
