01 Vectors and Linear Algebra Fundamentals
լուսանկարի հղումը, Հեղինակ՝ Suren Sargsyan
📚 Նյութը
- 📚 Ամբողջական նյութը
- 📺 Տեսագրությունը (ToDo)
- 🎞️ Սլայդեր - Vectors ToDo
- 🎞️ Սլայդեր - Geometry ToDo
- 🛠️📺 Գործնականի տեսագրությունը ToDo
- 🛠️🗂️ Գործնականի PDF-ը ToDo
ToDo
🏡 Տնային
- ❗❗❗ DON’T CHECK THE SOLUTIONS BEFORE TRYING TO DO THE HOMEWORK BY YOURSELF❗❗❗
- Please don’t hesitate to ask questions, never forget about the 🍊karalyok🍊 principle!
- The harder the problem is, the more 🧀cheeses🧀 it has.
- Problems with 🎁 are just extra bonuses. It would be good to try to solve them, but also it’s not the highest priority task.
- If the problem involve many boring calculations, feel free to skip them - important part is understanding the concepts.
- Submit your solutions here (even if it’s unfinished)
Vector Operations
01 RGB color mixing with vectors
Consider these RGB color vectors:
- Red: \(\vec{r} = (255, 0, 0)\)
- Cyan: \(\vec{c} = (0, 255, 255)\)
- Calculate what color you get by adding red and cyan: \(\vec{r} + \vec{c}\).
- Find the “average” color between red and cyan: \(\frac{1}{2}(\vec{r} + \vec{c})\).
- Use a color picker to verify your answers from parts (a) and (b). What colors do you actually see?
02 Dot product
A translation office translated \(a = [24, 17, 9, 13]\) documents from English, French, German and Russian, respectively. For each of those languages, it takes about \(b = [5, 10, 11, 7]\) minutes to translate one page. How much time did they spend translating in total? How much did each of the translators spend on average if there are 4 translators in the office? Write an expression for this amount in terms of the vectors \(a\) and \(b\).
03 Feature vector normalization
A customer is represented by the vector \(\vec{v} = (25, 50000, 3)\) where components represent [age, income in $, number of purchases].
- Calculate the Euclidean norm (magnitude) \(||\vec{v}||_2\)
- Find the unit vector \(\hat{v} = \frac{\vec{v}}{||\vec{v}||_2}\)
- Verify that \(||\hat{v}||_2 = 1\)
Note: No need to carry out the calculations explicitly.
04 Triangle inequality
For vectors \(\vec{u} = (3, 4)\) and \(\vec{v} = (5, -12)\):
- Calculate \(||\vec{u}||\), \(||\vec{v}||\), and \(||\vec{u} + \vec{v}||\)
- Verify the triangle inequality: \(||\vec{u} + \vec{v}|| \leq ||\vec{u}|| + ||\vec{v}||\)
- When does equality hold in the triangle inequality?
05 Model selection with regularization
Վստահ չեմ որ լավ եմ ձևակերպել (հատկապես) էս խնդիրը , եթե հարցեր լինեն՝ խաբար արեք։
You’re comparing two models that predict house prices:
- Model A: Complex formula with weights (coefficients) \(\vec{w_A} = (10, -8, 4)\) (this can correspond to equation (\(10x^2 - 8x + 4\) (quadratic))) and prediction error = 100
- Model B: Simpler formula with weights \(\vec{w_B} = (0.1, -3, 1)\) \((0.1x^2 - 3x + 1)\) (almost just a linear function) and prediction error = 120
Model B makes slightly worse predictions, but which model is better when considering both error and simplicity?
- L1 Regularization (λ = 0.5): Calculate the total error for each model
- Model A: \(\text{Error} + \lambda \cdot ||\vec{w_A}||_1 = ?\)
- Model B: \(\text{Error} + \lambda \cdot ||\vec{w_B}||_1 = ?\)
- L2 Regularization (λ = 0.5): Calculate the total error for each model
- Model A: \(\text{Error} + \lambda \cdot ||\vec{w_A}||_2^2 = ?\)
- Model B: \(\text{Error} + \lambda \cdot ||\vec{w_B}||_2^2 = ?\)
- Model Selection: Which model would you choose under each regularization method? How does the choice of \(\lambda\) affect your decision?
- Practical Insight: In production systems, why might we prefer a model with slightly worse accuracy but much simpler weights?
06 k-Nearest Neighbors Classification
Կցված կգտնեք csv ֆայլ երեք սյունով՝ feature_1, feature_2, label։ Կարող եք պատկերացնել որ feature_1-ը իրանից ներկայացնում ա ծաղկի բարձրությունը, feature_2-ը՝ լայնությունը ու label (պիտակը) ներկայացնում ա թե 4 ծաղկի տեսակներից (0,1,2,3) որ մեկն ա։
Պետք ա ստեղծել մոդել (ալգորիթմ) որը ստանալով feature_1, feature_2 արժեքները կգուշակի ծաղկի տեսակը։
Հետևյալ կերպով՝ նոր ծաղկի համար գտնել K հատ ամենամոտիկ ծաղիկները մեր ունեցած տվյալներից ու նայել թե էդ k հարևաններից որ տեսակի ծաղիկն ա գերակշռում՝ ու դա օգտագործել որպես գուշակություն,
Հեռավորություն որպես օգտագործեք մի դեպքում L1-ը (Manhattan), մի դեպքում L2-ը (Euclidean): K-ի համար էլ տարբեր արժեքներ բզբացեք՝ 2,3, 5, 10 .
Թեթև հավելյալ նշումներ 1. Ալգորիմթի անունն ա K Nearest Neighbors ու զուտ “ասա ինձ ովքեր են քո ընկերները, ես կասեմ ով ես դու” սկզբումքով ա աշխատում, պրակտիկայում համարյա երբեք չի օգտագործվում բայց տնայինի համար կարա հավես լինի 2. Պատճառներից մեկը թե ինչի չի օգտագործվում դա “Չափողականության անեծքն” ա (Curse of dimenionality), շատ հավես էֆեկտ ա ըստ որի երբ գործ ենք ունենում բարձր չափանի տարածությունների հետ, տվյալները հիմնականում իրարից համարյա հավասարահեռ են դառնում ու անկյուններում են կուտակվում (այլ կերպ ասած՝ եթե բարձրաչափ նարինջը կլպենք՝ տակը բան չի մնա)։ Աղբյուր (https://slds-lmu.github.io/i2ml/chapters/14_cod/)
Մնացածը կարաք անտեսեք դեռ
04: Similarity measurement
Two user preference vectors are \(\vec{u_1} = (5, 3, 1, 4)\) and \(\vec{u_2} = (3, 5, 2, 2)\) where each component represents rating for different movie genres.
- Calculate the dot product \(\vec{u_1} \cdot \vec{u_2}\)
- Calculate the cosine similarity: \(\cos(\theta) = \frac{\vec{u_1} \cdot \vec{u_2}}{||\vec{u_1}|| \cdot ||\vec{u_2}||}\)
- What does a cosine similarity close to 1 indicate about user preferences?
04.5: Word embeddings similarity
ToDo
06: Finding perpendicular vectors
Given the vector \(\vec{v} = (2, 3)\):
- Find a non-zero vector \(\vec{w} = (x, y)\) such that \(\vec{v}\) and \(\vec{w}\) are perpendicular.
- Verify that your chosen vector \(\vec{w}\) satisfies \(\vec{v} \cdot \vec{w} = 0\).
- Find a unit vector in the direction of \(\vec{w}\) by computing \(\frac{\vec{w}}{||\vec{w}||}\).
- Explain why there are infinitely many vectors perpendicular to \(\vec{v}\) and describe the general form of all such vectors.
08: Deriving the cosine angle formula
Derive the formula for the cosine of the angle between two vectors: \(\cos(\theta) = \frac{\vec{a} \cdot \vec{b}}{||\vec{a}|| \cdot ||\vec{b}||}\)
- Write down the law of cosines for the triangle with sides \(||\vec{a}||\), \(||\vec{b}||\), and \(||\vec{a} - \vec{b}||\)
- Express \(||\vec{a} - \vec{b}||^2\) in terms of dot products by expanding \((\vec{a} - \vec{b}) \cdot (\vec{a} - \vec{b})\)
- Substitute your result from part (2) into the law of cosines and solve for \(\cos(\theta)\)
- Verify your derived formula using vectors \(\vec{u} = (3, 4)\) and \(\vec{v} = (1, 0)\)
Geometric Interpretation
21: High-dimensional vector geometry
In high-dimensional spaces (common in ML), our intuition about geometry can be misleading.
Consider the unit sphere in \(\mathbb{R}^n\) (all vectors with norm 1):
- In 2D, what fraction of a unit square \([-1,1] \times [-1,1]\) is occupied by the unit circle?
- Estimate this fraction for a unit cube in 3D
- Research: What happens to this fraction as the dimension \(n\) increases? This is known as the “curse of dimensionality.”
🛠️ Գործնական ToDo
🎲 38 (01) TODO
- ▶️ToDo
- 🔗Random link
- 🇦🇲🎶ToDo
- 🌐🎶ToDo
- 🤌Կարգին