mp2: done 1-6

This commit is contained in:
Claudio Maggioni 2020-10-06 14:43:53 +02:00
parent c4e74d48c4
commit 5eea5d6feb
6 changed files with 133 additions and 26 deletions

View file

@ -3,6 +3,11 @@ clc;
load('householder/housegraph.mat')
names = split(strtrim(convertCharsToStrings(name')));
common1 = names((A(:,Golub) .* A(:, Moler)) == 1)
common2 = names((A(:,Golub) .* A(:, Saunders)) == 1)
common3 = names((A(:,TChan) .* A(:, Demmel)) == 1)
disp("Golub-Moler:");
disp(names((A(:,Golub) .* A(:, Moler)) == 1));
disp("Golub-Saunders:");
disp(names((A(:,Golub) .* A(:, Saunders)) == 1));
disp("TChan-Demmel:");
disp(names((A(:,TChan) .* A(:, Demmel)) == 1));

View file

@ -0,0 +1,6 @@
clear;
clc;
load('householder/housegraph.mat')
names = split(strtrim(convertCharsToStrings(name')));
pagerank(names, A);

View file

@ -8,43 +8,31 @@ function x = pagerank(U,G,p)
if nargin < 3, p = .85; end
if(ischar(U))
U=cellstr(U);
end
if(isreal(U))
U=(num2cell(U));
end
% Eliminate any self-referential links
%G = G - diag(diag(G));
G = G - diag(diag(G));
% c = out-degree, r = in-degree
n = size(G,1);
[~,n] = size(G);
c = sum(G,1);
r = sum(G,2);
% Scale column sums to be 1 (or 0 where there are no out links).
k = find(c~=0);
D = sparse(k,k,1./c(k),n,n);
% Solve (I - p*G*D)*x = e
e = ones(n,1);
I = speye(n,n);
% ---------------------------------- DEFAULT ------------------------------
% Solve (I - p*G*D)*x = e
x = (I - p*G*D)\e;
% Normalize so that sum(x) == 1.
% -------------------------------------------------------------------------
% Normalize so that sum(x) == 1.
x = x/sum(x);
% Bar graph of page rank.
shg
bar(x)
title('Page Rank')
@ -53,13 +41,14 @@ title('Page Rank')
if nargout < 1
[~,q] = sort(-x);
disp(' page-rank in out url')
disp(' page-rank in out author');
k = 1;
while (k <= n) && (x(q(k)) >= .005)
maxN = length(U);
while (k <= maxN) && (x(q(k)) >= .005)
j = q(k);
temp1 = r(j);
temp2 = c(j);
fprintf(' %3.0f %8.4f %4.0f %4.0f %s\n', j,x(j),full(temp1),full(temp2),U{j})
fprintf(' %3.0f %8.4f %4.0f %4.0f %s\n', j,x(j),full(temp1),full(temp2),U{j});
k = k+1;
end
end

Binary file not shown.

View file

@ -118,7 +118,7 @@ Assuming that the degree of the Householder graph is the number of co-authors of
each author and that an author is not co-author of himself, the degree
centralities of all authors sorted in descending order are below.
This output has been obtained by running \texttt{ex2.m}.
This output has been obtained by running \texttt{ex3.m}.
\begin{verbatim}
Author Centrality: Coauthors...
@ -248,6 +248,8 @@ as:
\[C = \{i \in N_0 \;|\; (A_{:,i} \odot A_{:,j})_i = 1\}\]
The results below were computing by using the script \texttt{ex4.m}.
The common Co-authors between Golub and Moler are Wilkinson and Van Loan.
The common Co-authors between Golub and Saunders are Golub, Saunders and Gill.
@ -257,6 +259,111 @@ Heath.
\section{PageRank of the Coauthor Graph [10 points]}
The PageRank values for all authors were computing by using the scripts
\texttt{ex5.m} and \texttt{pagerank.m}, a basically identical version of
\texttt{pagerank.m} from Mini Project 1. The output is shown below.
\begin{verbatim}
page-rank in out author
1 0.0511 32 32 Golub
104 0.0261 16 16 Demmel
86 0.0229 14 14 Plemmons
44 0.0212 13 13 Schreiber
3 0.0201 11 11 TChan
81 0.0198 13 13 Heath
90 0.0181 10 10 Gragg
74 0.0177 11 11 Hammarling
66 0.0171 11 11 VanDooren
42 0.0152 9 9 Moler
79 0.0151 8 8 Gutknecht
32 0.0142 9 9 VanLoan
59 0.0135 8 8 Eisenstat
98 0.0133 8 8 Paige
46 0.0130 7 7 NTrefethen
49 0.0129 6 6 Varga
96 0.0128 7 7 Meyer
77 0.0128 7 7 Stewart
73 0.0127 8 8 Luk
78 0.0127 7 7 Bunch
53 0.0127 6 6 Widlund
72 0.0125 7 7 Reichel
41 0.0125 8 8 George
82 0.0124 6 6 Ipsen
83 0.0122 6 6 Greenbaum
58 0.0113 7 7 Bjorck
97 0.0107 6 6 Nichols
51 0.0106 6 6 Kagstrom
80 0.0106 6 6 Laub
52 0.0104 6 6 Barlow
60 0.0103 6 6 Zha
69 0.0102 6 6 Duff
62 0.0100 6 6 Park
89 0.0099 5 5 BunseGerstner
63 0.0098 5 5 Arioli
43 0.0097 6 6 Gilbert
67 0.0096 6 6 Liu
87 0.0096 5 5 Hansen
47 0.0090 5 5 Nachtigal
54 0.0090 4 4 Bjorstad
2 0.0088 5 5 Wilkinson
23 0.0088 5 5 Harrod
99 0.0087 5 5 Gill
92 0.0086 5 5 Sameh
91 0.0086 5 5 Berry
15 0.0086 5 5 Boley
76 0.0085 4 4 Fischer
50 0.0085 3 3 Young
61 0.0084 5 5 VanHuffel
100 0.0084 3 3 Jessup
48 0.0083 4 4 Kahan
35 0.0083 5 5 Bojanczyk
65 0.0082 5 5 Ng
93 0.0082 4 4 Ammar
55 0.0079 4 4 OLeary
84 0.0079 3 3 Ruhe
19 0.0078 4 4 Kaufman
56 0.0076 4 4 NHigham
37 0.0075 3 3 Marek
75 0.0075 3 3 Szyld
103 0.0074 3 3 Starke
34 0.0072 4 4 Saunders
25 0.0072 4 4 Funderlic
39 0.0072 4 4 Bai
102 0.0072 3 3 Hochbruck
88 0.0071 4 4 Elden
71 0.0070 4 4 Tang
38 0.0069 3 3 Kuo
40 0.0069 3 3 Tong
4 0.0068 3 3 He
13 0.0067 2 2 Kincaid
14 0.0067 2 2 Crevelli
94 0.0065 3 3 Warner
17 0.0065 3 3 Byers
21 0.0064 3 3 Fierro
31 0.0064 2 2 Wold
45 0.0062 3 3 Pothen
36 0.0060 3 3 Dubrulle
57 0.0058 2 2 Boman
10 0.0058 3 3 Overton
9 0.0057 2 2 Modersitzki
68 0.0056 2 2 Smith
95 0.0056 2 2 Davis
33 0.0056 2 2 Chandrasekaran
27 0.0055 2 2 Cullum
28 0.0055 2 2 Strakos
64 0.0054 2 2 MuntheKaas
7 0.0053 2 2 Ashby
85 0.0053 2 2 ATrefethen
29 0.0052 2 2 Saied
30 0.0052 2 2 Ong
18 0.0052 2 2 Benzi
101 0.0052 2 2 Mathias
8 0.0052 2 2 LeBorne
12 0.0052 2 2 Borges
6 0.0051 2 2 Kenney
70 0.0050 2 2 Henrici
\end{verbatim}
\section{Zachary's karate club: social network of friendships between 34 members [50 points]}
\begin{thebibliography}{99}