Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 1 and Chapter 4 #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 127 additions & 80 deletions notebooks/SemiCircleLaw.ipynb
Original file line number Diff line number Diff line change
@@ -1,85 +1,132 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"using RandomMatrices"
]
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.0",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.0"
},
"colab": {
"name": "SemiCircleLaw.ipynb",
"provenance": []
}
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "9nKXerOM9_p_",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 130
},
"outputId": "fb35f8b0-f49b-4979-a8b3-2530cd1b7504"
},
"source": [
"using RandomMatrices"
],
"execution_count": 0,
"outputs": [
{
"output_type": "error",
"ename": "SyntaxError",
"evalue": "ignored",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-1-efe7167b7012>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m using RandomMatrices\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
]
},
{
"data": {
"text/html": [
"<script src=\"file:///Users/alanedelman/.julia/v0.6/Plots/src/backends/../../deps/plotly-latest.min.js\"></script> <div id=\"624c5082-2eeb-4b17-8de0-80522fa4e3c4\" style=\"width:600px;height:400px;\"></div>\n",
" <script>\n",
" PLOT = document.getElementById('624c5082-2eeb-4b17-8de0-80522fa4e3c4');\n",
" Plotly.plot(PLOT, [{\"xaxis\":\"x\",\"colorbar\":{\"title\":\"\"},\"yaxis\":\"y\",\"orientation\":\"v\",\"x\":[-1.95,-1.85,-1.75,-1.65,-1.55,-1.45,-1.35,-1.25,-1.15,-1.05,-0.95,-0.8500000000000001,-0.75,-0.6499999999999999,-0.55,-0.45,-0.35,-0.25,-0.15000000000000002,-0.05,0.05,0.15000000000000002,0.25,0.35,0.45,0.55,0.6499999999999999,0.75,0.8500000000000001,0.95,1.05,1.15,1.25,1.35,1.45,1.55,1.65,1.75,1.85,1.95],\"showlegend\":true,\"name\":\"y1\",\"marker\":{\"color\":[\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\"],\"line\":{\"width\":1}},\"y\":[0.07,0.12,0.15,0.16,0.21,0.22,0.24,0.26,0.27,0.25,0.3,0.29,0.28,0.31,0.29,0.32,0.31,0.32,0.31,0.31,0.33,0.3,0.32,0.33,0.31,0.3,0.29,0.3,0.29,0.27,0.28,0.26,0.25,0.23,0.23,0.2,0.18,0.15,0.13,0.06],\"type\":\"bar\",\"width\":[0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999998,0.09999999999999998,0.10000000000000009,0.09999999999999998,0.09999999999999998,0.09999999999999998,0.10000000000000003,0.09999999999999998,0.1,0.1,0.1,0.1,0.09999999999999998,0.10000000000000003,0.09999999999999998,0.09999999999999998,0.09999999999999998,0.10000000000000009,0.09999999999999998,0.09999999999999998,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009]},{\"showlegend\":true,\"mode\":\"lines\",\"xaxis\":\"x\",\"colorbar\":{\"title\":\"\"},\"line\":{\"color\":\"rgba(255, 0, 0, 1.000)\",\"shape\":\"linear\",\"dash\":\"solid\",\"width\":1},\"y\":[0.0,0.09939223010440976,0.1387480626605077,0.16768013734711915,0.19098593171027436,0.2105421996738962,0.22731872702791617,0.24189457115332305,0.25464790894703254,0.2658411660945885,0.27566444771089604,0.28425981769283604,0.29173582957799976,0.29817669031322924,0.3036482786292842,0.30820222203074993,0.31187872049347043,0.3147085270697081,0.3167143378597098,0.3179117498351263,0.3183098861837907,0.3179117498351263,0.3167143378597098,0.3147085270697081,0.31187872049347043,0.30820222203074993,0.3036482786292842,0.29817669031322924,0.29173582957799976,0.28425981769283604,0.27566444771089604,0.2658411660945885,0.25464790894703254,0.24189457115332305,0.22731872702791617,0.2105421996738962,0.19098593171027436,0.16768013734711915,0.1387480626605077,0.09939223010440976,0.0],\"type\":\"scatter\",\"name\":\"y2\",\"yaxis\":\"y\",\"x\":[-2.0,-1.9,-1.8,-1.7,-1.6,-1.5,-1.4,-1.3,-1.2,-1.1,-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0]}], {\"showlegend\":true,\"xaxis\":{\"showticklabels\":true,\"gridwidth\":0.5,\"tickvals\":[-2.0,-1.0,0.0,1.0,2.0],\"visible\":true,\"ticks\":\"inside\",\"range\":[-2.0,2.0],\"domain\":[0.05100612423447069,0.9934383202099737],\"tickmode\":\"array\",\"linecolor\":\"rgba(0, 0, 0, 1.000)\",\"showgrid\":true,\"title\":\"\",\"mirror\":false,\"tickangle\":0,\"showline\":true,\"gridcolor\":\"rgba(0, 0, 0, 0.100)\",\"titlefont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":15},\"tickcolor\":\"rgb(0, 0, 0)\",\"ticktext\":[\"-2\",\"-1\",\"0\",\"1\",\"2\"],\"zeroline\":false,\"type\":\"-\",\"tickfont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":11},\"zerolinecolor\":\"rgba(0, 0, 0, 1.000)\",\"anchor\":\"y\"},\"paper_bgcolor\":\"rgba(255, 255, 255, 1.000)\",\"annotations\":[],\"height\":400,\"margin\":{\"l\":0,\"b\":20,\"r\":0,\"t\":20},\"plot_bgcolor\":\"rgba(255, 255, 255, 1.000)\",\"yaxis\":{\"showticklabels\":true,\"gridwidth\":0.5,\"tickvals\":[0.0,0.1,0.2,0.30000000000000004],\"visible\":true,\"ticks\":\"inside\",\"range\":[0.0,0.33],\"domain\":[0.03762029746281716,0.9901574803149606],\"tickmode\":\"array\",\"linecolor\":\"rgba(0, 0, 0, 1.000)\",\"showgrid\":true,\"title\":\"\",\"mirror\":false,\"tickangle\":0,\"showline\":true,\"gridcolor\":\"rgba(0, 0, 0, 0.100)\",\"titlefont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":15},\"tickcolor\":\"rgb(0, 0, 0)\",\"ticktext\":[\"0.0\",\"0.1\",\"0.2\",\"0.3\"],\"zeroline\":false,\"type\":\"-\",\"tickfont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":11},\"zerolinecolor\":\"rgba(0, 0, 0, 1.000)\",\"anchor\":\"x\"},\"legend\":{\"bordercolor\":\"rgba(0, 0, 0, 1.000)\",\"bgcolor\":\"rgba(255, 255, 255, 1.000)\",\"font\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":11},\"y\":1.0,\"x\":1.0},\"width\":600});\n",
" </script>\n"
"cell_type": "code",
"metadata": {
"id": "Rm2dA00r9_qN",
"colab_type": "code",
"colab": {},
"outputId": "469becf9-834d-445e-a369-59a05d4cd706"
},
"source": [
"#semicircle.jl\n",
"#Algorithm 1.2 of Random Eigenvalues by Alan Edelman\n",
"\n",
"#Experiment: Sample random symmetric Gaussian matrices\n",
"#Plot: Histogram of the eigenvalues\n",
"#Theory: Semicircle as n->infinity\n",
"\n",
"using Plots\n",
"plotly()\n",
"\n",
"## Parameters\n",
"n = 1000\n",
"t = 1\n",
"\n",
"## Experiment\n",
"vals = Float64[] # initialize result vector\n",
"for i = 1:t\n",
" A = randn(n, n) # draw n by n matrix with idependent gaussians\n",
" S = (A + A')/2 # symmetrize matrix\n",
" vals = append!(vals, eigvals(S)) # calculate eigenvalues and append to result vector\n",
"end\n",
"vals /= √(n/2) # scale eigenvalues\n",
"\n",
" # set limits for x axis in plot\n",
"histogram(vals, xlim=(-2,2), nbins=50, normed=true ) # make histogram\n",
"xvals = -2:.1:2\n",
"plot!(xvals, sqrt.(4 - xvals.^2)/(2*π),color=:red) # plot semi circle"
],
"execution_count": 0,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<script src=\"file:///Users/alanedelman/.julia/v0.6/Plots/src/backends/../../deps/plotly-latest.min.js\"></script> <div id=\"624c5082-2eeb-4b17-8de0-80522fa4e3c4\" style=\"width:600px;height:400px;\"></div>\n",
" <script>\n",
" PLOT = document.getElementById('624c5082-2eeb-4b17-8de0-80522fa4e3c4');\n",
" Plotly.plot(PLOT, [{\"xaxis\":\"x\",\"colorbar\":{\"title\":\"\"},\"yaxis\":\"y\",\"orientation\":\"v\",\"x\":[-1.95,-1.85,-1.75,-1.65,-1.55,-1.45,-1.35,-1.25,-1.15,-1.05,-0.95,-0.8500000000000001,-0.75,-0.6499999999999999,-0.55,-0.45,-0.35,-0.25,-0.15000000000000002,-0.05,0.05,0.15000000000000002,0.25,0.35,0.45,0.55,0.6499999999999999,0.75,0.8500000000000001,0.95,1.05,1.15,1.25,1.35,1.45,1.55,1.65,1.75,1.85,1.95],\"showlegend\":true,\"name\":\"y1\",\"marker\":{\"color\":[\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\",\"rgba(0, 154, 250, 1.000)\"],\"line\":{\"width\":1}},\"y\":[0.07,0.12,0.15,0.16,0.21,0.22,0.24,0.26,0.27,0.25,0.3,0.29,0.28,0.31,0.29,0.32,0.31,0.32,0.31,0.31,0.33,0.3,0.32,0.33,0.31,0.3,0.29,0.3,0.29,0.27,0.28,0.26,0.25,0.23,0.23,0.2,0.18,0.15,0.13,0.06],\"type\":\"bar\",\"width\":[0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999998,0.09999999999999998,0.10000000000000009,0.09999999999999998,0.09999999999999998,0.09999999999999998,0.10000000000000003,0.09999999999999998,0.1,0.1,0.1,0.1,0.09999999999999998,0.10000000000000003,0.09999999999999998,0.09999999999999998,0.09999999999999998,0.10000000000000009,0.09999999999999998,0.09999999999999998,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.10000000000000009,0.09999999999999987,0.10000000000000009,0.09999999999999987,0.10000000000000009]},{\"showlegend\":true,\"mode\":\"lines\",\"xaxis\":\"x\",\"colorbar\":{\"title\":\"\"},\"line\":{\"color\":\"rgba(255, 0, 0, 1.000)\",\"shape\":\"linear\",\"dash\":\"solid\",\"width\":1},\"y\":[0.0,0.09939223010440976,0.1387480626605077,0.16768013734711915,0.19098593171027436,0.2105421996738962,0.22731872702791617,0.24189457115332305,0.25464790894703254,0.2658411660945885,0.27566444771089604,0.28425981769283604,0.29173582957799976,0.29817669031322924,0.3036482786292842,0.30820222203074993,0.31187872049347043,0.3147085270697081,0.3167143378597098,0.3179117498351263,0.3183098861837907,0.3179117498351263,0.3167143378597098,0.3147085270697081,0.31187872049347043,0.30820222203074993,0.3036482786292842,0.29817669031322924,0.29173582957799976,0.28425981769283604,0.27566444771089604,0.2658411660945885,0.25464790894703254,0.24189457115332305,0.22731872702791617,0.2105421996738962,0.19098593171027436,0.16768013734711915,0.1387480626605077,0.09939223010440976,0.0],\"type\":\"scatter\",\"name\":\"y2\",\"yaxis\":\"y\",\"x\":[-2.0,-1.9,-1.8,-1.7,-1.6,-1.5,-1.4,-1.3,-1.2,-1.1,-1.0,-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0]}], {\"showlegend\":true,\"xaxis\":{\"showticklabels\":true,\"gridwidth\":0.5,\"tickvals\":[-2.0,-1.0,0.0,1.0,2.0],\"visible\":true,\"ticks\":\"inside\",\"range\":[-2.0,2.0],\"domain\":[0.05100612423447069,0.9934383202099737],\"tickmode\":\"array\",\"linecolor\":\"rgba(0, 0, 0, 1.000)\",\"showgrid\":true,\"title\":\"\",\"mirror\":false,\"tickangle\":0,\"showline\":true,\"gridcolor\":\"rgba(0, 0, 0, 0.100)\",\"titlefont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":15},\"tickcolor\":\"rgb(0, 0, 0)\",\"ticktext\":[\"-2\",\"-1\",\"0\",\"1\",\"2\"],\"zeroline\":false,\"type\":\"-\",\"tickfont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":11},\"zerolinecolor\":\"rgba(0, 0, 0, 1.000)\",\"anchor\":\"y\"},\"paper_bgcolor\":\"rgba(255, 255, 255, 1.000)\",\"annotations\":[],\"height\":400,\"margin\":{\"l\":0,\"b\":20,\"r\":0,\"t\":20},\"plot_bgcolor\":\"rgba(255, 255, 255, 1.000)\",\"yaxis\":{\"showticklabels\":true,\"gridwidth\":0.5,\"tickvals\":[0.0,0.1,0.2,0.30000000000000004],\"visible\":true,\"ticks\":\"inside\",\"range\":[0.0,0.33],\"domain\":[0.03762029746281716,0.9901574803149606],\"tickmode\":\"array\",\"linecolor\":\"rgba(0, 0, 0, 1.000)\",\"showgrid\":true,\"title\":\"\",\"mirror\":false,\"tickangle\":0,\"showline\":true,\"gridcolor\":\"rgba(0, 0, 0, 0.100)\",\"titlefont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":15},\"tickcolor\":\"rgb(0, 0, 0)\",\"ticktext\":[\"0.0\",\"0.1\",\"0.2\",\"0.3\"],\"zeroline\":false,\"type\":\"-\",\"tickfont\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":11},\"zerolinecolor\":\"rgba(0, 0, 0, 1.000)\",\"anchor\":\"x\"},\"legend\":{\"bordercolor\":\"rgba(0, 0, 0, 1.000)\",\"bgcolor\":\"rgba(255, 255, 255, 1.000)\",\"font\":{\"color\":\"rgba(0, 0, 0, 1.000)\",\"family\":\"sans-serif\",\"size\":11},\"y\":1.0,\"x\":1.0},\"width\":600});\n",
" </script>\n"
]
},
"metadata": {
"tags": []
},
"execution_count": 32
}
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
},
{
"cell_type": "code",
"metadata": {
"id": "X4f5pRnA-DF5",
"colab_type": "code",
"colab": {}
},
"source": [
""
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "MTgZpHZ49_qj",
"colab_type": "code",
"colab": {}
},
"source": [
"import numpy"
],
"execution_count": 0,
"outputs": []
}
],
"source": [
"#semicircle.jl\n",
"#Algorithm 1.2 of Random Eigenvalues by Alan Edelman\n",
"\n",
"#Experiment: Sample random symmetric Gaussian matrices\n",
"#Plot: Histogram of the eigenvalues\n",
"#Theory: Semicircle as n->infinity\n",
"\n",
"using Plots\n",
"plotly()\n",
"\n",
"## Parameters\n",
"n = 1000\n",
"t = 1\n",
"\n",
"## Experiment\n",
"vals = Float64[] # initialize result vector\n",
"for i = 1:t\n",
" A = randn(n, n) # draw n by n matrix with idependent gaussians\n",
" S = (A + A')/2 # symmetrize matrix\n",
" vals = append!(vals, eigvals(S)) # calculate eigenvalues and append to result vector\n",
"end\n",
"vals /= √(n/2) # scale eigenvalues\n",
"\n",
" # set limits for x axis in plot\n",
"histogram(vals, xlim=(-2,2), nbins=50, normed=true ) # make histogram\n",
"xvals = -2:.1:2\n",
"plot!(xvals, sqrt.(4 - xvals.^2)/(2*π),color=:red) # plot semi circle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.0",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
]
}
Loading