commit dcda02c5164c315aecffd8d536395ec66adeef27
parent 4df9d61b008b4060625c2d64cff1108257a1cbd2
Author: Andrew <andrewlaack1@gmail.com>
Date: Tue, 30 Jul 2024 14:17:38 -0500
Took most of my notes
Diffstat:
4 files changed, 154 insertions(+), 5 deletions(-)
diff --git a/Kernels.md b/Kernels.md
@@ -1 +0,0 @@
-:todo:
diff --git a/LinearAlgebra.md b/LinearAlgebra.md
@@ -52,3 +52,5 @@ Khan Unit 2:
- [[DiagonalMatrices.md]]
- [[Rotation.md]]
- [[StandardMatrix.md]]
+ - [[UnitVector.md]]
+ - [[Projection.md]]
diff --git a/Projection.md b/Projection.md
@@ -1,10 +1,129 @@
-:ml:
+:ml: :lin-alg:
# Projection
-ML D5
+ML D5 / Khan
-## Notes
+## Notes (mostly ml)
**Definition:** Projection is the process of moving an element from higher dimensional space to a lower dimensional space.
Projection is often used to reduce dimensionallity of datasets as data becomes more sparse in higher dimensions.
+
+## Linear Algebra Specifics
+
+The Proj_L(x) = vector \in L where x - Proj_L(x) is orthogonal to L.
+
+This states the difference between the projection and the original vector is orthogonal to the line (dot produce = 0).
+
+Let's define v as some vector on L. We then know the projection of x onto L is cv for some coeficcient c. This coefficient can be found as described below.
+
+Finding:
+
+1. Take dot product between vector v on line L and our original vector x
+2. Divide result by ||v|| to find c
+3. Find the vector p which is v scaled to length of c
+
+Example:
+
+L = <2,1>
+x = <2,3>
+v = <2,1> (arbitrary on L)
+
+Find dot product:
+x dot v = 4 + 3 = 7
+
+Find length of v:
+||v|| = sqrt(5)
+
+Find length of projected vector (dot product / ||v||):
+l = 7 / sqrt(5) = 3.13
+
+Scale v to be projection:
+//it is not necessary to create a unit vector, but easier conceptually
+vhat = <2,1> x 1/sqrt(5)
+vhat = <.894, .447>
+
+p = vhat x l
+= <.894,.447> x 3.13
+= <2.798, 1.399>
+
+Code:
+
+```python3
+
+# Define vector class with init, length, standardize, multiply by scalar, and print
+import math
+
+class Vector3d:
+ def __init__(self, x, y, z):
+ self.x = x
+ self.y = y
+ self.z = z
+
+ def length(self):
+ return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
+
+ def standardized(self):
+ len = self.length()
+ scaleFactor = 1/len
+ return Vector3d(self.x * scaleFactor, self.y * scaleFactor, self.z * scaleFactor)
+
+ def __mul__(self, scalar):
+ return Vector3d(self.x * scalar, self.y*scalar, self.z * scalar)
+
+ def __repr__(self):
+ return('x: ' + str(self.x) + '\ny: ' + str(self.y) + '\nz: ' + str(self.z))
+
+# Initialize vector to project
+v = Vector3d(2,3,1)
+
+# Initialize vector to project onto
+u = Vector3d(3,10,2)
+
+# Find DP
+dp = v.x * u.x + v.y * u.y + v.z * u.z
+
+# Find length of projected onto
+uLen = u.length()
+
+# Find projected vector's length
+projLen = dp / uLen
+
+# Scale u to length projLen
+standardU = u.standardized()
+projected = standardU * projLen
+
+print(projected)
+
+# Output:
+
+# x: 1.008849557522124
+# y: 3.362831858407079
+# z: 0.6725663716814159
+
+```
+
+## Matrix Representation
+
+A projection is a L.T. and thus it can be expressed by a matrix.
+
+Additionally, given our knowledge about L.Ts we know that Proj(a + b) = Proj(a) + Proj(b) and that Proj(ca) = cProj(a).
+
+To find the matrix we use the same identity matrix strategy where we find the columns based on their mapping from the identity matrix to the output of the L.T.
+
+Example:
+
+// Projection onto
+u = <2,1>
+
+// Identity matrix
+[1 0]
+[0 1]
+
+// This can be calculated using the above strategy, but I used my code to find this
+Proj_u(<1,0>) = <.8,.4>
+Proj_u(<0,1>) = <.4,.2>
+
+// Standard Matrix of L.T. based on identity matrix column inputs
+[.8 .4]
+[.4 .2]
diff --git a/UnitVector.md b/UnitVector.md
@@ -1,8 +1,37 @@
:lin-alg:
-# Unit Vector
+# Unit Vector (Normalized Vector)
Khan
## Notes
**Definition:** A unit vector is any vector with length of 1.
+
+It is true that ||u|| = 1 when u is a unit vector, in all cases.
+
+Additionally, it is common practice to add a hat to unit vectors. As such, a hatted vector implies length of 1.
+
+Commonly we use ihat, jhat, and khat in 3d space where they are each orthogonal and denote some interesting information like right, forward, and up either relative to some object or in global space.
+
+## Construction
+
+To construct a unit vector from any other vector (with same direction) do the following:
+
+1. Find length of v (sqrt(x_1^2 + x_2^2 + ... + x_n^2))
+2. Multiply each component by one over the length of v
+
+Example (sorry for formatting but not worth my time):
+
+[4]
+[7] = u
+[9]
+
+||u|| = sqrt(16 + 49 + 81)
+= sqrt(146)
+= 12.083
+
+[4] [.331]
+[7] x (1/12.083) = [.579]
+[9] [.745]
+
+ = $\hat u$