class: center, middle, inverse, title-slide .title[ # Critical points, optimization, and matrices ] .author[ ###
MACS 33000
University of Chicago ] --- # Misc * Gradescope: grading underway -- should be all OK * Academic Integrity: workshop upcoming * MACSS Orientation 9/23 (expect notices re: scheduling, etc.) * JCLIP OH in classroom until 4pm Mon-Thurs! --- # Learning objectives * Define and calculate critical points and inflection points * Calculate higher order derivatives * Demonstrate optimization using maximum likelihood estimation and gradient descent * Linear vs matrix algebra!! * Define vector and matrix --- # Fermat's interior extremum theorem * Suppose `\(f:[a, b] \rightarrow \mathbb{R}\)` and is differentiable on c. * Suppose `\(f\)` has a relative maximum or minimum on `\((a,b)\)` and call that `\(c \in (a, b)\)` * Then `\(f'(c) = 0\)` -- .pull-left[ <img src="04-critical-points_files/figure-html/rolles-theorem-1.png" alt="" width="85%" style="display: block; margin: auto;" /> ] .pull-right[ * Fermat's theorem guarantees that, at some point, `\(f^{'}(c) = 0\)` * Intuition from proof - what happens as we approach from the left? * Intuition from proof - what happens as we approach from the right? ] --- # Higher order derivatives Conceptually, we are thinking about changes (get excited for all the *moments* you're going to have in stats later!). The first derivative tells us about the rate of change of our function. -- **BUT!** we can also explore how fast the derivative is changing...that is, the rate of change for our rate of change. Here, we can understand the acceleration of change. We can keep going (provided our function is differentiable). --- # Higher order derivatives (in other words:) * Derivatives of derivatives * First derivative `$$f'(x), ~~ y', ~~ \frac{d}{dx}f(x), ~~ \frac{dy}{dx}$$` * Second derivative `$$f''(x), ~~ y'', ~~ \frac{d^2}{dx^2}f(x), ~~ \frac{d^2y}{dx^2}$$` * `\(n\)`th derivative `$$\frac{d^n}{dx^n}f(x), \quad \frac{d^ny}{dx^n}$$` --- # Higher order derivatives Example: Suppose we start with a function: `\(x^3\)` -- let's explore the different derivatives we might take. Try it out! -- $$ `\begin{aligned} f(x) &=x^3\\ f^{\prime}(x) &=3x^2\\ f^{\prime\prime}(x) &=6x \\ f^{\prime\prime\prime}(x) &=6\\ f^{\prime\prime\prime\prime}(x) &=0\\ \end{aligned}` $$ * If `\(f(x)\)` is differentiable, then it is also continuous * If `\(f'(x)\)` is differentiable, then f is also **continuously differentiable** * Note: these run one direction only. * Continuous does not imply differentiable: `\(|x|\)` at `\(x=0\)` * Continuously differentiable does not imply `\(f'\)` is differentiable: `\(x|x|\)` at `\(x=0\)` * Analytical optimization requires differentiation --- # Inflection point Inflection points are where we move from being concave down to concave up (or vice versa). <img src="04-critical-points_files/figure-html/concave-inf-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Inflection point > For a given function `\(y = f(x)\)`, a point `\((x^*, y^*)\)` where the second derivative immediately on one side of the point is signed oppositely to the second derivative immediately on the other side <img src="04-critical-points_files/figure-html/inflect-1.png" alt="" width="85%" style="display: block; margin: auto;" /> ``` ## $ncol ## [1] 1 ## ## $nrow ## list() ## attr(,"class") ## [1] "waiver" ## ## $byrow ## list() ## attr(,"class") ## [1] "waiver" ## ## $widths ## list() ## attr(,"class") ## [1] "waiver" ## ## $heights ## list() ## attr(,"class") ## [1] "waiver" ## ## $guides ## list() ## attr(,"class") ## [1] "waiver" ## ## $tag_level ## list() ## attr(,"class") ## [1] "waiver" ## ## $axes ## list() ## attr(,"class") ## [1] "waiver" ## ## $axis_titles ## list() ## attr(,"class") ## [1] "waiver" ## ## $design ## list() ## attr(,"class") ## [1] "waiver" ## ## attr(,"class") ## [1] "plot_layout" ``` --- # Inflection point: example function > For a given function `\(y = f(x)\)`, a point `\((x^*, y^*)\)` where the second derivative immediately on one side of the point is signed oppositely to the second derivative immediately on the other side Let's start with a basic plot: here, we have a function: `\(\frac{x^3}{15} - x^2 + 4x +2\)`. We can see where we might guess there are the concave up / down points and where the inflection point might be. <img src="04-critical-points_files/figure-html/inflect-1-1.png" alt="" width="75%" height="75%" style="display: block; margin: auto;" /> --- # Inflection point <!-- Let's now consider the same function, but the derivative. We are expecting THE VALUE OF CHANGE (AKA RATE OF CHANGE TO BE ZERO). GREEN: where the derivative (change) is positive or negative. GRAY: point where we don't see any more change (rate of change = 0). --> <img src="04-critical-points_files/figure-html/inflect-deriv0-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- ### Derivative of original function: Let's now consider the same function, but the derivative. We are expecting THE VALUE OF CHANGE (AKA RATE OF CHANGE TO BE ZERO). GREEN: where the derivative (change) is positive or negative. GRAY: point where we don't see any more change (rate of change = 0). `\(f'(x)= \frac{x^2}{5}-2x+4\)`, `\(f''(x)= 0.4x-2\)`. <img src="04-critical-points_files/figure-html/inflect-deriv1-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Inflection point > For a given function `\(y = f(x)\)`, a point `\((x^*, y^*)\)` where the second derivative immediately on one side of the point is signed oppositely to the second derivative immediately on the other side <img src="04-critical-points_files/figure-html/inflect-all-1.png" alt="" width="85%" style="display: block; margin: auto;" /> ``` ## $ncol ## [1] 1 ## ## $nrow ## list() ## attr(,"class") ## [1] "waiver" ## ## $byrow ## list() ## attr(,"class") ## [1] "waiver" ## ## $widths ## list() ## attr(,"class") ## [1] "waiver" ## ## $heights ## list() ## attr(,"class") ## [1] "waiver" ## ## $guides ## list() ## attr(,"class") ## [1] "waiver" ## ## $tag_level ## list() ## attr(,"class") ## [1] "waiver" ## ## $axes ## list() ## attr(,"class") ## [1] "waiver" ## ## $axis_titles ## list() ## attr(,"class") ## [1] "waiver" ## ## $design ## list() ## attr(,"class") ## [1] "waiver" ## ## attr(,"class") ## [1] "plot_layout" ``` --- # Concavity * Concave up (convex) * Concave down (concave) * Verification * Graphically * Analytically --- # Concavity * Where a function is twice differentiable over some area, then the function is concave down where `\(f''(x) < 0\)` and concave up where `\(f''(x) > 0\)` What does this mean? -- * A critical point when f'(x)=0 has potential for some kind of concavity (sometimes, but not always! (`\(x^3\)`)). * We are then moving away from that point and we're either *increasing* (min - concave up) or *decreasing* (max - concave down). * If we're increasing through the critical point, the second derivative is positive, `\(f''(x) > 0\)`. * If we're decreasing through the critical point, the second derivative is negative, `\(f''(x) < 0\)`. --- # Concavity * Where a function is twice differentiable and concave over some area, then the function is **concave down where `\(f''(x) < 0\)`** and where `\(f''(x) > 0\)` is **concave up**. Recall: `\(f(x)=(x^3 - 15 * x^2 + 60 * x + 30) / 15\)`. <img src="04-critical-points_files/figure-html/concave-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Exponential function .pull-left[ <img src="04-critical-points_files/figure-html/strict-e-1.png" alt="" width="85%" style="display: block; margin: auto;" /> ] .pull-right[ Exploring change: <font size="2"> $$ `\begin{aligned} f(x) & = e^{x} \text{ (what the function is doing?)}\\ f^{'}(x) & = e^{x} \text{ rate of change (never zero!)} \\ f^{''}(x) & = e^{x} \text{ rate of change of rate of change} \\ & \text{ (still never zero!)} \end{aligned}` $$ </font> ] --- # Natural logarithm .pull-left[ <img src="04-critical-points_files/figure-html/strict-log-1.png" alt="" width="85%" style="display: block; margin: auto;" /> ] .pull-right[ Exploring change: <font size="2"> $$ `\begin{aligned} f(x) & = \ln(x) \\ \\ f^{'}(x) & = \frac{1}{x} \\ & \text{ rate of change (always positive (above 0))*}\\ \\ f^{''}(x) & = -\frac{1}{x^2} \\ & \text{ rate of change of rate of change} \end{aligned}` $$ </font> \* .tiny[note that `\(\ln(x)\)` is only defined for `\(x > 0\)`] ] --- # Types of extreme values * Maximum or minimum * Local or global -- *You can find these graphically or analytically* --- # Types of extreme values: Examples How would we evaluate the extreme values here? <img src="04-critical-points_files/figure-html/endpoints-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Types of extreme values: Examples How would we evaluate the extreme values here? <img src="04-critical-points_files/figure-html/endpoints2-1.png" alt="" width="25%" style="display: block; margin: auto;" /> * Derivative of the function: `\(f'(x) = 1\)` * Set to zero and solve. (n/a) * Options: * Plug in values to original function to find corresponding f(x). (only evaluate at end points (0 and 5)) * Find second derivative to see if positive (min) or negative (max) [not informative] --- # Types of extreme values: Examples Try with a neighbor: <img src="04-critical-points_files/figure-html/max-middle-1.png" alt="" width="864" style="display: block; margin: auto;" /> -- #### `\(f'(x) = -2x\)`; zero at `\(x=0\)`, `\(f(x) = -0^2+5=5\)`. But is it a max or min? -- Try adjacent point (e.g. -1 or 1). `\(f(-1) = (-(-1)^2+5)=4\)` OR take second derivative: `\(-2\)` -- Since 4 is less than 5, we know this is a max at x = 0, since `\(f(x = 0) > f(x=1)\)`. Similarly, the second derivative is negative, so this also indicates that it is a max (concave down from this point). --- # Types of extreme values <img src="04-critical-points_files/figure-html/min-middle-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Types of extreme values <img src="04-critical-points_files/figure-html/local-all-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Types of extreme values <img src="04-critical-points_files/figure-html/inflection-point-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- ### Function and derivative <img src="04-critical-points_files/figure-html/inflection-point-2-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Framework for analytical optimization 1. Find `\(f'(x)\)` 1. Set `\(f'(x)=0\)` and solve for `\(x\)`. Call all `\(x_0\)` such that `\(f'(x_0)=0\)` or `\(f'(x_0)\)` does not exist **critical points** 1. Find `\(f''(x_0)\)`. Evaluate at each `\(x_0\)` * If `\(f''(x_0) > 0\)`, concave up, and therefore a local minimum * If `\(f''(x_0) < 0\)`, concave down, and therefore a local maximum * If it's the global maximum/minimum, it will produce the largest/smallest value for `\(f(x)\)` * On a closed range along the domain, **check the endpoints as well** --- ### Ex: `\(f(x) = -x^2\)`, `\(x \in [-3, 3]\)` <img src="04-critical-points_files/figure-html/ex-1-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- ### Ex: `\(f(x) = x^3 - 6x-2\)`, `\(x \in [-3, 3]\)` <img src="04-critical-points_files/figure-html/ex-2-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- class: center, middle, inverse # CSS Application of optimization: MLE ### You aren't going to have to calculate this, but you need to understand the big picture --- # Maximum likelihood estimation * Likelihood function * Distinguish from probability * Known data, unknown parameters * Maximize to find the values located at the **global maximum** of the likelihood function --- # Maximum likelihood estimation $$ `\begin{aligned} f(\mu) & = \prod_{i=1}^{N} \exp( \frac{-(Y_{i} - \mu)^2}{ 2}) \\ & = \exp(- \frac{(Y_{1} - \mu)^2}{ 2}) \times \ldots \times \exp(- \frac{(Y_{N} - \mu)^2}{ 2}) \\ & = \exp( - \frac{\sum_{i=1}^{N} (Y_{i} - \mu)^2} {2}) \end{aligned}` $$ * Maximizing a function with very very very small numbers --- # Maximum likelihood estimation * Log-likelihood * `\(f:\mathbb{R} \rightarrow (0, \infty)\)` * If `\(x_{0}\)` maximizes `\(f\)`, then `\(x_{0}\)` maximizes `\(\log(f(x))\)` * Maximize the log-likelihood instead (easier math!) --- # Maximum likelihood estimation $$ `\begin{aligned} \log f(\mu) & = \log \left( \exp( - \frac{\sum_{i=1}^{N} (Y_{i} - \mu)^2} {2}) \right) \\ & = - \frac{\sum_{i=1}^{N} (Y_{i} - \mu)^2} {2} \\ & = -\frac{1}{2} \left(\sum_{i=1}^{N} Y_{i}^2 - 2\mu \sum_{i=1}^{N} Y_{i} + N\times\mu^2 \right) \\ \frac{ \partial \log f(\mu) }{ \partial \mu } & = -\frac{1}{2} \left( - 2\sum_{i=1}^{N} Y_{i} + 2 N \mu \right) \end{aligned}` $$ --- # Maximum likelihood estimation $$ `\begin{aligned} 0 & = -\frac{1}{2} \left( - 2 \sum_{i=1}^{N} Y_{i} + 2 N \mu^{*} \right) \\ 0 & = \sum_{i=1}^{N} Y_{i} - N \mu^{*} \\ N \mu^{*} & = \sum_{i=1}^{N}Y_{i} \\ \mu^{*} & = \frac{\sum_{i=1}^{N}Y_{i}}{N} \\ \mu^{*} & = \bar{Y} \end{aligned}` $$ --- # Maximum likelihood estimation * Second derivative test $$ `\begin{aligned} \frac{ \partial \log f(\mu) }{ \partial \mu } & = -\frac{1}{2} \left( - 2\sum_{i=1}^{N} Y_{i} + 2 N \mu \right) \\ \frac{ \partial \log f(\mu) }{ \partial \mu }& = \sum_{i=1}^{N} Y_{i} - N \mu \\ \frac{ \partial^2 \log f(\mu) }{ \partial \mu^2 }& = -N \end{aligned}` $$ -- * `\(-N<0 \leadsto \text{concave down}\)` --- # Maximum likelihood estimation: MLE in life Logit and other limited-dependent variable models: what parameter estimate makes the observed pattern most likely? * Simplest example: 0s and 1s as outcome * Trying to determine which value of `\(\beta\)` best predicts the outcomes observed --- class: inverse, middle, center # Optimization in CSS --- # Computational optimization procedures * Analytical approaches can be difficult/impossible * Computational approaches simplify the problem * Different algorithms available with benefits/drawbacks * Newton-Raphson (not covered) * Grid search * Gradient descent --- # Grid search * Often used in finetuning hyperparameters (e.g. structure of the model) * Exhaustive search algorithm * Define a specified set of `\(x_i\)` * Calculate `\(f(x_i) \forall i\)` * Compare all resulting values --- # Grid search `$$y = -x^2$$` * Evaluate the function for all `\(x \in \{ -2, -1.99, -1.98, \ldots, 1.98, 1.99, 2 \}\)` -- <img src="04-critical-points_files/figure-html/grid-search-1.png" alt="" width="85%" style="display: block; margin: auto;" /> <!-- <!-- --> <!-- # Analytically optimize --> <!-- $$ --> <!-- \begin{aligned} --> <!-- f'(x) &= 2.4x - 4.8 \\ --> <!-- 0 &= 2.4x - 4.8 \\ --> <!-- 4.8 &= 2.4x \\ --> <!-- x &= 2 --> <!-- \end{aligned} --> <!-- $$ --> <!-- -- --> <!-- $$ --> <!-- \begin{aligned} --> <!-- f''(x) &= 2.4 \\ --> <!-- f''(2) &= 2.4 --> <!-- \end{aligned} --> <!-- $$ --> <!-- --> --- # Gradient descent <img src="04-critical-points_files/figure-html/grad-ex-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Gradient descent `$$x_1 = x_0 - \alpha f'(x_0)$$` * Gradient * Learning rate * Iterative algorithm * Important components --- # `\(\alpha = 0.6\)` <img src="04-critical-points_files/figure-html/grad-descent-learn-rate-6-1.gif" alt="" width="85%" style="display: block; margin: auto;" /> --- # `\(\alpha = 0.1\)` <img src="04-critical-points_files/figure-html/grad-descent-learn-rate-2-1.gif" alt="" width="85%" style="display: block; margin: auto;" /> --- class: inverse, center, middle # STARTING THE PARTY: Matrices --- ## Example matrices We have two matrices: X and Y. `$$\begin{aligned}\mathbf{X} &= \left[ \begin{array}{rrr}1 & 2 & 3 \\ 2 & 1 & 4 \\ \end{array} \right] \\ \mathbf{Y} &= \left[ \begin{array}{rr} 1 & 2 \\ 3 & 2 \\ 1 & 4 \\ \end{array} \right] \end{aligned}$$` X has two rows and three columns, so is `\(2 \times 3\)`. Y has three rows and two columns, so is `\(3 \times 2\)`. -- Matrices are incredibly helpful, despite also being a bit challenging to get the hang of. We'll talk more about them tomorrow but you will want to note the dimensions of a matrix. You can do some operations with them (addition / subtraction) and they work the way you are probably guessing (need to be the same size). **MULTIPLICATION DOES NOT WORK THAT WAY! WARNING!!!** --- # Linear algebra * Data stored in **matrices** * Matrix algebra is the study of matrices and finite-dimensional vector spaces * Higher dimensional spaces * Flood of big data, stored in many dimensions * Linear algebra * Algebra of matrices * Geometry of high dimensional space * Calculus (multivariable) in many dimensions * Very important for regression/machine learning/deep learning --- # Points and vectors * A point in `\(\mathbb{R}^1\)` * `\(1\)` * `\(\pi\)` * `\(e\)` -- * An ordered pair in `\(\mathbb{R}^2 = \mathbb{R} \times \mathbb{R}\)` * `\((1,2)\)` * `\((0,0)\)` * `\((\pi, e)\)` -- * An ordered triple in `\(\mathbb{R}^3 = \mathbb{R} \times \mathbb{R} \times \mathbb{R}\)` * `\((3.1, 4.5, 6.1132)\)` -- * An ordered `\(n\)`-tuple in `\(\mathbb{R}^n = \mathbb{R} \times \mathbb{R} \times \ldots \times \mathbb{R}\)` * `\((a_{1}, a_{2}, \ldots, a_{n})\)` --- # One dimensional example <img src="04-critical-points_files/figure-html/one-d-1.png" alt="" width="85%" style="display: block; margin: auto;" /><img src="04-critical-points_files/figure-html/one-d-2.png" alt="" width="85%" style="display: block; margin: auto;" /><img src="04-critical-points_files/figure-html/one-d-3.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Two dimensional example <img src="04-critical-points_files/figure-html/two-d-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Two dimensional example <img src="04-critical-points_files/figure-html/two-d2-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Two dimensional example <img src="04-critical-points_files/figure-html/two-d3-1.png" alt="" width="85%" style="display: block; margin: auto;" /> --- # Three dimensional example * (Latitude, Longitude, Elevation) * `\((1,2,3)\)` * `\((0,1,2)\)` -- ## `\(N\)`-dimensional example * Individual campaign donation records `$$\mathbf{x} = (1000, 0, 10, 50, 15, 4, 0, 0, 0, \ldots, 24000000)$$` * Proportion of county vote for Trump `$$\mathbf{y} = (0.8, 0.5, 0.6, \ldots, 0.2)$$` * Run experiment, assess feeling thermometer of elected official `$$\mathbf{t} = (0, 100, 50, 70, 80, \ldots, 100)$$` --- # Vectors (*source: Gill*) * Serial listing of numbers where the order matters * Can add and subtract at will if conformable (either by adding / subtracting a constant (*scalar*) or adding / subtracting a second vector ) * If adding / subtracting vectors, they need to be *conformable* -- otherwise, *nonconformable* * Multiplying vectors (not fun): Either dot `\(\cdot\)` or cross product `\(\times\)` (note: difference in these!) * dot product AKA inner product, produces a scalar. (we'll get to this later) * cross product, produces vector --- # Vector/scalar addition/multiplication $$ `\begin{aligned} \mathbf{u} & = [1, 2, 3, 4, 5] \\ \mathbf{v} & = [1, 1, 1, 1, 1] \\ k & = 2 \end{aligned}` $$ -- $$ `\begin{aligned} \mathbf{u} + \mathbf{v} & = [1 + 1, 2 + 1, 3+ 1, 4 + 1, 5+ 1] = [2, 3, 4, 5, 6] \\ k \mathbf{u} & = [2 \times 1, 2 \times 2, 2 \times 3, 2 \times 4, 2 \times 5] = [2, 4, 6, 8, 10] \\ k \mathbf{v} & = [2 \times 1,2 \times 1,2 \times 1,2 \times 1,2 \times 1] = [2, 2, 2, 2, 2] \end{aligned}` $$ --- # Linear combinations * Linear combinations of vectors `\(\mathbf{a}\)` and `\(\mathbf{b}\)` `$$\mathbf{a} + \mathbf{b}$$` `$$2\mathbf{a} - 3\mathbf{b}$$` * Generic form `$$\alpha \mathbf{a} + \beta\mathbf{b} + \gamma\mathbf{c} + \delta\mathbf{d} + \ldots$$` --- # Linear combinations: (in)dependence * **Linear independence**: cannot get from one vector to another through linear combination * Another way to consider is if you have to go *beyond the space (span)* of the set to include an additional vector. * Can think of as multiplication by a scalar, but technically, combining each NON-ZERO vector, multiplied by a scalar, gives us zero. ( `\(\mathbf{v}_1, \mathbf{v}_2, \ldots \mathbf{v}_k\)` are linearly dependent if and only if there exist scalars `\(\alpha_1, \alpha_2, \ldots, \alpha_k\)` *not all zero* such that `\(\alpha_1 \mathbf{v}_1 + \alpha_2 \mathbf{v}_2 + \ldots + \alpha_k \mathbf{v}_k = \mathbf{0}\)`) * Overall, we may be in a situation where the number of dimensions helps us understand the size of the solution set -- * **Question** Do you make a zero vector with *some* combo of all of these? --- # Linear (in)dependence `$$\mathbf{a} = \begin{bmatrix} 3 \\ 1 \end{bmatrix}, \quad \mathbf{b} = \begin{bmatrix} 2 \\ 2 \end{bmatrix}, \quad \mathbf{c} = \begin{bmatrix} 1 \\ 3 \end{bmatrix}$$` Is the set linearly dependent? -- These are (together) linearly dependent. -- `$$\mathbf{a}-2\times\mathbf{b}+\mathbf{c} =\Big( \begin{matrix} 0 \\ 0 \end{matrix}\Big)$$` --- # Detecting linear dependence * `\(\mathbf{v}_1, \mathbf{v}_2, \ldots \mathbf{v}_k\)` are linearly dependent if and only if there exist scalars `\(\alpha_1, \alpha_2, \ldots, \alpha_k\)` *not all zero* such that `$$\alpha_1 \mathbf{v}_1 + \alpha_2 \mathbf{v}_2 + \ldots + \alpha_k \mathbf{v}_k = \mathbf{0}$$` --- # Example: determining (in)dependence `$$\mathbf{a} = \begin{bmatrix} 2 \\ 1 \\ 2 \end{bmatrix}, \quad \mathbf{b} = \begin{bmatrix} 4 \\ 1 \\ 3 \end{bmatrix}, \quad \mathbf{c} = \begin{bmatrix} 1 \\ 1 \\ 2 \end{bmatrix}$$` If we're not sure what to do, we set this up as trying to solve for our variable of choice. So, if we're multiplying scalars, it must be the case, for example, that `\(2\alpha + 4\beta + 1\gamma = 0\)`, and so on. That is, we're trying to solve for `\(\alpha \mathbf{a} + \beta\mathbf{b} + \gamma\mathbf{c} = \mathbf{0}\)`. -- * Express as a **system of equations** (note: renaming each line so you can see the transformations more easily on the next slide) `$$\begin{aligned}2\alpha &+ 4\beta &+ \gamma &= 0 \text{ (}\mathbf{h}\text{) }\\ \alpha &+ \beta &+ \gamma &= 0 \text{ (}\mathbf{j}\text{) }\\ 2\alpha &+ 3\beta &+ 2\gamma &= 0\text{ (}\mathbf{k}\text{) } \end{aligned}$$` --- ## Aside: solving systems of equations * Need at least x equations for x unknowns (e.g. 2 unknowns, 2 equations) * Multiply/divide each equation and add together * Different approaches, but often try to eliminate or 'kick out' variables to get down to solving for one variable * Once you have one variable, continue! --- # Solve the system of equations Let's work through an example to evaluate whether our matrices (technically vectors) are linearly independent or dependent. * **Step 1:** We re-write our matrices from the previous slide, setting each equal to zero. Note that we've named them to make following along a little easier. * **Step 2:** We leave our first equation `\(\mathbf{h}\)` as-is. We then take our second equation and calculate: `\(h-k\)` and replace that result in the third row. We can see from the third row that `\(\beta = \gamma\)`. --- # Solve the system of equations - example Let's work through an example to evaluate whether our matrices are linearly independent or dependent. * **Step 1: write out equations** `$$\begin{aligned} 2\alpha + 4\beta &+ \gamma &= 0 \text{ (}\mathbf{h}\text{) }\\ \alpha + \beta &+ \gamma &= 0 \text{ (}\mathbf{j}\text{) }\\ 2\alpha + 3\beta &+ 2\gamma &= 0\text{ (}\mathbf{k}\text{) } \end{aligned}$$` * **Step 2: Add/subtract** $$ `\begin{aligned} 2\alpha + 4\beta + \gamma &= 0 \\ \alpha + \beta + \gamma &= 0 \\ \beta - \gamma &= 0 \end{aligned}` $$ --- # Solve the system of equations Let's work through an example to evaluate whether our matrices are linearly independent or dependent. .pull-left[ * **Step 2: Add/subtract** $$ `\begin{aligned} 2\alpha + 4\beta + \gamma &= 0 \\ \alpha + \beta + \gamma &= 0 \\ \beta - \gamma &= 0 \end{aligned}` $$ * **Step 3: ... Solve ...** $$ `\begin{aligned} 2\alpha + 5\gamma &= 0 \\ \alpha + 2\gamma &= 0 \\ -\beta + \gamma &= 0 \end{aligned}` $$ ] .pull-right[ * **Step 3**: Now, we continue to work, trying to solve for any of our three variables (three variables, three equations). We can sub in `\(\gamma\)` for `\(\beta\)` and simplify our middle equation. ] --- # Solve the system of equations Let's work through an example to evaluate whether our matrices are linearly independent or dependent. .pull-left[ * **Step 3: ... Solve ...** $$ `\begin{aligned} 2\alpha + 5\gamma &= 0 \\ \alpha + 2\gamma &= 0 \\ -\beta + \gamma &= 0 \end{aligned}` $$ * **Step 4: ... continue ...** $$ `\begin{aligned} \gamma &= 0 \\ \alpha + 2\gamma &= 0 \\ -\beta + \gamma &= 0 \end{aligned}` $$ ] .pull-right[ * **Step 4**: We can then take 2 times our middle row (j) from the top row (replacing h) to get `\(\gamma = 0\)`. As `\(\gamma = \beta = 0\)`, we can substitute those into our middle equation. ] --- ## So what? Conclusion * **Conclusion**: This means that ... `\(\alpha = 0\)` as well. Therefore, these equations (and matrices) are linearly independent as the only possible solution that satisfies our requirements is for all variables to be zero (trivial). --- # Example Now, let's try this together -- work with a partner. Are these matrices linearly dependent or independent? `$$\mathbf{a} = \begin{bmatrix} 4 \\ 3 \\ 3 \end{bmatrix}, \quad \mathbf{b} = \begin{bmatrix} 2 \\ 1 \\ -1 \end{bmatrix}, \quad \mathbf{c} = \begin{bmatrix} 1 \\ 1 \\ 2 \end{bmatrix}$$` --- # Example * **Step 1: write out** $$ `\begin{aligned} 4\alpha + 2\beta + 1\gamma &= 0 (h)\\ 3\alpha + 1\beta + 1\gamma &= 0 (j)\\ 3\alpha - 1\beta + 2\gamma &= 0 (k) \end{aligned}` $$ -- * **Step 2: manipulate (j-k)** $$ `\begin{aligned} 4\alpha + 2\beta + 1\gamma &= 0 \\ 2\beta - 1\gamma &= 0 \\ 3\alpha - 1\beta + 2\gamma &= 0 \end{aligned}` $$ -- * **Step 3: Solve!!** $$ `\begin{aligned} 4\alpha + 4\beta &= 0 \\ 2\beta &=\gamma \\ \end{aligned}` $$ -- `$$\gamma = 2, \quad \beta = 1, \quad \alpha = -1$$` *Is this our only solution?* -- (no! linearly dependent) --- class: inverse, middle, center # RECAP --- # SO FAR: * Critical and inflection points * Higher order derivatives * Grid search and gradient descent * MLE * Matrices --- class: center, middle, inverse ## Let’s get to know each other a bit more – Name, pronouns, subfield/research area, where you are currently, something fun/interesting about you and/or your hobbies