Review: Tools for Code and Calc/Linear Algebra Debugging - - PowerPoint PPT Presentation

review tools for code and calc linear algebra debugging
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Review: ¡Tools ¡for ¡Code ¡and ¡ Calc/Linear ¡Algebra ¡Debugging

slide-2
SLIDE 2
  • 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
slide-3
SLIDE 3
  • 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.

slide-4
SLIDE 4

Neighbor’s ¡Name Why ¡are ¡they ¡taking ¡optimization? What ¡is ¡one ¡thing ¡they ¡would ¡like ¡to ¡optimize?

slide-5
SLIDE 5

Motivation ¡Example

Finding ¡a ¡good ¡direction ¡to ¡go Finding ¡a ¡step ¡size Finding ¡the ¡minimum

slide-6
SLIDE 6

HOW ¡ ¡WILL ¡ ¡A ¡ ¡COMPUTE TER ¡ ¡KNOW?

slide-7
SLIDE 7

Partial ¡Derivatives

F(x1,x2) ¡= ¡3x1x2 +6x2

2+9x1 3

Analytical ¡for ¡x1 and ¡x2 dF/dx1= ¡3x2 +27x12 dF/dx2= ¡3x1 +12x2

slide-8
SLIDE 8

Chain ¡Rule

Differentiate ¡w.r.t x: ¡ ¡ ¡ ¡ ¡f(x,y,z) ¡= ¡x3y*cos(x3y+z)

x3y*(-­‑sin(x3y+z) ¡* ¡3x2y) ¡+ ¡3x2y*cos(x3y+z)

slide-9
SLIDE 9

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 ¡

slide-10
SLIDE 10

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…

slide-11
SLIDE 11

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

slide-12
SLIDE 12

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

slide-13
SLIDE 13

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)

slide-14
SLIDE 14

Directional ¡Derivative

slide-15
SLIDE 15

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) . . .

slide-16
SLIDE 16

2-­‑Norm

slide-17
SLIDE 17

Matlab Debugging ¡Experience?

  • Syntax
  • Logic ¡(math, ¡matrix, ¡program ¡structure)
  • Memory ¡(rewriting, ¡lost)
slide-18
SLIDE 18

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
slide-19
SLIDE 19

Functions

  • Example