13d ago

5 Views

0 Downloads

709.40 KB

8 Pages

Transcription

1/21/2016RandomMatrixTheoryHintsPythonRandom Matrix Theory(Sethna, "Entropy, Order Parameters, and Complexity", ex. 1.6, developed with Piet Brouwer)This is an ipython notebook. This hints file is unusually detailed. If you are familiar with Mathematica, feelfree to skip parts you don't need, or start your own notebooks.Lectures about Python, useful both for beginners and experts, can be found at http://scipylectures.github.io (http://scipy-lectures.github.io).I recommend installing the Anaconda ) distribution.Go to https://www.continuum.io/downloads (https://www.continuum.io/downloads)Pick your operating system (Windows, Mac OS X, Linux)Follow instructions for Python 3.5.To make it run much faster (probably necessary for some assignments):Be sure not to pay for it! Get an academic subscription, using your Cornell (.edu) e-mail, onda-academic-subscriptions-available)Set up an account, using your Cornell e-mailGo to My Settings under your name in the upper right hand side of the Anaconda Cloudwindow, andGo to Add Ons, the lowest menu entry in the left-hand columnDownload the licenses, and follow the installation instructions link just above the MKL licencebutton (or go to p://docs.continuum.io/advanced-installation))Open the notebook by (1) copying this file into a directory, (2) in that directory typing:ipython notebookand (3) selecting the notebook. In later exercises, if you do animations, you may choose to not have theplots inline.Like Mathematica, you type in commands and then hit 'Shift Return' to execute domMatrixTheoryHintsPython.html1/8

1/21/2016RandomMatrixTheoryHintsPythonIn [ ]: a 3.print(a)Python is not a complete scientific environment. Functions like log, sin, and exp are provided by externalpackages. The plotting package pylab supports many of these; '%pylab inline' puts the graphs into thenotebook. We usually want more functionality than that, so we import a package called 'scipy' (anextension of 'numpy'). We'll also be using some of their linear algebra routines, which are in a subpackage 'scipy.linalg'.In [ ]: %pylab inlinefrom scipy import *One of the most active and unusual applications of ensembles is random matrix theory, used to describephenomena in nuclear physics, mesoscopic quantum mechanics, and wave phenomena. Random matrixtheory was invented in a bold attempt to describe the statistics of energy level spectra in nuclei. In manycases, the statistical behavior of systems exhibiting complex wave phenomena -- almost anycorrelations involving eigenvalues and eigenstates -- can be quantitatively modeled using ensembles ofmatrices with completely random, uncorrelated entries!The most commonly explored ensemble of matrices is the Gauusian orthogonal ensemble (GOE).Generating a member takes two steps:Generate an NxN matrix whose elements are independent Gaussian distributions of zero meanand standard deviation.Add the matrix to its transpose to symmetrize it.Start by finding out how Python generates random numbers. Type ?random to find out about scipy'srandom number generators.Try typing 'random.random()' a few times. Try calling it with an integer argument. Use 'hist' (reallypylab.hist) to make a histogram of 1000 numbers generated by random.random. Is the distributionGaussian, uniform, or exponential? The flag 'normed' tells us to not just count the number of occurencesin each bin, but to divide by the width of the bin and the number of counts (to approximate a normalizedprobability distribution).In [ ]: ))hist(random.random(1000), normed ndomMatrixTheoryHintsPython.html2/8

1/21/2016RandomMatrixTheoryHintsPythonUse random.standard normal to generate a Gaussian distribution of one thousand random numbers.Check that it is a standard Gaussianby using 'hist'.In [ ]: print(random.standard normal(.))hist(random.standard normal(.), normed .);x 2),'r')show()One final matrix operation. To generate a symmetric matrix of the GOE form, we'll want to add a matrixto its transpose. Generate a 2x3 matrix of normally distributed random numbers, and print it and itstranspose.In [ ]: m random.standard normal((2,3));print(m)print(transpose(m))Now define a function GOE(N) (using 'def') which generates a GOE NxN matrix.In [ ]: def GOE(N):"""Creates an NxN element of the Gaussian Orthogonal Ensemble,by creating an NxN matrix of Gaussian random variablesusing the random array function random.standard normal([shape])with [shape] (N,N).and adding it to its transpose (applying transpose to the matrix)#Typing GOE(4) a few times, check it's symmetric and random"""m random. .((.,.))m m transpose(m)return mTest it by generating a 4x4 matrix. Is it symmetric?In [ ]: ndomMatrixTheoryHintsPython.html3/8

1/21/2016RandomMatrixTheoryHintsPythonNow write a function GOE Ensemble(num, N) generating an ensemble (a long list with 'num' elements) ofGOE NxN matrices. Call GOE(N) to fill the list.In [ ]: def GOE Ensemble(num, N):"""Creates a list "ensemble" of length num of NxN GOE matrices.#You can start with an empty list, and fill it with 'append'ensemble []for n in range(num):ensemble.append(GOE(N))return ensembleor you can use the convenient 'list comprehension'ensemble [GOE(N) for n in range(num)]#Check GOE Ensemble(3,2) gives 3 2x2 symmetric matrices"""ensemble .return ensembleHere you may want to generate an ensemble, and check if the diagonal elements and the off-diagonalelements have different standard deviations, as you calculated in part (c). (This difference is part of thedefinition of the GOE ensemble, and is needed to make the ensemble rotation invariant.)One of the most striking properties that large random matrices share is the distribution of level splittings.To look at eigenvalues of our symmetric matrices, we use 'eigvalsh'. We'll want them sorted. And we'llwant to find the difference between the two middle-most eigenvalues.Notice, in python, arrays are indexed lambda [lambda[0], ., lambda[N-1]], so the middle two are N/2and N/2-1. Note that in the new version of python dividing integers 4/2 2.0 gives a floating pointnumber, so we need to use N//2 to get an integer. (This is a good thing: having 2/10 0 causes lots ofproblems when you write routines that don't know whether their inputs are floats or ints.)In [ ]: N 4midpoint int(N/2)mat GOE(N)print(mat)eig andomMatrixTheoryHintsPython.html4/8

1/21/2016RandomMatrixTheoryHintsPythonIn [ ]: def CenterEigenvalueDifferences(ensemble):"""For each symmetric matrix in the ensemble, calculates the differencebetween the two center eigenvalues of the ensemble, and returnsthedifferences as an array.#Given an ensemble of symmetric matrices,finds their size N, using the first member ensemble[0]len(m) gives the number of rows in mstarts with an empty list of differencesfor each m in ensemblefinds the eigenvalueseigvals(m) gives the eigenvalues of msorts themsort(e) sorts a list from smallest to largestappends eigenvalue[N/2] - eigenvalue[N/2-1] to the list(Note: python lists go from 0 . N-1, so for N 2 thisgives the difference between the only two eigenvalues)#Checkensemble GOE gives three positive numbers, that look like eigenvalues of the2x2 matrices"""# Size of matrixN len(.)diffs []# Note that you can 'iterate' not only over integers, but overelements of a list (for mat in ensemble: .)for mat in ensemble:eigenvalues sort(.)diffs.append(.)return diffsCheck thatensemble GOE gives three positive numbers, that look like eigenvalue differences of 2x2 matrices, Check thathist(CenterEigenvalueDifferences(ensemble), bins 30, normed True);gives three spikes at the three eigenvalue hon/RandomMatrixTheoryHintsPython.html5/8

1/21/2016RandomMatrixTheoryHintsPythonIn [ ]: ensemble GOE st(CenterEigenvalueDifferences(.), bins 50, normed True);Now try it with 10000 or more. Notice the smooth distribution, with a linear tail near zero.In [ ]: M 10000N 2ensemble GOE Ensemble(M, N);diffs CenterEigenvalueDifferences(ensemble)hist(diffs, bins 50, normed True);What is this dip in the eigenvalue splitting probability near zero? It is called level repulsion.Wigner's surmise (meaning 'guess') was that this distribution was universal, that is, independent of theensemble of matrices. Clearly another ensemble, with all our matrix elements multiplied by two, will haveeigenvalue differences twice as big. Wigner surmised that the eigenvalue differences, divided by themean of the differences would be universal. Plot these normalized centered differences against youranalytical prediction for 2x2 matrices (see text), which should beIn [ ]: hist(diffs/mean(diffs), bins 50, normed True);s arange(0.,3.,0.01)rhoWigner .plot(s, rhoWigner, 'r');title('2x2 matrix eig diffs')Try N 4 and N 10; do they look similar?In [ ]: M 10000N 4ensemble .diffs .hist(.);plot(.);title(.)In [ ]: M 10000N 10ensemble .diffs l6/8

1/21/2016RandomMatrixTheoryHintsPythonNote that we're typing the same commands several times. This is a bad programming practice (a 'badsmell') -- whenever writing the same code more than a couple of lines long, write it as a subroutine. Thatway, when you fix an error, it'll get fixed everywhere you use it.In [ ]: def CompareEnsembleWigner(ensemble):diffs r 2x2 formula is pretty good, but turns out to be up to 2% off for larger matrices; Wigner was wrongabout that. But he was correct that the eigenvalue splitting is universal, if you consider large matrices.We can test this by trying a different ensemble. For example, let's try random symmetric matrices filledwith -1. In the past, we've created these matrices the hard way. But let's just take the signs of thematrix elements generated by the GOE ensemble!In [ ]: sign(GOE Ensemble(4,3))Define a PM1 ensemble (Plus or Minus 1)In [ ]: def PM1 Ensemble(num, N):"""Generates a -1 ensemble, as for GOE Ensemble above.Use with CompareEnsembleWigner to test that N 2 looks differentfrom the Wigner ensemble, but larger N looks close to the GOE ensemble.#This is a powerful truth: the eigenvalue differences of very general classesof symmetric NxN matrices all have the same probability distributionas N goes to infinity. This is what we call universality."""return sign(.)Try comparing the splittings for 2x2 matrices with the prediction.In [ ]: CompareEnsembleWigner(PM1 62/Python/RandomMatrixTheoryHintsPython.html7/8

1/21/2016RandomMatrixTheoryHintsPythonIs it well approximated by the Wigner surmise? Why not? (Hint: how many different symmetric 2x2matrices ofare there?)Try it with 4x4 and 10x10 matrices.In [ ]: CompareEnsembleWigner(.)10x10 should work better, except for a funny bump at zero.In [ ]: CompareEnsembleWigner(.)The GOE ensemble has some nice statistical properties (see text).This is our first example of an emergent symmetry. Many different ensembles of symmetric matrices, asthe sizegoes to infinity, have eigenvalue and eigenvector distributions that are invariant underorthogonal transformations even though the original matrix ensemble did not have this symmetry.Similarly, rotational symmetry emerges in random walks on the square lattice as the number of stepsgoes to infinity, and also emerges on long length scales for Ising models at their critical thon/RandomMatrixTheoryHintsPython.html8/8