Вы находитесь на странице: 1из 7

 

​RV College of Engineering​®​, Bangalore – 560 059


(Autonomous Institution affiliated to VTU, Belagavi)

​ Certificate

 
 
 
Problem Statement : 
 

Demonstrating the use of the eigenvector and eigenvalues in implementing the PageRank. 

The PageRank is to determine the popularity or importance of a webpage based on the 


interconnection of the web. The basic principle used here is the page with more number of 
incoming links is more important than the page with number of the less incoming links. The other 
factor is a page with a link from a page which is known to be of high importance is also important. 

Source Code and Output : 


 

Page Rank General Algorithm 

Linking structure saved in two vectors there is a link from J(k) to I(k) 

I = [2 3 1 3 4 4 1];
J = [1 1 2 2 2 3 4];
% Create the Adjacency matrix/Connectivity matrix from I,J
H = full(sparse(I,J,1,4,4)); ​% notice the order of
% if you are using MATLAB 2015b or later, you can plot the directed graph
G = digraph(H'); plot(G); axis ​off ​% notice the transpose on H
% calculate in-degree and out-degree
r = sum(H,2); ​% out-degree, sum of each row
c = sum(H,1); ​% in-degree, sum of each column
% create the scaled matrix Ht
Ht = H*diag(1./c);
% Find the PageRank vector from eigenvalues associated with the eigenvector
[V,D] = eig(Ht); ​% find the eigenvalues and the eigenvectors
[~,ind] = min(abs(diag(D)-1)); ​% find the index of the eigenvalue 1 (not
exactly because of numerical error)
p = V(:,1)/sum(V(:,1)) ​% normalised eigenvector as the PageRank vector

p = ​4×1
0.3333
0.1667
0.2222
0.2778

[newp,rank] = sort(p,​'descend'​) ​% sort in descending order

newp = ​4×1
0.3333
0.2778
0.2222
0.1667
rank = ​4×1
1
4
3
2
 

Special Case: Dangling node (nodes without out-going links) 

I = [2 3 1 3 4 5 4 5 1];
J = [1 1 2 2 2 2 3 3 4];
H = full(sparse(I,J,1,5,5));
% if you are using MATLAB 2015b or later, you can plot the directed graph
G = digraph(H'); plot(G); axis ​off

% the last column of H is identically zero, and the resulting eigenpair


% does not work (eigenvalue is not 1), fixed by adding ones at the last
% comumn
H(:,5) = ones(5,1);
r = sum(H,2); ​% out-degree, sum of each row
c = sum(H,1); ​% in-degree, sum of each column
Ht = H*diag(1./c); ​% the rescaled matrix
[V,D] = eig(Ht); ​% find the eigenvalues and the eigenvectors
[~,ind] = min(abs(diag(D)-1)); ​% find the index of the eigenvalue 1 (not
exactly because of numerical error)
p = V(:,1)/sum(V(:,1)) ​% normalised eigenvector as the PageRank vector

p = ​5×1
0.2604
0.1667
0.2083
0.1823
0.1823

[newp,rank] = sort(p,​'descend'​) ​% sort in descending order

newp = ​5×1
0.2604
0.2083
0.1823
0.1823
0.1667
rank = ​5×1
1
3
4
5
2

Вам также может понравиться