Gradient Descent Michail Michailidis & Patrick Maiden - - PowerPoint PPT Presentation

gradient descent
SMART_READER_LITE
LIVE PREVIEW

Gradient Descent Michail Michailidis & Patrick Maiden - - PowerPoint PPT Presentation

Gradient Descent Michail Michailidis & Patrick Maiden Outline Mo4va4on Gradient Descent Algorithm Issues & Alterna4ves Stochas4c Gradient Descent


slide-1
SLIDE 1

Michail ¡Michailidis ¡& ¡Patrick ¡Maiden ¡

Gradient ¡Descent ¡

slide-2
SLIDE 2
  • Mo4va4on ¡
  • Gradient ¡Descent ¡Algorithm ¡

▫ Issues ¡& ¡Alterna4ves ¡

  • Stochas4c ¡Gradient ¡Descent ¡ ¡
  • Parallel ¡Gradient ¡Descent ¡
  • HOGWILD! ¡

Outline ¡

slide-3
SLIDE 3
  • It ¡is ¡good ¡for ¡finding ¡global ¡minima/maxima ¡if ¡the ¡func4on ¡is ¡convex ¡
  • It ¡is ¡good ¡for ¡finding ¡local ¡minima/maxima ¡if ¡the ¡func4on ¡is ¡not ¡convex ¡
  • It ¡is ¡used ¡for ¡op4mizing ¡many ¡models ¡in ¡Machine ¡learning: ¡

▫ It ¡is ¡used ¡in ¡conjunc-on ¡with: ¡ ¡

– Neural ¡Networks ¡ ¡ – Linear ¡Regression ¡ – Logis4c ¡Regression ¡ – Back-­‑propaga4on ¡algorithm ¡ – Support ¡Vector ¡Machines ¡

Mo4va4on ¡

slide-4
SLIDE 4

Func4on ¡Example ¡

slide-5
SLIDE 5
  • Deriva4ve ¡
  • Par4al ¡Deriva4ve ¡
  • Gradient ¡Vector ¡

Quickest ¡ever ¡review ¡of ¡mul4variate ¡calculus ¡ ¡

slide-6
SLIDE 6
  • Slope ¡of ¡the ¡tangent ¡line ¡

¡ ¡ ¡ ¡ ¡ ¡

  • Easy ¡when ¡a ¡func4on ¡is ¡univariate ¡

Deriva4ve ¡

𝑔(𝑦)=​𝑦↑2 ¡ 𝑔′(𝑦) ¡=​𝑒𝑔/𝑒𝑦 =2𝑦 𝑔′′(𝑦)=​𝑒↑2 𝑔/𝑒𝑦 = ¡2 ¡

slide-7
SLIDE 7

For ¡mul4variate ¡func4ons ¡(e.g ¡two ¡variables) ¡we ¡need ¡par4al ¡deriva4ves ¡ – ¡one ¡per ¡dimension. ¡Examples ¡of ¡mul4variate ¡func4ons: ¡ ¡ ¡ ¡

Par4al ¡Deriva4ve ¡– ¡Mul4variate ¡Func4ons ¡

𝑔(𝑦,𝑧)=​𝑦↑2 +​𝑧↑2 ¡ 𝑔(𝑦,𝑧)=​cos↑2 ⁠(𝑦) +​𝑧↑2 ¡ 𝑔(𝑦,𝑧)=​cos↑2 ⁠(𝑦) +​cos↑2 ⁠(𝑧) ¡ Convex! ¡ 𝑔(𝑦,𝑧)=−​𝑦↑2 −​𝑧↑2 ¡ Concave! ¡

slide-8
SLIDE 8

To ¡visualize ¡the ¡par4al ¡deriva4ve ¡for ¡each ¡of ¡the ¡dimensions ¡x ¡and ¡y, ¡we ¡can ¡imagine ¡a ¡plane ¡that ¡ “cuts” ¡our ¡surface ¡along ¡the ¡two ¡dimensions ¡and ¡once ¡again ¡we ¡get ¡the ¡slope ¡of ¡the ¡tangent ¡line. ¡

¡ ¡ ¡ ¡

Par4al ¡Deriva4ve ¡– ¡Cont’d ¡ ¡

surface: ¡𝑔(𝑦,𝑧)=9−​𝑦↑2 −​𝑧↑2 ¡ plane: ¡𝑧=1 ¡ cut: ¡𝑔(𝑦,1)=8−​𝑦↑2 ¡ slope ¡/ ¡deriva-ve ¡of ¡cut: ¡𝑔′(𝑦)=−2𝑦 ¡

slide-9
SLIDE 9

Par4al ¡Deriva4ve ¡– ¡Cont’d ¡2 ¡ ¡

𝑔(𝑦,𝑧)=9−​𝑦↑2 −​𝑧↑2 ¡

If ¡we ¡par4ally ¡differen4ate ¡a ¡func4on ¡with ¡respect ¡to ¡x, ¡we ¡pretend ¡y ¡is ¡constant ¡

𝑔(𝑦,𝑧)=9−​𝑦↑2 −​𝑑↑2 ¡ ​𝑔↓𝑦 =​𝜖𝑔/𝜖𝑦 =−2𝑦 ¡ 𝑔(𝑦,𝑧)=9−​𝑑↑2 −​𝑧↑2 ¡ ​𝑔↓𝑧 =​𝜖𝑔/𝜖𝑧 =−2𝑧 ¡

slide-10
SLIDE 10

Par4al ¡Deriva4ve ¡– ¡Cont’d ¡3 ¡ ¡

The ¡two ¡tangent ¡lines ¡that ¡pass ¡through ¡a ¡point, ¡define ¡the ¡tangent ¡plane ¡to ¡that ¡point ¡

slide-11
SLIDE 11
  • Is ¡the ¡vector ¡that ¡has ¡as ¡coordinates ¡the ¡par4al ¡deriva4ves ¡of ¡the ¡

func4on: ¡ ¡ ¡

  • Note: ¡Gradient ¡Vector ¡is ¡not ¡parallel ¡to ¡tangent ¡surface ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

Gradient ¡Vector ¡

𝑔(𝑦,𝑧)=9−​𝑦↑2 −​𝑧↑2 ¡ 𝛼𝑔= ¡​𝜖𝑔/𝜖𝑦 𝑗+​𝜖𝑔/𝜖𝑧 𝑘=(​𝜖𝑔/𝜖𝑦 ,​𝜖𝑔/𝜖𝑧 )=(−2x, ¡−2y) ¡ ​𝜖𝑔/𝜖𝑦 =−2𝑦 ¡ ​𝜖𝑔/𝜖𝑧 =−2𝑧 ¡

slide-12
SLIDE 12
  • Idea ¡

▫ Start ¡somewhere ¡ ▫ Take ¡steps ¡based ¡on ¡the ¡gradient ¡vector ¡of ¡ the ¡current ¡posi4on ¡4ll ¡convergence ¡

  • Convergence ¡: ¡

▫ happens ¡when ¡change ¡between ¡two ¡steps ¡< ¡ε ¡

Gradient ¡Descent ¡Algorithm ¡& ¡Walkthrough ¡

slide-13
SLIDE 13

Gradient ¡Descent ¡Code ¡(Python) ¡

​𝑔↑′ (𝑦)=4​𝑦↑3 −9​𝑦↑2 ¡ 𝑔(𝑦)=​𝑦↑4 −3​𝑦↑3 +2 ¡ ​𝑔↑′ (𝑦)=4​𝑦↑3 −9​𝑦↑2 ¡

slide-14
SLIDE 14

Gradient ¡Descent ¡Algorithm ¡& ¡Walkthrough ¡

slide-15
SLIDE 15

Poten4al ¡issues ¡of ¡gradient ¡descent ¡-­‑ ¡Convexity ¡

𝑔(𝑦,𝑧)=​𝑦↑2 +​𝑧↑2 ¡ We ¡need ¡a ¡convex ¡func4on ¡ ¡ ¡ à ¡so ¡there ¡is ¡a ¡global ¡minimum: ¡ ¡

slide-16
SLIDE 16

Poten4al ¡issues ¡of ¡gradient ¡descent ¡– ¡Convexity ¡(2) ¡

slide-17
SLIDE 17
  • As ¡we ¡saw ¡before, ¡one ¡parameter ¡needs ¡to ¡be ¡set ¡is ¡the ¡step ¡size ¡
  • Bigger ¡steps ¡leads ¡to ¡faster ¡convergence, ¡right? ¡

Poten4al ¡issues ¡of ¡gradient ¡descent ¡– ¡Step ¡Size ¡

slide-18
SLIDE 18
  • Newton’s ¡Method ¡

▫ Approximates ¡a ¡polynomial ¡and ¡jumps ¡to ¡the ¡ min ¡of ¡that ¡func4on ¡ ▫ Needs ¡Hessian ¡

  • BFGS ¡

▫ More ¡complicated ¡algorithm ¡ ▫ Commonly ¡used ¡in ¡actual ¡op4miza4on ¡ packages ¡

Alterna4ve ¡algorithms ¡

slide-19
SLIDE 19
  • Mo4va4on ¡

▫ One ¡way ¡to ¡think ¡of ¡gradient ¡descent ¡is ¡as ¡a ¡minimiza4on ¡of ¡a ¡sum ¡of ¡ func4ons: ¡

– 𝑥=𝑥 ¡−𝛽𝛼𝑀 ¡(𝑥)=𝑥−𝛽∑↑▒𝛼​𝑀↓𝑗 (𝑥) ¡

– (​𝑀↓𝑗 ¡is ¡the ¡loss ¡func4on ¡evaluated ¡on ¡the ¡i-­‑th ¡element ¡of ¡the ¡dataset) ¡

– On ¡large ¡datasets, ¡it ¡may ¡be ¡computa4onally ¡expensive ¡to ¡iterate ¡over ¡the ¡ whole ¡dataset, ¡so ¡pulling ¡a ¡subset ¡of ¡the ¡data ¡may ¡perform ¡beeer ¡ – Addi4onally, ¡sampling ¡the ¡data ¡leads ¡to ¡“noise” ¡that ¡can ¡avoid ¡finding ¡“shallow ¡ local ¡minima.” ¡This ¡is ¡good ¡for ¡op4mizing ¡non-­‑convex ¡func4ons. ¡(Murphy) ¡

Stochas4c ¡Gradient ¡Descent ¡

slide-20
SLIDE 20
  • Online ¡learning ¡algorithm ¡
  • Instead ¡of ¡going ¡through ¡the ¡en4re ¡dataset ¡on ¡each ¡itera4on, ¡randomly ¡

sample ¡and ¡update ¡the ¡model ¡

¡ Initialize ¡w ¡and ¡α ¡ Until ¡convergence ¡do: ¡ Sample ¡one ¡example ¡i ¡from ¡dataset ¡//stochastic ¡portion ¡

w ¡= ¡w ¡-­‑ ¡α​𝛼𝑀↓𝑗 (𝑥) ¡

return ¡w ¡

¡

Stochas4c ¡Gradient ¡descent ¡

slide-21
SLIDE 21
  • Checking ¡for ¡convergence ¡afer ¡each ¡data ¡example ¡can ¡be ¡slow ¡
  • One ¡can ¡simulate ¡stochas4city ¡by ¡reshuffling ¡the ¡dataset ¡on ¡each ¡pass: ¡

Initialize ¡w ¡and ¡α ¡ Until ¡convergence ¡do: ¡ shuffle ¡dataset ¡of ¡n ¡elements ¡//simulating ¡stochasticity ¡ For ¡each ¡example ¡i ¡in ¡n: ¡ ¡w ¡= ¡w ¡-­‑ ¡α​𝛼𝑀↓𝑗 (𝑥) ¡ return ¡w ¡ ¡

  • This ¡is ¡generally ¡faster ¡than ¡the ¡classic ¡itera4ve ¡approach ¡(“noise”) ¡
  • However, ¡you ¡are ¡s4ll ¡passing ¡over ¡the ¡en4re ¡dataset ¡each ¡4me ¡
  • An ¡approach ¡in ¡the ¡middle ¡is ¡to ¡sample ¡“batches”, ¡subsets ¡of ¡the ¡en4re ¡dataset ¡

▫ This ¡can ¡be ¡parallelized! ¡

Stochas4c ¡Gradient ¡descent ¡(2) ¡

slide-22
SLIDE 22
  • Training ¡data ¡is ¡chunked ¡into ¡batches ¡and ¡distributed ¡

¡

Initialize ¡w ¡and ¡α ¡ Loop ¡until ¡convergence: ¡ ¡generate ¡randomly ¡sampled ¡chunk ¡of ¡data ¡m ¡ ¡on ¡each ¡worker ¡machine ¡v: ¡ ¡ ¡𝛼​𝑀↓𝑤 (𝑥) ¡= ¡𝑡𝑣𝑛(​𝛼𝑀↓𝑗 (𝑥)) ¡// ¡compute ¡gradient ¡on ¡batch ¡ ¡𝑥 ¡= ¡𝑥 ¡−𝛽∗𝑡𝑣𝑛(​𝛼𝑀↓𝑤 (𝑥)) ¡//update ¡global ¡w ¡model ¡ ¡ return ¡w ¡

Parallel ¡Gradient ¡descent ¡

slide-23
SLIDE 23
  • Unclear ¡why ¡it ¡is ¡called ¡this ¡
  • Idea: ¡

▫ In ¡Parallel ¡SGD, ¡each ¡batch ¡needs ¡to ¡finish ¡before ¡star4ng ¡next ¡pass ¡ ▫ In ¡HOGWILD!, ¡share ¡the ¡global ¡model ¡amongst ¡all ¡machines ¡and ¡update ¡on-­‑ the-­‑fly ¡

– No ¡need ¡to ¡wait ¡for ¡all ¡worker ¡machines ¡to ¡finish ¡before ¡star4ng ¡next ¡epoch ¡ – Assump4on: ¡component-­‑wise ¡addi4on ¡is ¡atomic ¡and ¡does ¡not ¡require ¡locking ¡

¡

HOGWILD! ¡(Niu, ¡et ¡al. ¡2011) ¡

slide-24
SLIDE 24

Initialize ¡global ¡model ¡w ¡ On ¡each ¡worker ¡machine: ¡ ¡loop ¡until ¡convergence: ¡ ¡ ¡draw ¡a ¡sample ¡e ¡from ¡complete ¡dataset ¡E ¡ ¡ ¡get ¡current ¡global ¡state ¡w ¡and ¡compute ¡𝛼​𝑀↓𝑓 (𝑥) ¡ ¡ ¡ ¡for ¡each ¡component ¡i ¡in ¡e: ¡ ¡ ¡ ¡​𝑥↓𝑗 ¡= ¡​𝑥↓𝑗 ¡−𝛽​𝑐↓𝑤↑𝑈 𝛼​𝑀↓𝑓 (𝑥) ¡// ¡bv ¡is ¡vth ¡std. ¡basis ¡ component ¡ ¡ ¡ ¡update ¡global ¡w ¡ return ¡w ¡ ¡

HOGWILD! ¡-­‑ ¡Pseudocode ¡

slide-25
SLIDE 25

HOGWILD! ¡ Parallel ¡SGD ¡

Comparison ¡

W0 ¡ W1 ¡ W2 ¡ GA ¡ Gc ¡ GB ¡ GA ¡ Gc ¡ GB ¡ Wx ¡ GA ¡ Gc ¡ GB ¡

slide-26
SLIDE 26

Comparison ¡

  • RR ¡– ¡Round ¡Robin ¡ ¡
  • Each ¡machine ¡updates ¡x ¡as ¡it ¡comes ¡in. ¡Wait ¡for ¡all ¡before ¡star4ng ¡next ¡pass ¡
  • AIG ¡ ¡
  • Like ¡Hogwild ¡but ¡does ¡fine-­‑grained ¡locking ¡of ¡variables ¡that ¡are ¡going ¡to ¡be ¡used ¡
slide-27
SLIDE 27

Comparison ¡(2) ¡

SVM ¡ Graph ¡Cuts ¡ Matrix ¡Comple4on ¡

slide-28
SLIDE 28
  • Having ¡an ¡idea ¡of ¡how ¡gradient ¡descent ¡works ¡informs ¡your ¡use ¡of ¡
  • thers’ ¡implementa4ons ¡
  • There ¡are ¡very ¡good ¡implementa4ons ¡of ¡the ¡algorithm ¡and ¡other ¡

approaches ¡to ¡op4miza4on ¡in ¡many ¡languages ¡

  • Packages: ¡
  • Python ¡
  • NumPy/SciPy ¡
  • Matlab ¡
  • Matlab ¡Op4miza4on ¡toolbox ¡
  • Pmtk3 ¡

Moral ¡of ¡the ¡story ¡

  • R ¡
  • General-­‑purpose ¡op4miza4on: ¡op4m() ¡
  • R ¡Op4miza4on ¡Infrastructure ¡(ROI) ¡
  • TupleWare ¡
  • Coming ¡soon…. ¡

¡

slide-29
SLIDE 29

Par-al ¡Deriva-ves: ¡

  • hep://msemac.redwoods.edu/~darnold/math50c/matlab/pderiv/index.xhtml ¡
  • hep://mathinsight.org/nondifferen4able_discon4nuous_par4al_deriva4ves ¡
  • hep://www.sv.vt.edu/classes/ESM4714/methods/df2D.html ¡
  • Gradients ¡Vector ¡Field ¡Interac4ve ¡Visualiza4on: ¡hep://dlippman.imathas.com/g1/Grapher.html ¡from ¡

heps://www.khanacademy.org/math/calculus/par4al_deriva4ves_topic/gradient/v/gradient-­‑1 ¡

  • hep://simmakers.com/wp-­‑content/uploads/Sof/gradient.gif ¡

Gradient ¡Descent: ¡

  • hep://en.wikipedia.org/wiki/Gradient_descent ¡
  • hep://www.youtube.com/watch?v=5u4G23_OohI ¡(Stanford ¡ML ¡Lecture ¡2) ¡
  • hep://en.wikipedia.org/wiki/Stochas4c_gradient_descent ¡
  • Murphy, ¡Machine ¡Learning, ¡ ¡a ¡Probabils2c ¡Perspec2ve, ¡2012, ¡MIT ¡Press ¡
  • Hogwild ¡paper: ¡hep://pages.cs.wisc.edu/~brecht/papers/hogwildTR.pdf ¡

¡

Resources ¡