mp5: 3.3 correction
This commit is contained in:
parent
a3990dceb4
commit
34dc22c5b0
9 changed files with 111 additions and 28 deletions
Binary file not shown.
|
@ -20,7 +20,7 @@
|
|||
\setassignment
|
||||
\setduedate{Wednesday, December 02, 2020, 11:59 PM}
|
||||
|
||||
\serieheader{Numerical Computing}{2020}{Student: Claudio Maggioni}{Discussed with: --}{Solution for Project 5}{}
|
||||
\serieheader{Numerical Computing}{2020}{Student: Claudio Maggioni}{Discussed with: Gianmarco De Vita (3.3)}{Solution for Project 5}{}
|
||||
\newline
|
||||
|
||||
\assignmentpolicy
|
||||
|
@ -98,11 +98,7 @@ The plot of the squared residual 2-norms over all iterations can be found in Fig
|
|||
condition number and convergence rate.}
|
||||
|
||||
The eigenvalues of A can be found in figure
|
||||
\ref{fig:plot2}. The condition number for matrix $A$ according to \texttt{rcond(...)} is $\approx 3.2720 \cdot 10^7$,
|
||||
which is very low without sitting in the denormalized range (i.e. $< \text{eps}$) and thus very good for the Conjugate Gradient algorithm.
|
||||
This well conditioning is also
|
||||
reflected in the eigenvalue plot, which shows a not so
|
||||
drastic increase of the first eigenvalues ordered in increasing order.
|
||||
\ref{fig:plot2}.
|
||||
|
||||
\begin{figure}[h]
|
||||
\centering
|
||||
|
@ -110,6 +106,24 @@ drastic increase of the first eigenvalues ordered in increasing order.
|
|||
\caption{Semilog plot of the eigenvalues of A}\label{fig:plot2}
|
||||
\end{figure}
|
||||
|
||||
The condition number for matrix $A$ according to \texttt{cond(...)} is $\approx 1.3700 \cdot 10^6$,
|
||||
which is rather ill conditioned. The eigenvalue plot agrees with the condition number, by showing that there are significant differences in the magnitude of the eigenvalues of \texttt{A\_test}.
|
||||
|
||||
The two methods agree due to the fact that the condition number is computed by using singular values,
|
||||
which in turn are derived by eigenvalues. This fact was demonstrated practically by Dr. Edoardo Vecchi, \textit{future PhD}
|
||||
using this MATLAB snippet.
|
||||
|
||||
\begin{verbatim}
|
||||
X = A_test'*A_test;
|
||||
singular_values = sqrt(eig(X));
|
||||
norm(sort(singular_values,'descend') - svd(A_test))/numel(A_test)
|
||||
\end{verbatim}
|
||||
|
||||
The final norm is less than $10^{12}$, showning that the definition of
|
||||
\texttt{singular\_values}, which is a generalization of the computation of
|
||||
eigenvalues for rectangular matrices, is equivalent to MATLAB's \texttt{svd(...)} other than approximation errors.
|
||||
|
||||
|
||||
\section{Debluring problem [40 points]}
|
||||
\subsection{ Solve the debluring problem for the blurred image matrix
|
||||
\texttt{B.mat} and transformation matrix \texttt{A.mat} using
|
||||
|
|
78
mp5/Project_5_Maggioni_Claudio/code_template.m
Normal file
78
mp5/Project_5_Maggioni_Claudio/code_template.m
Normal file
|
@ -0,0 +1,78 @@
|
|||
close all;
|
||||
clear; clc;
|
||||
addpath /Users/maggicl/Git/matlab2tikz/src/;
|
||||
|
||||
%% Load Default Img Data
|
||||
load('blur_data/B.mat');
|
||||
B=double(B);
|
||||
load('blur_data/A.mat');
|
||||
A=double(A);
|
||||
|
||||
% Show Image
|
||||
figure
|
||||
im_l=min(min(B));
|
||||
im_u=max(max(B));
|
||||
imshow(B,[im_l,im_u])
|
||||
title('Blured Image')
|
||||
|
||||
% Vectorize the image (row by row)
|
||||
b=B';
|
||||
b=b(:);
|
||||
|
||||
AT = A' * A;
|
||||
bt = A' * b;
|
||||
|
||||
IL = ichol(AT, struct('type', 'nofill', 'diagcomp', 0.01));
|
||||
|
||||
[x, rvec] = myCG(AT, bt, zeros(size(b)), 200, 1e-6);
|
||||
[x2, ~, ~, ~, rvec2] = pcg(AT, bt, 1e-6, 200, IL, IL');
|
||||
|
||||
figure;
|
||||
semilogy(rvec / norm(bt));
|
||||
hold on;
|
||||
semilogy(rvec2 / norm(bt));
|
||||
hold off;
|
||||
title('Residual norms over iteration (y is log)')
|
||||
matlab2tikz('showInfo', false, '../res_log.tex');
|
||||
|
||||
|
||||
X = zeros(250, 250);
|
||||
for i = 0:249
|
||||
for j = 1:250
|
||||
X(i + 1, j) = x(i * 250 + j);
|
||||
end
|
||||
end
|
||||
|
||||
figure;
|
||||
im_l=min(min(X));
|
||||
im_u=max(max(X));
|
||||
imshow(X,[im_l,im_u])
|
||||
title('Sharp Image (myCG)')
|
||||
matlab2tikz('showInfo', false, '../img_my.tex');
|
||||
|
||||
|
||||
X2 = zeros(250, 250);
|
||||
for i = 0:249
|
||||
for j = 1:250
|
||||
X2(i + 1, j) = x2(i * 250 + j);
|
||||
end
|
||||
end
|
||||
|
||||
figure;
|
||||
im_l=min(min(X2));
|
||||
im_u=max(max(X2));
|
||||
imshow(X2,[im_l,im_u])
|
||||
title('Sharp Image (rcg)')
|
||||
matlab2tikz('showInfo', false, '../img_rcg.tex');
|
||||
|
||||
|
||||
|
||||
%% Validate Test values
|
||||
load('test_data/A_test.mat');
|
||||
load('test_data/x_test_exact.mat');
|
||||
load('test_data/b_test.mat');
|
||||
|
||||
%res=||x^*-A^{-1}b||
|
||||
res=x_test_exact-inv(A_test)*b_test;
|
||||
norm(res);
|
||||
%(Now do it with your CG and Matlab's PCG routine!!!)
|
BIN
mp5/img_my-1.png
BIN
mp5/img_my-1.png
Binary file not shown.
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
@ -7,8 +7,8 @@ width=1.736in,
|
|||
height=1.736in,
|
||||
at={(0.75in,0.653in)},
|
||||
scale only axis,
|
||||
point meta min=-0.0235938830592792,
|
||||
point meta max=0.99393991750956,
|
||||
point meta min=-0.0268505831942635,
|
||||
point meta max=1.01130200411968,
|
||||
axis on top,
|
||||
xmin=0.5,
|
||||
xmax=250.5,
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 58 KiB |
|
@ -7,8 +7,8 @@ width=1.736in,
|
|||
height=1.736in,
|
||||
at={(0.75in,0.653in)},
|
||||
scale only axis,
|
||||
point meta min=0.0282583971491394,
|
||||
point meta max=0.921555841989536,
|
||||
point meta min=-0.0235938830592792,
|
||||
point meta max=0.99393991750956,
|
||||
axis on top,
|
||||
xmin=0.5,
|
||||
xmax=250.5,
|
||||
|
|
8
mp5/submit.sh
Executable file
8
mp5/submit.sh
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
PID="5"
|
||||
dname="Project_${PID}_Maggioni_Claudio"
|
||||
zname="Project_${PID}_Maggioni_Claudio"
|
||||
|
||||
rm -v $zname.zip
|
||||
zip $zname.zip *.tex *.sty usi_inf.pdf $zname.{pdf,tex} $dname/blur_data/*.mat $dname/test_data/*.mat $dname/*.m
|
|
@ -12,7 +12,7 @@ scale only axis,
|
|||
xmin=0,
|
||||
xmax=180,
|
||||
ymode=log,
|
||||
ymin=1e-12,
|
||||
ymin=1e-08,
|
||||
ymax=1000000,
|
||||
yminorticks=true,
|
||||
axis background/.style={fill=white},
|
||||
|
@ -183,23 +183,6 @@ title={Residual vector squared 2-norm (log) over iterations}
|
|||
160 1.65115695649721e-06\\
|
||||
161 2.09460062061473e-06\\
|
||||
162 5.05915189772462e-07\\
|
||||
163 1.32841240174248e-07\\
|
||||
164 1.28360359603615e-06\\
|
||||
165 1.43607180361307e-05\\
|
||||
166 5.04094734598852e-06\\
|
||||
167 7.41197749055341e-06\\
|
||||
168 5.04948498688418e-07\\
|
||||
169 1.54446803267932e-08\\
|
||||
170 1.81444161747323e-07\\
|
||||
171 8.78831793802036e-08\\
|
||||
172 1.53613965535421e-06\\
|
||||
173 2.81415884074516e-06\\
|
||||
174 4.43530815074645e-07\\
|
||||
175 2.7224336876613e-08\\
|
||||
176 1.43297134609307e-06\\
|
||||
177 1.62527199539552e-09\\
|
||||
178 2.50972491576067e-10\\
|
||||
179 1.74075823612926e-11\\
|
||||
};
|
||||
\end{axis}
|
||||
\end{tikzpicture}%
|
Reference in a new issue