Review: Tools for Code and Calc/Linear Algebra Debugging - - PowerPoint PPT Presentation
Review: Tools for Code and Calc/Linear Algebra Debugging - - PowerPoint PPT Presentation
Review: Tools for Code and Calc/Linear Algebra Debugging Math: directional derivatives our convention is a vector is always a column vector. vector-vector
- Math:
- ur ¡convention ¡is ¡a ¡vector ¡is ¡always ¡a ¡column ¡vector.
- vector-‑vector ¡products ¡(also ¡known ¡as ¡a ¡dot ¡
product). ¡ Notation ¡a^T b ¡(results ¡in ¡a ¡scalar).
- -‑ Outer ¡products: ¡a ¡b^T
- matrix ¡vector ¡multiplication ¡A ¡b ¡(results ¡in ¡a ¡column ¡
vector) ¡or ¡b^T A ¡results ¡in ¡a ¡row ¡vector. ¡(help ¡visualize ¡ these ¡things)
- matrix ¡matrix ¡multiplication
- identity ¡matrix
- diagonal ¡matrix
- transpose
- symmetric ¡matrices
- 2-‑norm ¡of ¡a ¡vector
- matrix ¡inverse
- quadratic ¡forms: ¡x^T A ¡x ¡(results ¡in ¡a ¡scalar)
- positive/negative ¡definite
- gradient/Hessian
- cross ¡product
- partial ¡derivatives
- chain ¡rule
directional ¡derivatives Matlab (mostly ¡I'd ¡focus ¡on ¡doing ¡the ¡things ¡you ¡reviewed ¡in ¡linear ¡algebra, ¡in
- ‑ how ¡to ¡create ¡row ¡vectors, ¡column ¡vectors ¡(comma ¡vs ¡semicolon)
- ‑ demonstrate ¡the ¡same ¡kind ¡of ¡things ¡covered ¡in ¡linear ¡algebra ¡(inner ¡product
- ‑ linspace
- ‑ colon ¡notation ¡to ¡create ¡arrays
- ‑ functions
- ‑ creating ¡matrices
- ‑ indexing ¡arrays, ¡single ¡elements, ¡rows, ¡columns
- ‑ help ¡/ ¡doc
- ‑ basic ¡plotting
- ‑ basic ¡debugging
- Multivariable ¡Calculus
- Partial ¡Derivatives
- Analytical ¡and ¡Numerical
- Chain ¡Rule
- Dot ¡and ¡Cross ¡Product
- Directional ¡Derivative
- Linear ¡Algebra
- Matrix ¡Operations
- Gradient
- Hessian
- Matlab:
- Debugging
- Functions
- Examples
Linear ¡Algebra ¡Review ¡and ¡Reference Link ¡found ¡on ¡syllabus Example: ¡ Multivariable ¡Calculus ¡Study ¡Guide: ¡A ¡LATEX ¡Version ¡ Forums, ¡matlab documentation This ¡is ¡a ¡simple ¡review, ¡use ¡more ¡comprehensive ¡sources ¡for ¡quizes, ¡tests, ¡etc.
Neighbor’s ¡Name Why ¡are ¡they ¡taking ¡optimization? What ¡is ¡one ¡thing ¡they ¡would ¡like ¡to ¡optimize?
Motivation ¡Example
Finding ¡a ¡good ¡direction ¡to ¡go Finding ¡a ¡step ¡size Finding ¡the ¡minimum
HOW ¡ ¡WILL ¡ ¡A ¡ ¡COMPUTE TER ¡ ¡KNOW?
Partial ¡Derivatives
F(x1,x2) ¡= ¡3x1x2 +6x2
2+9x1 3
Analytical ¡for ¡x1 and ¡x2 dF/dx1= ¡3x2 +27x12 dF/dx2= ¡3x1 +12x2
Chain ¡Rule
Differentiate ¡w.r.t x: ¡ ¡ ¡ ¡ ¡f(x,y,z) ¡= ¡x3y*cos(x3y+z)
x3y*(-‑sin(x3y+z) ¡* ¡3x2y) ¡+ ¡3x2y*cos(x3y+z)
Matrix ¡Operations
Transpose ¡ A ¡= ¡ 1 4 5 7 2 6 8 9 3 AT ¡= ¡ 1 7 8 4 2 9 5 6 3 b = ¡ 1 ¡ ¡ 7 ¡ ¡ 8 ¡ ¡ bT ¡=1 7 8
Identity ¡= ¡ 1 1 1 Diagonal ¡ ¡ 4 3 9 Symmetric ¡ ¡ 2 1 9 1 6 2 9 2 8 ALWAYS ¡column ¡vector ¡for ¡this ¡class ¡
Matrix ¡Operations
Inverse ¡ A ¡= ¡ 1 4 5 7 2 6 8 9 3 A-‑1 ¡= ¡ −.16 .11 .05 .09 −.13 .1 .16 .08 −.09
Cramer’s ¡Rule Eigendecomposition Gaussian ¡Elimination Newton’s ¡Method Etc…
Matrix ¡Operations
A ¡= ¡ 1 4 5 7 2 6 8 9 3 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡b ¡= ¡ 1 ¡ ¡ 2 ¡ ¡ 3 ¡ ¡
bT*A A*A bT*A*b
39 35 36 69 ¡ ¡ ¡ ¡57 ¡ ¡ ¡ ¡44 ¡ ¡ ¡ ¡ 69 ¡ ¡ ¡ ¡86 ¡ ¡ ¡ ¡65 95 77 ¡ ¡ ¡103 187
Matrix ¡Operations
5*a a*bT aT*b aT + ¡aT aT x ¡c 5 10 15 1 2 3 2 4 6 3 6 9 14 ¡(dot ¡product) [2,4,6] [-‑2,4,-‑2] ¡(cross ¡product) a = ¡ 1 2 3 b ¡= ¡ 1 2 3 ¡ ¡ ¡ ¡c ¡= ¡ 3 4 5
Gradient: ¡Partial ¡Derivatives ¡Array
Points ¡to ¡steepest ¡descent ¡ F(x1,x2) ¡= ¡3x1x2 +6x22+9x13
How ¡to ¡point ¡to ¡steepest ¡ascent?
(dF/dx1) ¡i (in ¡direction ¡of ¡x1) (dF/dx2) ¡j ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(in ¡direction ¡of ¡x2)
. . .
(dF/dxn) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(in ¡direction ¡of ¡xn)
Directional ¡Derivative
Hessian: ¡Second ¡Order ¡partial ¡Derivatives
F(x1,x2) ¡= ¡3x1x2 +6x22+9x13 dF2/d2x1= ¡54x1 ¡ ¡ ¡ ¡(in ¡direction ¡of ¡x1) dF2/d2x2= ¡12 ¡ ¡ ¡ ¡ ¡ ¡(in ¡direction ¡of ¡x2) . . .
2-‑Norm
Matlab Debugging ¡Experience?
- Syntax
- Logic ¡(math, ¡matrix, ¡program ¡structure)
- Memory ¡(rewriting, ¡lost)
General ¡Debugging
- Clues ¡from ¡output ¡error ¡messages
- Search ¡“matlab” ¡and ¡a ¡key ¡word
- Use ¡breakpoints ¡and ¡track ¡output
- Use ¡hand ¡calculations ¡to ¡check ¡output
- Evaluate ¡Sections
Functions
- Example