Skip to content

Commit

Permalink
Merge pull request #81 from u-siri-ous/main
Browse files Browse the repository at this point in the history
Corrected typos in 02_math_recap_linear_algebra.ipynb
  • Loading branch information
iacopomasi authored Mar 5, 2024
2 parents c9e127b + 70dc6d9 commit 57dbfa6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
" [ 0. 1. ]\n",
" [ 2. -3. ]]\n",
"Shape (3, 2)\n",
"Number of dimension: 2\n",
"Number of dimensions: 2\n",
"Number of elements: 6\n"
]
}
Expand Down Expand Up @@ -305,9 +305,9 @@
"that people often take of vectors: as directions in space.\n",
"Not only can we think of the vector $\\mathbf{v} = [3,2]^\\top$\n",
"as the location $3$ units to the right and $2$ units up from the origin,\n",
"we can also think of it as the direction itself\n",
"We can also think of it as the direction itself\n",
"to take $3$ steps to the right and $2$ steps up.\n",
"In this way, we consider all the vectors in figure the same.\n",
"In this way, we consider all the vectors in the figure the same.\n",
"<img src=\"https://raw.githubusercontent.com/d2l-ai/d2l-en/master/img/par-vec.svg\" width=\"30%\">"
]
},
Expand All @@ -322,7 +322,7 @@
"## Direction in space\n",
"\n",
"One of the benefits of this shift is that\n",
"we can make visual sense of the act of vector addition.\n",
"We can make visual sense of the act of vector addition.\n",
"In particular, we follow the directions given by one vector,\n",
"and then follow the directions given by the other, as is seen below (rule of the parallelogram).\n",
"\n",
Expand Down Expand Up @@ -564,7 +564,7 @@
],
"source": [
"print(A,end='\\n\\n')\n",
"# Possible to do reduction on the matrix (sum along rows)\n",
"# Possible to do a reduction on the matrix (sum along rows)\n",
"A_c = A.sum(axis=0, keepdims=False) # 3 (rows are canceled out)\n",
"A_c.shape\n",
"print(A_c)"
Expand Down Expand Up @@ -592,7 +592,7 @@
],
"source": [
"# Works for other operations too like mean (average)\n",
"A.mean(axis=0, keepdims=False) # 3 (rows are canceled out)"
"A.mean(axis=0, keepdims=False) # 3 (rows are cancelled out)"
]
},
{
Expand Down Expand Up @@ -762,7 +762,7 @@
"source": [
"# Sum all the values across cols (cols will disappear)\n",
"# Sum all values across axis 1.\n",
"A.sum(axis=1, keepdims=False) #3 (cols are canceled out)"
"A.sum(axis=1, keepdims=False) #3 (cols are cancelled out)"
]
},
{
Expand Down Expand Up @@ -811,7 +811,7 @@
],
"source": [
"# Works for other operations too like mean (average)\n",
"A.mean(axis=0, keepdims=True) #1x3 (rows are canceled out but row axis is NOT dropped)"
"A.mean(axis=0, keepdims=True) #1x3 (rows are cancelled out but row axis is NOT dropped)"
]
},
{
Expand Down Expand Up @@ -853,7 +853,7 @@
"- The result is a **scalar** (not a vector anymore).\n",
"- Must be in the same dimension\n",
"- It is **commutative**\n",
"- The data is **paired**: just multiply elementwise and sum across axis."
"- The data is **paired**: just multiply elementwise and sum across the axis."
]
},
{
Expand Down Expand Up @@ -966,7 +966,7 @@
"$$\n",
"\n",
"- What happens if cosine similarity is 1?\n",
"- Notice any similarity with some concept we saw in previous lecture?"
"- Notice any similarity with some concept we saw in the previous lecture?"
]
},
{
Expand Down Expand Up @@ -1000,7 +1000,7 @@
"- Input can have different dimensions. The output is $D \\times P$ dimensional.\n",
"- It is **NOT commutative**\n",
"- The data is not paired $\\rightarrow$ compute all combinations.\n",
"- Very Important to build matrices from the ground-up: complex matrix is the **sum of outer products (sum of rank-1 matrices).**"
"- Very Important to build matrices from the ground-up: a complex matrix is the **sum of outer products (sum of rank-1 matrices).**"
]
},
{
Expand Down Expand Up @@ -1380,7 +1380,7 @@
"source": [
"#### Indexes (or variables):\n",
"- **Free indexes** are $i,j$ if you see the are specified in the output. They are in the input but they are let \"free\" in the output\n",
"- **Summation indexes** are all those that are not preserve in the output, $k$ in this case."
"- **Summation indexes** are all those that are not preserved in the output, $k$ in this case."
]
},
{
Expand Down Expand Up @@ -1475,7 +1475,7 @@
"\n",
"Suppose we have two arrays, A and B. Now suppose that we want to:\n",
"\n",
"- **multiply** **A** with **B** in a particular way to create new array of products, and then maybe\n",
"- **multiply** **A** with **B** in a particular way to create a new array of products, and then maybe\n",
"- **sum** this new array along particular axes, and/or\n",
"\n",
"<ins>Taken from https://ajcr.net/Basic-guide-to-einsum/</ins>"
Expand Down Expand Up @@ -1539,7 +1539,7 @@
"B = np.array([[ 0, 1, 2, 3], # 0\n",
" [ 4, 5, 6, 7], # 1\n",
" [ 8, 9, 10, 11]]) # 2\n",
"A[:, np.newaxis] * B # we wanna do this np.newaxis is brod cast and tells \n",
"A[:, np.newaxis] * B # we wanna do this np.newaxis is broad cast and tells \n",
" # numpy to put A as col vector"
]
},
Expand Down Expand Up @@ -1629,7 +1629,7 @@
"np.einsum('i,ij->i', A, B) #3 X 3x4 --> 3\n",
"\n",
"```\n",
"- we di not need to reshape A at all and, \n",
"- we do not need to reshape A at all and, \n",
"- most importantly, the multiplication did not create a temporary array like `A[:, np.newaxis] * B` did. Instead, einsum simply summed the products along the rows as it went. Even for this tiny example, I timed einsum to be about three times faster.\n"
]
},
Expand Down Expand Up @@ -1956,7 +1956,7 @@
}
},
"source": [
"### 4. Direction where to move to minimize loss (Gradients, Deep Learning)"
"### 4. Give the direction where to move to minimize loss (Gradients, Deep Learning)"
]
},
{
Expand Down Expand Up @@ -2098,7 +2098,7 @@
}
},
"source": [
"# Matrices as linear map between spaces\n",
"# Matrices as a linear map between spaces\n",
"\n",
"- Do **NOT** think of a matrix as a bunch of random points.\n",
"- We have to start thinking **matrices as linear functions that map a space into another space**.\n",
Expand Down Expand Up @@ -2370,7 +2370,7 @@
" src = np.stack((Xs, Ys), axis=2)\n",
" # flatten first two dimension\n",
" # (NN)x2\n",
" # ask reshape to keep last dimension and adjust the rest\n",
" # ask to reshape to keep the last dimension and adjust the rest\n",
" src_r = src.reshape(-1, src.shape[-1])\n",
" # 2x2 @ 2x(NN)\n",
" dst = A @ src_r.T # 2xNN\n",
Expand Down Expand Up @@ -2635,7 +2635,7 @@
"\n",
"and show that $\\mathbf{C}$ has rank two $\\mathrm{rank}(C)=2$ since, for instance,\n",
"the first two columns are linearly independent,\n",
"however any of the four collections of three columns are dependent."
"However any of the four collections of three columns are dependent."
]
},
{
Expand All @@ -2651,7 +2651,7 @@
"We have seen above that multiplication by a matrix with linearly dependent columns\n",
"cannot be undone, i.e., there is no inverse operation that can always recover the input. However, multiplication by a full-rank matrix\n",
"(i.e., some $\\mathbf{A}$ that is $n \\times n$ matrix with rank $n$),\n",
"we should always be able to undo it. Consider the matrix\n",
"We should always be able to undo it. Consider the matrix\n",
"\n",
"$$\n",
"\\mathbf{I} = \\begin{bmatrix}\n",
Expand All @@ -2666,7 +2666,7 @@
"We call this the *identity* matrix.\n",
"It is the matrix which leaves our data unchanged when applied.\n",
"To find a matrix which undoes what our matrix $\\mathbf{A}$ has done,\n",
"we want to find a matrix $\\mathbf{A}^{-1}$ such that\n",
"We want to find a matrix $\\mathbf{A}^{-1}$ such that\n",
"\n",
"$$\n",
"\\mathbf{A}^{-1}\\mathbf{A} = \\mathbf{A}\\mathbf{A}^{-1} = \\mathbf{I}.\n",
Expand Down Expand Up @@ -2807,7 +2807,7 @@
"\\end{bmatrix},\n",
"$$\n",
"\n",
"we can see with some computation that the area\n",
"We can see with some computation that the area\n",
"of the resulting parallelogram is $ad-bc$.\n",
"This area is referred to as the *determinant*."
]
Expand All @@ -2824,9 +2824,9 @@
"\n",
"![The matrix $\\mathbf{A}$ again distorting the grid. This time, I want to draw particular attention to what happens to the highlighted square.](https://raw.githubusercontent.com/d2l-ai/d2l-en/master/img/grid-transform-filled.svg)\n",
"\n",
"**Sanity Check:** We cannot apply Pythagoras Theorem to compute area because axis are not aligned anymore.\n",
"**Sanity Check:** We cannot apply Pythagoras Theorem to compute area because axes are not aligned anymore.\n",
"\n",
"The picture is misleading since axis are **CLOSED to be aligned**.\n",
"The picture is misleading since the axis is **CLOSED to be aligned**.\n",
"\n",
"The angle between $[1, -1]$ and $[2,3]$ is 101.30993247402021\n",
"```python import numpy as np; X = np.array([[1, -1], [2, 3]]);thetarad = angle(X[0,:],X[1,:]);theta = thetarad*180/np.pi; print(theta)}}\n",
Expand Down Expand Up @@ -2854,7 +2854,7 @@
"# Determinant $\\rightarrow$ tells how the space is compressed\n",
"\n",
"- Determinant is 0, compresses the space and loses a dimension (area zero)\n",
"- Determinant $\\geq$ 0 moves the space (area is non zero)\n",
"- Determinant $\\geq$ 0 moves the space (the area is non zero)\n",
"- Determinant $\\leq$ 0 moves the space and flips it (area is non zero but flips the order)\n",
"\n",
"> A matrix $A$ is invertible if and only if\n",
Expand Down Expand Up @@ -2937,7 +2937,7 @@
"\n",
"- Projection must be on unit vector $\\alpha\\cdot\\mathbf{\\hat{w}}$\n",
"- How long in this direction? $\\alpha=\\mathbf{\\hat{w}}^T \\mathbf{v}$ that gives the length of **v** onto **w**.\n",
"- **$\\mathbf{w}$** can be also a matrix not a vector (matrix which columns are vectors)."
"- **$\\mathbf{w}$** can be also a matrix, not a vector (matrix which columns are vectors)."
]
}
],
Expand Down
24 changes: 12 additions & 12 deletions CONTRIBUTORS_AA2324.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57dbfa6

Please sign in to comment.