Professional Documents
Culture Documents
1RV17CS134 1RV17CS202
1RV17CS134 1RV17CS202
Certificate
Problem Statement :
Demonstrating the use of the eigenvector and eigenvalues in implementing the PageRank.
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 = 4×1
0.3333
0.2778
0.2222
0.1667
rank = 4×1
1
4
3
2
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
p = 5×1
0.2604
0.1667
0.2083
0.1823
0.1823
newp = 5×1
0.2604
0.2083
0.1823
0.1823
0.1667
rank = 5×1
1
3
4
5
2