gradient descent
play

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


  1. Gradient ¡Descent ¡ Michail ¡Michailidis ¡& ¡Patrick ¡Maiden ¡

  2. Outline ¡ • Mo4va4on ¡ • Gradient ¡Descent ¡Algorithm ¡ ▫ Issues ¡& ¡Alterna4ves ¡ • Stochas4c ¡Gradient ¡Descent ¡ ¡ • Parallel ¡Gradient ¡Descent ¡ • HOGWILD! ¡

  3. Mo4va4on ¡ • 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 ¡

  4. Func4on ¡Example ¡

  5. Quickest ¡ever ¡review ¡of ¡mul4variate ¡calculus ¡ ¡ • Deriva4ve ¡ • Par4al ¡Deriva4ve ¡ • Gradient ¡Vector ¡

  6. Deriva4ve ¡ • Slope ¡of ¡the ¡tangent ¡line ¡ 𝑔(𝑦) = ​𝑦↑ 2 ¡ ¡ ¡ ¡ ¡ 𝑔 ′ (𝑦) ¡ = ​𝑒𝑔/𝑒𝑦 =2 𝑦 ¡ ¡ • Easy ¡when ¡a ¡func4on ¡is ¡univariate ¡ 𝑔 ′′ (𝑦) = ​𝑒↑ 2 𝑔/𝑒𝑦 = ¡2 ¡

  7. Par4al ¡Deriva4ve ¡– ¡Mul4variate ¡Func4ons ¡ For ¡mul4variate ¡func4ons ¡(e.g ¡two ¡variables) ¡we ¡need ¡par4al ¡deriva4ves ¡ – ¡one ¡per ¡dimension. ¡Examples ¡of ¡mul4variate ¡func4ons: ¡ ¡ ¡ ¡ 𝑔(𝑦 , 𝑧) = ​𝑦↑ 2 + ​𝑧↑ 2 ¡ 𝑔(𝑦 , 𝑧) =− ​𝑦↑ 2 − ​𝑧↑ 2 ¡ 𝑔(𝑦 , 𝑧) = ​ cos ↑ 2 ⁠ ( 𝑦 ) + ​ cos ↑ 2 ⁠ ( 𝑧 ) ¡ 𝑔(𝑦 , 𝑧) = ​ cos ↑ 2 ⁠ ( 𝑦 ) + ​𝑧↑ 2 ¡ Convex! ¡ Concave! ¡

  8. Par4al ¡Deriva4ve ¡– ¡Cont’d ¡ ¡ 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. ¡ ¡ ¡ ¡ ¡ cut: ¡ 𝑔(𝑦 ,1 ) =8− ​𝑦↑ 2 ¡ surface: ¡ 𝑔(𝑦 , 𝑧) =9− ​𝑦↑ 2 − ​𝑧↑ 2 ¡ plane: ¡ 𝑧 = 1 ¡ slope ¡/ ¡deriva-ve ¡of ¡cut: ¡ 𝑔 ′( 𝑦 )=−2 𝑦 ¡

  9. Par4al ¡Deriva4ve ¡– ¡Cont’d ¡2 ¡ ¡ If ¡we ¡par4ally ¡differen4ate ¡a ¡func4on ¡with ¡respect ¡to ¡x, ¡we ¡pretend ¡y ¡is ¡constant ¡ 𝑔(𝑦 , 𝑧) =9− ​𝑦↑ 2 − ​𝑧↑ 2 ¡ 𝑔(𝑦 , 𝑧) =9− ​𝑦↑ 2 − ​𝑑↑ 2 ¡ 𝑔(𝑦 , 𝑧) =9− ​𝑑↑ 2 − ​𝑧↑ 2 ¡ ​𝑔↓𝑦 = ​𝜖𝑔/𝜖𝑦 =−2 𝑦 ¡ ​𝑔↓𝑧 = ​𝜖𝑔/𝜖𝑧 =−2 𝑧 ¡

  10. Par4al ¡Deriva4ve ¡– ¡Cont’d ¡3 ¡ ¡ The ¡two ¡tangent ¡lines ¡that ¡pass ¡through ¡a ¡point, ¡define ¡the ¡tangent ¡plane ¡to ¡that ¡point ¡

  11. Gradient ¡Vector ¡ • Is ¡the ¡vector ¡that ¡has ¡as ¡coordinates ¡the ¡par4al ¡deriva4ves ¡of ¡the ¡ func4on: ¡ ​𝜖𝑔/𝜖𝑦 =−2 𝑦 ¡ ​𝜖𝑔/𝜖𝑧 =−2 𝑧 ¡ ¡ 𝑔(𝑦 , 𝑧) =9− ​𝑦↑ 2 − ​𝑧↑ 2 ¡ 𝛼𝑔 = ¡ ​𝜖𝑔/𝜖𝑦 𝑗 + ​𝜖𝑔/𝜖𝑧 𝑘 = (​𝜖𝑔/𝜖𝑦 , ​𝜖𝑔/𝜖𝑧 ) =(−2x, ¡−2y) ¡ ¡ • Note: ¡Gradient ¡Vector ¡is ¡not ¡parallel ¡to ¡tangent ¡surface ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  12. Gradient ¡Descent ¡Algorithm ¡& ¡Walkthrough ¡ • Idea ¡ ▫ Start ¡somewhere ¡ ▫ Take ¡steps ¡based ¡on ¡the ¡gradient ¡vector ¡of ¡ the ¡current ¡posi4on ¡4ll ¡convergence ¡ • Convergence ¡: ¡ ▫ happens ¡when ¡change ¡between ¡two ¡steps ¡< ¡ε ¡

  13. Gradient ¡Descent ¡Code ¡(Python) ¡ 𝑔(𝑦) = ​𝑦↑ 4 −3 ​𝑦↑ 3 +2 ¡ ​𝑔↑ ′ ( 𝑦 )=4 ​𝑦↑ 3 −9 ​𝑦↑ 2 ¡ ​𝑔↑ ′ ( 𝑦 )=4 ​𝑦↑ 3 −9 ​𝑦↑ 2 ¡

  14. Gradient ¡Descent ¡Algorithm ¡& ¡Walkthrough ¡

  15. Poten4al ¡issues ¡of ¡gradient ¡descent ¡-­‑ ¡Convexity ¡ We ¡need ¡a ¡convex ¡func4on ¡ ¡ ¡ à ¡so ¡there ¡is ¡a ¡global ¡minimum: ¡ ¡ 𝑔(𝑦 , 𝑧) = ​𝑦↑ 2 + ​𝑧↑ 2 ¡

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

  17. Poten4al ¡issues ¡of ¡gradient ¡descent ¡– ¡Step ¡Size ¡ • As ¡we ¡saw ¡before, ¡one ¡parameter ¡needs ¡to ¡be ¡set ¡is ¡the ¡step ¡size ¡ • Bigger ¡steps ¡leads ¡to ¡faster ¡convergence, ¡right? ¡

  18. Alterna4ve ¡algorithms ¡ • 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 ¡

  19. Stochas4c ¡Gradient ¡Descent ¡ • 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) ¡

  20. Stochas4c ¡Gradient ¡descent ¡ • 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 ¡ ¡

  21. Stochas4c ¡Gradient ¡descent ¡(2) ¡ • 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! ¡ ▫

  22. Parallel ¡Gradient ¡descent ¡ • 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 ¡

  23. HOGWILD! ¡(Niu, ¡et ¡al. ¡2011) ¡ • 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 ¡ ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend