mp1: added template
This commit is contained in:
commit
ee71bfbd5d
9 changed files with 491 additions and 0 deletions
147
.gitignore
vendored
Executable file
147
.gitignore
vendored
Executable file
|
@ -0,0 +1,147 @@
|
||||||
|
*.ijvm
|
||||||
|
*.mic1
|
||||||
|
|
||||||
|
# ---> TeX
|
||||||
|
## Core latex/pdflatex auxiliary files:
|
||||||
|
*.aux
|
||||||
|
*.lof
|
||||||
|
*.log
|
||||||
|
*.lot
|
||||||
|
*.fls
|
||||||
|
*.out
|
||||||
|
*.toc
|
||||||
|
|
||||||
|
## Intermediate documents:
|
||||||
|
*.dvi
|
||||||
|
*-converted-to.*
|
||||||
|
# these rules might exclude image files for figures etc.
|
||||||
|
# *.ps
|
||||||
|
# *.eps
|
||||||
|
# *.pdf
|
||||||
|
|
||||||
|
## Bibliography auxiliary files (bibtex/biblatex/biber):
|
||||||
|
*.bbl
|
||||||
|
*.bcf
|
||||||
|
*.blg
|
||||||
|
*-blx.aux
|
||||||
|
*-blx.bib
|
||||||
|
*.brf
|
||||||
|
*.run.xml
|
||||||
|
|
||||||
|
## Build tool auxiliary files:
|
||||||
|
*.fdb_latexmk
|
||||||
|
*.synctex
|
||||||
|
*.synctex.gz
|
||||||
|
*.synctex.gz(busy)
|
||||||
|
*.pdfsync
|
||||||
|
|
||||||
|
## Auxiliary and intermediate files from other packages:
|
||||||
|
|
||||||
|
|
||||||
|
# algorithms
|
||||||
|
*.alg
|
||||||
|
*.loa
|
||||||
|
|
||||||
|
# achemso
|
||||||
|
acs-*.bib
|
||||||
|
|
||||||
|
# amsthm
|
||||||
|
*.thm
|
||||||
|
|
||||||
|
# beamer
|
||||||
|
*.nav
|
||||||
|
*.snm
|
||||||
|
*.vrb
|
||||||
|
|
||||||
|
#(e)ledmac/(e)ledpar
|
||||||
|
*.end
|
||||||
|
*.[1-9]
|
||||||
|
*.[1-9][0-9]
|
||||||
|
*.[1-9][0-9][0-9]
|
||||||
|
*.[1-9]R
|
||||||
|
*.[1-9][0-9]R
|
||||||
|
*.[1-9][0-9][0-9]R
|
||||||
|
*.eledsec[1-9]
|
||||||
|
*.eledsec[1-9]R
|
||||||
|
*.eledsec[1-9][0-9]
|
||||||
|
*.eledsec[1-9][0-9]R
|
||||||
|
*.eledsec[1-9][0-9][0-9]
|
||||||
|
*.eledsec[1-9][0-9][0-9]R
|
||||||
|
|
||||||
|
# glossaries
|
||||||
|
*.acn
|
||||||
|
*.acr
|
||||||
|
*.glg
|
||||||
|
*.glo
|
||||||
|
*.gls
|
||||||
|
|
||||||
|
# gnuplottex
|
||||||
|
*-gnuplottex-*
|
||||||
|
|
||||||
|
# hyperref
|
||||||
|
*.brf
|
||||||
|
|
||||||
|
# knitr
|
||||||
|
*-concordance.tex
|
||||||
|
*.tikz
|
||||||
|
*-tikzDictionary
|
||||||
|
|
||||||
|
# listings
|
||||||
|
*.lol
|
||||||
|
|
||||||
|
# makeidx
|
||||||
|
*.idx
|
||||||
|
*.ilg
|
||||||
|
*.ind
|
||||||
|
*.ist
|
||||||
|
|
||||||
|
# minitoc
|
||||||
|
*.maf
|
||||||
|
*.mtc
|
||||||
|
*.mtc[0-9]
|
||||||
|
*.mtc[1-9][0-9]
|
||||||
|
|
||||||
|
# minted
|
||||||
|
_minted*
|
||||||
|
*.pyg
|
||||||
|
|
||||||
|
# morewrites
|
||||||
|
*.mw
|
||||||
|
|
||||||
|
# mylatexformat
|
||||||
|
*.fmt
|
||||||
|
|
||||||
|
# nomencl
|
||||||
|
*.nlo
|
||||||
|
|
||||||
|
# sagetex
|
||||||
|
*.sagetex.sage
|
||||||
|
*.sagetex.py
|
||||||
|
*.sagetex.scmd
|
||||||
|
|
||||||
|
# sympy
|
||||||
|
*.sout
|
||||||
|
*.sympy
|
||||||
|
sympy-plots-for-*.tex/
|
||||||
|
|
||||||
|
# TikZ & PGF
|
||||||
|
*.dpth
|
||||||
|
*.md5
|
||||||
|
*.auxlock
|
||||||
|
|
||||||
|
# todonotes
|
||||||
|
*.tdo
|
||||||
|
|
||||||
|
# xindy
|
||||||
|
*.xdy
|
||||||
|
|
||||||
|
# WinEdt
|
||||||
|
*.bak
|
||||||
|
*.sav
|
||||||
|
|
||||||
|
# Mac stupid tmp files
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
!*.pdf
|
||||||
|
|
||||||
|
*~
|
13
mp1/Makefile
Normal file
13
mp1/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
filename=template
|
||||||
|
|
||||||
|
pdf:
|
||||||
|
pdflatex ${filename}
|
||||||
|
pdflatex ${filename}
|
||||||
|
make clean
|
||||||
|
|
||||||
|
read:
|
||||||
|
evince ${filename}.pdf &
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f ${filename}.out ${filename}.log ${filename}.bbl ${filename}.blg ${filename}.au ${filename}.log ${filename}.ps ${filename}.aux ${filename}.out ${filename}.dvi ${filename}.bbl ${filename}.blg ${filename}.toc ${filename}.nav ${filename}.vrb ${filename}.snm
|
95
mp1/assignment.sty
Normal file
95
mp1/assignment.sty
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
\usepackage{ifthen}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage{graphics}
|
||||||
|
\usepackage{graphicx}
|
||||||
|
\usepackage{hyperref}
|
||||||
|
|
||||||
|
\pagestyle{plain}
|
||||||
|
\voffset -5mm
|
||||||
|
\oddsidemargin 0mm
|
||||||
|
\evensidemargin -11mm
|
||||||
|
\marginparwidth 2cm
|
||||||
|
\marginparsep 0pt
|
||||||
|
\topmargin 0mm
|
||||||
|
\headheight 0pt
|
||||||
|
\headsep 0pt
|
||||||
|
\topskip 0pt
|
||||||
|
\textheight 255mm
|
||||||
|
\textwidth 165mm
|
||||||
|
|
||||||
|
\newcommand{\duedate} {}
|
||||||
|
\newcommand{\setduedate}[1]{%
|
||||||
|
\renewcommand\duedate {Due date:~ #1}}
|
||||||
|
\newcommand\isassignment {false}
|
||||||
|
\newcommand{\setassignment}{\renewcommand\isassignment {true}}
|
||||||
|
\newcommand{\ifassignment}[1]{\ifthenelse{\boolean{\isassignment}}{#1}{}}
|
||||||
|
\newcommand{\ifnotassignment}[1]{\ifthenelse{\boolean{\isassignment}}{}{#1}}
|
||||||
|
|
||||||
|
\newcommand{\assignmentpolicy}{
|
||||||
|
\begin{table}[h]
|
||||||
|
\begin{center}
|
||||||
|
\scalebox{0.8} {%
|
||||||
|
\begin{tabular}{|p{0.02cm}p{16cm}|}
|
||||||
|
\hline
|
||||||
|
&\\
|
||||||
|
\multicolumn{2}{|c|}{\Large\textbf{Numerical Computing 2020 --- Submission Instructions}}\\
|
||||||
|
\multicolumn{2}{|c|}{\large\textbf{(Please, notice that following instructions are mandatory: }}\\
|
||||||
|
\multicolumn{2}{|c|}{\large\textbf{submissions that don't comply with, won't be considered)}}\\
|
||||||
|
&\\
|
||||||
|
\textbullet & Assignments must be submitted to \href{https://www.icorsi.ch/course/view.php?id=10018}{iCorsi} (i.e. in electronic format).\\
|
||||||
|
\textbullet & Provide both executable package and sources (e.g. C/C++ files, Matlab).
|
||||||
|
If you are using libraries, please add them in the file. Sources must be organized in directories called:\\
|
||||||
|
\multicolumn{2}{|c|}{\textit{Project\_number\_lastname\_firstname}}\\
|
||||||
|
& and the file must be called:\\
|
||||||
|
\multicolumn{2}{|c|}{\textit{project\_number\_lastname\_firstname.zip}}\\
|
||||||
|
\multicolumn{2}{|c|}{\textit{project\_number\_lastname\_firstname.pdf}}\\
|
||||||
|
\textbullet & The TAs will grade your project by reviewing your project write-up, and looking at the implementation
|
||||||
|
you attempted, and benchmarking your code's performance.\\
|
||||||
|
|
||||||
|
\textbullet & You are allowed to discuss all questions with anyone you like; however: (i) your submission must list anyone you discussed problems with and (ii) you must write up your submission independently.\\
|
||||||
|
\hline
|
||||||
|
\end{tabular}
|
||||||
|
}
|
||||||
|
\end{center}
|
||||||
|
\end{table}
|
||||||
|
}
|
||||||
|
\newcommand{\punkte}[1]{\hspace{1ex}\emph{\mdseries\hfill(#1~\ifcase#1{Points}\or{Points}\else{Points}\fi)}}
|
||||||
|
|
||||||
|
|
||||||
|
\newcommand\serieheader[6]{
|
||||||
|
\thispagestyle{empty}%
|
||||||
|
\begin{flushleft}
|
||||||
|
\includegraphics[width=0.4\textwidth]{usi_inf}
|
||||||
|
\end{flushleft}
|
||||||
|
\noindent%
|
||||||
|
{\large\ignorespaces{\textbf{#1}}\hspace{\fill}\ignorespaces{ \textbf{#2}}}\\ \\%
|
||||||
|
{\large\ignorespaces #3 \hspace{\fill}\ignorespaces #4}\\
|
||||||
|
\noindent%
|
||||||
|
\bigskip
|
||||||
|
\hrule\par\bigskip\noindent%
|
||||||
|
\bigskip {\ignorespaces {\Large{\textbf{#5}}}
|
||||||
|
\hspace{\fill}\ignorespaces \large \ifthenelse{\boolean{\isassignment}}{\duedate}{#6}}
|
||||||
|
\hrule\par\bigskip\noindent% \linebreak
|
||||||
|
}
|
||||||
|
|
||||||
|
\makeatletter
|
||||||
|
\def\enumerateMod{\ifnum \@enumdepth >3 \@toodeep\else
|
||||||
|
\advance\@enumdepth \@ne
|
||||||
|
\edef\@enumctr{enum\romannumeral\the\@enumdepth}\list
|
||||||
|
{\csname label\@enumctr\endcsname}{\usecounter
|
||||||
|
{\@enumctr}%%%? the following differs from "enumerate"
|
||||||
|
\topsep0pt%
|
||||||
|
\partopsep0pt%
|
||||||
|
\itemsep0pt%
|
||||||
|
\def\makelabel##1{\hss\llap{##1}}}\fi}
|
||||||
|
\let\endenumerateMod =\endlist
|
||||||
|
\makeatother
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\usepackage{textcomp}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
mp1/files_data/ETH500.mat
Normal file
BIN
mp1/files_data/ETH500.mat
Normal file
Binary file not shown.
56
mp1/files_data/pagerank.m
Normal file
56
mp1/files_data/pagerank.m
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
function x = pagerank(U,G,p)
|
||||||
|
% PAGERANK Google's PageRank
|
||||||
|
% pagerank(U,G,p) uses the URLs and adjacency matrix produced by SURFER,
|
||||||
|
% together with a damping factory p, (default is .85), to compute and plot
|
||||||
|
% a bar graph of page rank, and print the dominant URLs in page rank order.
|
||||||
|
% x = pagerank(U,G,p) returns the page ranks instead of printing.
|
||||||
|
% See also SURFER, SPY.
|
||||||
|
|
||||||
|
if nargin < 3, p = .85; end
|
||||||
|
|
||||||
|
% Eliminate any self-referential links
|
||||||
|
%G = G - diag(diag(G));
|
||||||
|
|
||||||
|
% c = out-degree, r = in-degree
|
||||||
|
[~,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);
|
||||||
|
|
||||||
|
e = ones(n,1);
|
||||||
|
I = speye(n,n);
|
||||||
|
|
||||||
|
% ---------------------------------- DEFAULT ------------------------------
|
||||||
|
% Solve (I - p*G*D)*x = e
|
||||||
|
disp('Using default implementation\n');
|
||||||
|
x = (I - p*G*D)\e;
|
||||||
|
|
||||||
|
% -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
% Normalize so that sum(x) == 1.
|
||||||
|
x = x/sum(x);
|
||||||
|
|
||||||
|
% Bar graph of page rank.
|
||||||
|
shg
|
||||||
|
bar(x)
|
||||||
|
title('Page Rank')
|
||||||
|
|
||||||
|
% Print URLs in page rank order.
|
||||||
|
|
||||||
|
if nargout < 1
|
||||||
|
[~,q] = sort(-x);
|
||||||
|
disp(' page-rank in out url')
|
||||||
|
k = 1;
|
||||||
|
maxN = length(U);
|
||||||
|
while (k <= maxN) && (x(q(k)) >= .005)
|
||||||
|
disp(k)
|
||||||
|
j = q(k);
|
||||||
|
temp1 = r(j);
|
||||||
|
temp2 = c(j);
|
||||||
|
disp(fprintf(' %3.0f %8.4f %4.0f %4.0f %s', j,x(j),full(temp1),full(temp2),U{j}))
|
||||||
|
k = k+1;
|
||||||
|
end
|
||||||
|
end
|
149
mp1/files_data/surfer.m
Normal file
149
mp1/files_data/surfer.m
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
function [U,G] = surfer(root,n)
|
||||||
|
% UPDATED VERSION
|
||||||
|
|
||||||
|
% SURFER Create the adjacency graph of a portion of the Web.
|
||||||
|
% [U,G] = surfer(root,n) starts at the URL root and follows
|
||||||
|
% Web links until it forms an adjacency graph with n nodes.
|
||||||
|
% U = a cell array of n strings, the URLs of the nodes.
|
||||||
|
% G = an n-by-n sparse matrix with G(i,j)=1 if node j is linked to node i.
|
||||||
|
%
|
||||||
|
% Example: [U,G] = surfer('https://inf.ethz.ch/',500);
|
||||||
|
% See also PAGERANK.
|
||||||
|
%
|
||||||
|
% This function currently has two defects. (1) The algorithm for
|
||||||
|
% finding links is naive. We just look for the string 'http:'.
|
||||||
|
% (2) An attempt to read from a URL that is accessible, but very slow,
|
||||||
|
% might take an unacceptably long time to complete. In some cases,
|
||||||
|
% it may be necessary to have the operating system terminate MATLAB.
|
||||||
|
% Key words from such URLs can be added to the skip list in surfer.m.
|
||||||
|
|
||||||
|
% Initialize
|
||||||
|
|
||||||
|
clf
|
||||||
|
shg
|
||||||
|
set(gcf,'doublebuffer','on')
|
||||||
|
axis([0 n 0 n])
|
||||||
|
axis square
|
||||||
|
axis ij
|
||||||
|
box on
|
||||||
|
set(gca,'position',[.12 .20 .78 .78])
|
||||||
|
uicontrol('style','frame','units','normal','position',[.01 .09 .98 .07]);
|
||||||
|
uicontrol('style','frame','units','normal','position',[.01 .01 .98 .07]);
|
||||||
|
t1 = uicontrol('style','text','units','normal','position',[.02 .10 .94 .04], ...
|
||||||
|
'horiz','left');
|
||||||
|
t2 = uicontrol('style','text','units','normal','position',[.02 .02 .94 .04], ...
|
||||||
|
'horiz','left');
|
||||||
|
slow = uicontrol('style','toggle','units','normal', ...
|
||||||
|
'position',[.01 .24 .07 .05],'string','slow','value',0);
|
||||||
|
quit = uicontrol('style','toggle','units','normal', ...
|
||||||
|
'position',[.01 .17 .07 .05],'string','quit','value',0);
|
||||||
|
|
||||||
|
U = cell(n,1);
|
||||||
|
hash = zeros(n,1);
|
||||||
|
G = logical(sparse(n,n));
|
||||||
|
m = 1;
|
||||||
|
U{m} = root;
|
||||||
|
hash(m) = hashfun(root);
|
||||||
|
|
||||||
|
j = 1;
|
||||||
|
while j < n && get(quit,'value') == 0
|
||||||
|
|
||||||
|
% Try to open a page.
|
||||||
|
|
||||||
|
try
|
||||||
|
set(t1,'string',sprintf('%5d %s',j,U{j}))
|
||||||
|
set(t2,'string','');
|
||||||
|
drawnow
|
||||||
|
page = urlread(U{j});
|
||||||
|
catch
|
||||||
|
set(t1,'string',sprintf('fail: %5d %s',j,U{j}))
|
||||||
|
drawnow
|
||||||
|
j = j+1;
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
if get(slow,'value')
|
||||||
|
pause(.25)
|
||||||
|
end
|
||||||
|
|
||||||
|
% Follow the links from the open page.
|
||||||
|
|
||||||
|
for f = strfind(page, 'https:')
|
||||||
|
|
||||||
|
% A link starts with 'http:' and ends with the next quote.
|
||||||
|
|
||||||
|
e = min([strfind(page(f:end),'"') strfind(page(f:end),'''')]);
|
||||||
|
if isempty(e), continue, end
|
||||||
|
url = deblank(page(f:f+e-2));
|
||||||
|
url(url<' ') = '!'; % Nonprintable characters
|
||||||
|
if url(end) == '/', url(end) = []; end
|
||||||
|
|
||||||
|
% Look for links that should be skipped.
|
||||||
|
|
||||||
|
skips = {'.gif','.jpg','.jpeg','.pdf','.css','.asp','.mwc','.ram', ...
|
||||||
|
'.cgi','lmscadsi','cybernet','w3.org','google','yahoo', ...
|
||||||
|
'scripts','netscape','shockwave','webex','fansonly', ...
|
||||||
|
'idref.fr', 'purl.org', 'freedomdefined','wernfbox' };
|
||||||
|
|
||||||
|
skip = any(url=='!') | any(url=='?');
|
||||||
|
k = 0;
|
||||||
|
while ~skip && (k < length(skips))
|
||||||
|
k = k+1;
|
||||||
|
skip = ~isempty(strfind(url,skips{k}));
|
||||||
|
end
|
||||||
|
if skip
|
||||||
|
if ~contains(url,'.gif') && ~contains(url,'.jpg')
|
||||||
|
set(t2,'string',sprintf('skip: %s',url))
|
||||||
|
drawnow
|
||||||
|
if get(slow,'value')
|
||||||
|
pause(.25)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
% Check if page is already in url list.
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for k = find(hash(1:m) == hashfun(url))'
|
||||||
|
if isequal(U{k},url)
|
||||||
|
i = k;
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
% Add a new url to the graph there if are fewer than n.
|
||||||
|
|
||||||
|
if (i == 0) && (m < n)
|
||||||
|
m = m+1;
|
||||||
|
U{m} = url;
|
||||||
|
hash(m) = hashfun(url);
|
||||||
|
i = m;
|
||||||
|
end
|
||||||
|
|
||||||
|
% Add a new link.
|
||||||
|
|
||||||
|
if i > 0
|
||||||
|
G(i,j) = 1;
|
||||||
|
set(t2,'string',sprintf('%5d %s',i,url))
|
||||||
|
line(j,i,'marker','.','markersize',6)
|
||||||
|
drawnow
|
||||||
|
if get(slow,'value')
|
||||||
|
pause(.5)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
j = j+1;
|
||||||
|
end
|
||||||
|
delete(t1)
|
||||||
|
delete(t2)
|
||||||
|
delete(slow)
|
||||||
|
set(quit,'string','close','callback','close(gcf)','value',0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%------------------------
|
||||||
|
|
||||||
|
function h = hashfun(url)
|
||||||
|
% Almost unique numeric hash code for pages already visited.
|
||||||
|
h = length(url) + 1024*sum(url);
|
BIN
mp1/template.pdf
Normal file
BIN
mp1/template.pdf
Normal file
Binary file not shown.
31
mp1/template.tex
Normal file
31
mp1/template.tex
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
\documentclass[unicode,11pt,a4paper,oneside,numbers=endperiod,openany]{scrartcl}
|
||||||
|
|
||||||
|
\input{assignment.sty}
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
|
||||||
|
\setassignment
|
||||||
|
\setduedate{Thursday, 8 October 2020, 12:00 AM}
|
||||||
|
|
||||||
|
\serieheader{Numerical Computing}{2020}{Student: Claudio Maggioni}{Discussed with: --}{Solution for Project 1}{}
|
||||||
|
\newline
|
||||||
|
|
||||||
|
\assignmentpolicy
|
||||||
|
The purpose of this assignment\footnote{This document is originally based on a SIAM book chapter from \textsl{Numerical Computing with Matlab} from Clever B. Moler.} is to learn the importance of numerical linear algebra algorithms to solve fundamental linear algebra problems that occur in search engines.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\section{Page-Rank Algorithm }
|
||||||
|
|
||||||
|
\subsection{Theory [20 points]}
|
||||||
|
|
||||||
|
\subsection{Other webgraphs [10 points]}
|
||||||
|
|
||||||
|
\subsection{Connectivity matrix and subcliques [10 points]}
|
||||||
|
|
||||||
|
\subsection{Connectivity matrix and disjoint subgraphs [10 points]}
|
||||||
|
|
||||||
|
\subsection{PageRanks by solving a sparse linear system [50 points]}
|
||||||
|
|
||||||
|
|
||||||
|
\end{document}
|
BIN
mp1/usi_inf.pdf
Normal file
BIN
mp1/usi_inf.pdf
Normal file
Binary file not shown.
Reference in a new issue