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
Review: ¡Tools ¡for ¡Code ¡and ¡ Calc/Linear ¡Algebra ¡Debugging
• Math: directional ¡derivatives our ¡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). Matlab (mostly ¡I'd ¡focus ¡on ¡doing ¡the ¡things ¡you ¡reviewed ¡in ¡linear ¡algebra, ¡in • -‑ Outer ¡products: ¡a ¡b^T -‑ how ¡to ¡create ¡row ¡vectors, ¡column ¡vectors ¡(comma ¡vs ¡semicolon) matrix ¡vector ¡multiplication ¡A ¡b ¡(results ¡in ¡a ¡column ¡ • -‑ demonstrate ¡the ¡same ¡kind ¡of ¡things ¡covered ¡in ¡linear ¡algebra ¡(inner ¡product vector) ¡or ¡b^T A ¡results ¡in ¡a ¡row ¡vector. ¡(help ¡visualize ¡ -‑ linspace these ¡things) -‑ colon ¡notation ¡to ¡create ¡arrays matrix ¡matrix ¡multiplication • -‑ functions identity ¡matrix • -‑ creating ¡matrices -‑ indexing ¡arrays, ¡single ¡elements, ¡rows, ¡columns diagonal ¡matrix • -‑ help ¡/ ¡doc transpose • -‑ basic ¡plotting symmetric ¡matrices • -‑ basic ¡debugging 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 •
This ¡is ¡a ¡simple ¡review, ¡use ¡more ¡comprehensive ¡sources ¡for ¡quizes, ¡tests, ¡etc. • Multivariable ¡Calculus • Partial ¡Derivatives Example: ¡ Multivariable ¡Calculus ¡Study ¡Guide: ¡A ¡LATEX ¡Version ¡ • Analytical ¡and ¡Numerical • Chain ¡Rule • Dot ¡and ¡Cross ¡Product • Directional ¡Derivative • Linear ¡Algebra Linear ¡Algebra ¡Review ¡and ¡Reference • Matrix ¡Operations Link ¡found ¡on ¡syllabus • Gradient • Hessian • Matlab: Forums, ¡matlab documentation • Debugging • Functions • Examples
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 Analytical ¡for ¡x 1 and ¡x 2 F(x 1 ,x 2 ) ¡= ¡3x 1 x 2 +6x 2 2 +9x 1 3 dF/dx 1 = ¡3x 2 +27x 12 dF/dx 2 = ¡3x 1 +12x 2
Chain ¡Rule Differentiate ¡w.r.t x: ¡ ¡ ¡ ¡ ¡f(x,y,z) ¡= ¡x 3 y*cos(x 3 y+z) x 3 y*(-‑sin(x 3 y+z) ¡* ¡3x 2 y) ¡+ ¡3x 2 y*cos(x 3 y+z)
Matrix ¡Operations 1 0 0 Identity ¡= ¡ 0 1 0 0 0 1 Transpose ¡ 1 4 5 1 7 8 4 0 0 A ¡= ¡ A T ¡ = ¡ Diagonal ¡ ¡ 0 3 0 7 2 6 4 2 9 0 0 9 5 6 3 8 9 3 1 ¡ ¡ 2 1 9 b = ¡ b T ¡ = 1 7 ¡ ¡ 7 8 Symmetric ¡ ¡ 1 6 2 9 2 8 8 ¡ ¡ ALWAYS ¡column ¡vector ¡for ¡this ¡class ¡
Matrix ¡Operations Inverse ¡ Cramer’s ¡Rule 1 4 5 −.16 .11 .05 Eigendecomposition Gaussian ¡Elimination A ¡= ¡ A -‑1 ¡ = ¡ 7 2 6 .09 −.13 .1 Newton’s ¡Method 8 9 3 .16 .08 −.09 Etc…
Matrix ¡Operations 1 4 5 1 ¡ ¡ A ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ b ¡= ¡ 7 2 6 2 ¡ ¡ 3 ¡ ¡ 8 9 3 39 35 36 b T *A 69 ¡ ¡ ¡ ¡57 ¡ ¡ ¡ ¡44 ¡ ¡ ¡ ¡ 69 ¡ ¡ ¡ ¡86 ¡ ¡ ¡ ¡65 A*A 95 77 ¡ ¡ ¡103 187 b T *A*b
1 1 3 Matrix ¡Operations a = ¡ b ¡= ¡ ¡ ¡ ¡ ¡c ¡= ¡ 2 2 4 3 3 5 5 5*a 10 15 1 2 3 a*b T 2 4 6 3 6 9 a T *b 14 ¡(dot ¡product) a T + ¡a T [2,4,6] a T x ¡c [-‑2,4,-‑2] ¡(cross ¡product)
Gradient: ¡Partial ¡Derivatives ¡Array Points ¡to ¡steepest ¡descent ¡ F(x 1 ,x 2 ) ¡= ¡3x 1 x 2 +6x 22 +9x 13 (dF/dx 1 ) ¡i (in ¡direction ¡of ¡x 1 ) (dF/dx 2 ) ¡j ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(in ¡direction ¡of ¡x 2 ) . . . (dF/dx n ) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(in ¡direction ¡of ¡x n ) How ¡to ¡point ¡to ¡steepest ¡ascent?
Directional ¡Derivative
Hessian: ¡Second ¡Order ¡partial ¡Derivatives F(x 1 ,x 2 ) ¡= ¡3x 1 x 2 +6x 22 +9x 13 dF 2 /d 2 x 1 = ¡54x 1 ¡ ¡ ¡ ¡ (in ¡direction ¡of ¡x 1 ) dF 2 /d 2 x 2 = ¡12 ¡ ¡ ¡ ¡ ¡ ¡(in ¡direction ¡of ¡x 2 ) . . .
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
Recommend
More recommend
Explore More Topics
Stay informed with curated content and fresh updates.