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

CO923 Assignment 2

Henry Charlesworth
January 26, 2015

Generating the Laplacian


To generate the Laplacian, first I generated N random numbers between 0 and 2 representing the nodes distances
around the unit circle. As with the previous assignment I chose to use the GNU Scientific Library random number
generator. For each row i = 1 : N I set the row counter to 0, and for each j < i subtract the value L[i][j]. Then for
each j > i I compare whether the distance between node i and node j (in either direction around the unit circle) is
less than t = 5 . If it is then I set L[i][j] = L[j][i] = 1 and add one to the row counter. When the end of the row
is reached I then set L[i][i] equal to the row counter. This way means that you do not need to store the degree of
each node separately to construct the Laplacian.

Calculating the Eigenvalues


To find the eigenvalues of the Laplacian I made an implementation of the QR algorithm looked at in lectures. As
the Laplacian is symmetric it can be tridiagonalized by the application of Householder matrices (matrices of the
T
form P = 1 u H.u where u is a vector and H = 21 |u|2 ) without changing its eigenvalues. For the tridiagonalization
step the application of N-2 householder matrices is required, such that:
Ltri = PN 2 .PN 3 ...P2 .P1 .L.P1 .P2 ...PN 3 .PN 2
where each Pi removes all elements below the tridiagonal in column i and to the right of the tridiagonal in row i,
and are constructed as described in the notes from lecture 2. The application of these Householder transformations
can be significantly sped up by noting that for any Householder matrix P and arbitrary matrix A, P.A.P can be
uT .r
simplified in the following way. If we define r = A.u
H and the scalar K = 2H , then letting q = r Ku it can be
shown (section 11.2 of Numerical Recipes) that
P.A.P = A uT q qT u
The QR algorithm works by taking a matrix Ai and performing a decomposition Ai = Qi .Ri where Ri is upper
triangular and Qi is orthogonal, and then letting Ai+1 = Ri .Qi . This is iterated until Ai converges to a matrix
from which the eigenvalues can be easily extracted. It turns out that this is also equivalent to the application
of particular Householder transformations, i.e. Ai+1 = PN 1 .PN 2 ...P1 .Ai .P1 ...PN 2 .PN 1 . When the matrix is
tridiagonal the vector ui used to construct Pi has at most two non-zero components (ui [i] and ui [i + 1]), from
which it follows that the vector ri (and therefore also qi ) has at most 4 non-zero components (ri [i 1], ri [i], ri [i + 1]
and ri [i + 2]). This allows for an iteration of the QR algorithm to be applied to a tridiagonal matrix very efficiently.
Also as the matrix is symmetric it retains its tridiagonal form after the QR iteration.
Reading the first section of this paper (http://comjnl.oxfordjournals.org/content/8/1/85.full.pdf) it says provided
|i | = |j | only when i = j then Ai converge to upper-triangular form, and since Ai are real and symmetric
this means they in fact converge to diagonal form. We know that all the eigenvalues are real and because of
Gershgorins Circle Theorem we know that they are also all more than or equal to zero, and so this condition
holds. The code that I have written starts in the bottom right corner of the matrix (where the convergence of
non-diagonal elements to zero should be fastest) and waits until the absolute value of the element to the left of
the bottom right element is less than a given tolerance. At this point the bottom right element is approximately
an eigenvalue. The final row/column are then deleted (or rather ignored) and the process is repeated until all N
eigenvalues are found. This works and appears to give all of the eigenvalues correctly however it is also very slow
to converge (for 1 million 100x100 laplacians the code took about 10 hours to run, with a tolerance for convergence
of only 104 . The reason for this (I think) is that I have not used shifting of any sort, because when I attempt
to do so it no longer converges to a purely diagonal matrix. The shifting I tried to implement was to do the QR
decomposition on Ai ki 1 where ki is the bottom right element of the current Ai , and then let Ai+1 = Ri .Qi + ki 1.
Presumably it does converge to a matrix which is diagonal except for with block diagonal submatrices which could
then be treated separately. I expect that it would converge much more quickly than my current implementation,
1

however as I was just about able to get adequate results for the problem were looking at without having to modify
my code to account for this I decided it was easier to just not use shifting at all, and let the code run overnight!

Results
The eigenvalues calculated between 0 and 40 (fewer than 1000 out of the 100 million were higher than this, and
these were ignored) are then placed in to bins of length = 0.001. Because the resulting histogram has sharp
peaks at integer values of it is important that the bins are centred on the integer values, i.e. instead of having
for example the two bins 19.999-20.000 and 20.000-20.001 you need to have a bin covering 19.9995-20.0005. This
is because otherwise eigenvalues which mathematically are exactly 20 can be placed in two different bins due to
the finite accuracy of the eigenvalues obtained making some just below 20 and some just above. The histogram
is then normalized by calculating the area using the trapz function in MATLAB, and the results are attached
as a Mathematica notebook. There the histogram is compared with the function given on the assignment sheet
and we see that the peaks in the histogram are well approximated by the function as stated. As the nodes are
placed independently around the unit circle by symmetry the average degree of each node must be the same, and
we can calculate the average degree of a particular node by noting that the average fraction of nodes to which it
2
5
= 51 . This means that < k >= 20 as stated. Looking at the histogram we see that
is connected is given by 2
the highest peak is at 21 =< k > +1. A zoomed in plot of the histogram is also shown. The next part of the
Mathematica notebook has a comparison of the results I obtained from my code with the results I obtained in
MATLAB using the eig function (code for both is attached).

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