Fix typos and math errors in notebooks
This commit is contained in:
@@ -6,17 +6,17 @@
|
||||
"source": [
|
||||
"# QR Decompositions\n",
|
||||
"\n",
|
||||
"QR decompositions are a powerful tool in linear algebra and data science for several reasons. They provide a way to decompose a matrix into an orthogonal matrix $Q$ aand an upper triangular matrix $R$, which can simplify many computations and analyses.\n",
|
||||
"QR decompositions are a powerful tool in linear algebra and data science for several reasons. They provide a way to decompose a matrix into an orthogonal matrix $Q$ and an upper triangular matrix $R$, which can simplify many computations and analyses.\n",
|
||||
"\n",
|
||||
"> **Theorem**: Let $A$ is an $m \\times n$ matrix with linearly independent columns ($m \\geq n$ in this case), then $A$ can be decomposed as $A = QR$ where $Q$ is an $m \\times n$ matrix whose columns form an orthonormal basis for Col($A$) and $R$ is an $n \\times n$ upper-triangular invertible matrix with positive entries on the diagonal.\n",
|
||||
"> **Theorem**: Let $A$ be an $m \\times n$ matrix with linearly independent columns ($m \\geq n$ in this case), then $A$ can be decomposed as $A = QR$ where $Q$ is an $m \\times n$ matrix whose columns form an orthonormal basis for Col($A$) and $R$ is an $n \\times n$ upper-triangular invertible matrix with positive entries on the diagonal.\n",
|
||||
"\n",
|
||||
"In the literature, sometimes the QR decomposition is phrased as follows: any $m \\times n$ matrix $A$ can also be written as $A = QR$ where $Q$ is an $m \\times m$ orthogonal matrix ($Q^T = Q^{-1}$), and $R$ is an $m \\times n$ upper-triangular matrix. One follows from the other by playing around with some matrix equations. Indeed, suppose that $A = Q_1R_1$ is a decomposition as above (that is, $Q_1$ is $m \\times n$ and $R_1$ is $n \\times n$). Use can use the Gram-Schmidt procedure to extend the columns of $Q_1$ to an orthonormal basis for all of $\\mathbb{R}^m$, and put the remaining vectors in a $(m - n) \\times n$ matrix $Q_2$. Then\n",
|
||||
"In the literature, sometimes the QR decomposition is phrased as follows: any $m \\times n$ matrix $A$ can also be written as $A = QR$ where $Q$ is an $m \\times m$ orthogonal matrix ($Q^T = Q^{-1}$), and $R$ is an $m \\times n$ upper-triangular matrix. One follows from the other by playing around with some matrix equations. Indeed, suppose that $A = Q_1R_1$ is a decomposition as above (that is, $Q_1$ is $m \\times n$ and $R_1$ is $n \\times n$). We can use the Gram-Schmidt procedure to extend the columns of $Q_1$ to an orthonormal basis for all of $\\mathbb{R}^m$, and put the remaining vectors in an $m \\times (m-n)$ matrix $Q_2$. Then\n",
|
||||
"\n",
|
||||
"$$ A = Q_1R_1 = \\begin{bmatrix} Q_1 & Q_2 \\end{bmatrix}\\begin{bmatrix} R_1 \\\\ 0 \\end{bmatrix}. $$\n",
|
||||
"\n",
|
||||
"The left matrix is an $m \\times m$ orthogonal matrix and the right matrix is $m \\times n$ upper triangular. Moreover, the decomposition provides orthonormal bases for both the column space of $A$ and the perp of the column space of $A$; $Q_1$ will consist of an orthonormal basis for the column space of $A$ and $Q_2$ will consist of an orthonormal basis for the perp of the column space of $A$. \n",
|
||||
"\n",
|
||||
"However, we will often want to use the decomposition when $Q$ is $m \\times n$, $R$ is $n \\times n$, and the columns of $Q$ form an orthonormal basis for the column space of $A$. For example, the python function `numpy.linalg.qr` give QR decompositions this way (again, assuming that the columns of $A$ are linearly independent, so $m \\geq n$).\n",
|
||||
"However, we will often want to use the decomposition when $Q$ is $m \\times n$, $R$ is $n \\times n$, and the columns of $Q$ form an orthonormal basis for the column space of $A$. For example, the Python function `numpy.linalg.qr` gives QR decompositions this way (again, assuming that the columns of $A$ are linearly independent, so $m \\geq n$).\n",
|
||||
"\n",
|
||||
"> **Key take-away**. The QR decomposition provides an orthonormal basis for the column space of $A$. If $A$ has rank $k$, then the first $k$ columns of $Q$ will form a basis for the column space of $A$. \n",
|
||||
"\n",
|
||||
@@ -254,7 +254,7 @@
|
||||
"\n",
|
||||
"> **Example**. Working with the matrix\n",
|
||||
"> $$ A = \\begin{bmatrix} 1 & 0 & 0 \\\\ 1 & 1 & 0 \\\\ 1 & 1 & 1 \\\\ 1 & 1 & 1 \\end{bmatrix}, $$\n",
|
||||
"> the projection onto the column space if given by\n",
|
||||
"> the projection onto the column space is given by\n",
|
||||
"> $$ QQ^T = \\begin{bmatrix} 1 \\\\ & 1 \\\\ & & \\frac{1}{2} & \\frac{1}{2} \\\\ & & \\frac{1}{2} & \\frac{1}{2} \\end{bmatrix}. $$\n",
|
||||
"> This is a well-understood projection: it is the direct sum of the identity on $\\mathbb{R}^2$ and the projection onto the line $y = x$ in $\\mathbb{R}^2$.\n",
|
||||
"\n",
|
||||
@@ -299,11 +299,9 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"cell_type": "markdown",
|
||||
"id": "d26b49a6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"array([[1.00000000e+00, 2.89687929e-17, 2.89687929e-17, 2.89687929e-17],\n",
|
||||
" [2.89687929e-17, 1.00000000e+00, 7.07349921e-17, 7.07349921e-17],\n",
|
||||
@@ -351,7 +349,7 @@
|
||||
"> $$ P = A(A^TA)^{-1}A^T. $$\n",
|
||||
"> Indeed, let $b \\in \\mathbb{R}^n$ and let $x_0 \\in \\mathbb{R}^p$ be a solution to the normal equations\n",
|
||||
"> $$ A^TAx_0 = A^Tb. $$\n",
|
||||
"> Then $x_0 = (A^TA)^{-1}A^Tb$ and so $Ax_0 = A(A^TA^{-1})A^Tb$ is the (unique!) vector in the column space of $A$ which is closest to $b$, i.e., the projection of $b$ onto the column space of $A$.\n",
|
||||
"> Then $x_0 = (A^TA)^{-1}A^Tb$ and so $Ax_0 = A(A^TA)^{-1}A^Tb$ is the (unique!) vector in the column space of $A$ which is closest to $b$, i.e., the projection of $b$ onto the column space of $A$.\n",
|
||||
"> However, taking transposes, multiplying, and inverting is not what we would like to do numerically. "
|
||||
]
|
||||
},
|
||||
@@ -503,7 +501,7 @@
|
||||
"> and note that\n",
|
||||
"> $$ A = U_rDV_r^T. $$\n",
|
||||
"> We call this the reduced singular value decomposition of $A$. Note that $D$ is invertible, and its inverse is simply\n",
|
||||
"> $$ D = \\begin{bmatrix} \\sigma_1^{-1} \\\\ & \\sigma_2^{-1} \\\\ & & \\ddots \\\\ & & & \\sigma_r^{-1} \\end{bmatrix}. $$\n",
|
||||
"> $$ D^{-1} = \\begin{bmatrix} \\sigma_1^{-1} \\\\ & \\sigma_2^{-1} \\\\ & & \\ddots \\\\ & & & \\sigma_r^{-1} \\end{bmatrix}. $$\n",
|
||||
"> The **pseudoinverse** (or **Moore-Penrose inverse**) of $A$ is the matrix\n",
|
||||
"> $$ A^+ = V_rD^{-1}U_r^T. $$\n",
|
||||
"\n",
|
||||
@@ -656,7 +654,7 @@
|
||||
"> $$ \\kappa(A) = 1 \\text{ and } \\kappa(B) = 10^6. $$\n",
|
||||
"> Inverting $X_2$ includes dividing by $\\frac{1}{10^6}$, which will amplify errors by $10^6$.\n",
|
||||
"\n",
|
||||
"Let's look our main example in python by using `numpy.linalg.cond`. \n",
|
||||
"Let's look at our main example in Python by using `numpy.linalg.cond`. \n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
@@ -680,7 +678,7 @@
|
||||
"# Create a pandas DataFrame\n",
|
||||
"df = pd.DataFrame(data)\n",
|
||||
"\n",
|
||||
"# Create out matrix X\n",
|
||||
"# Create our matrix X\n",
|
||||
"X = df[['Square ft', 'Bedrooms']].to_numpy()\n",
|
||||
"\n",
|
||||
"# Check the condition number\n",
|
||||
|
||||
Reference in New Issue
Block a user