Upgrade to Pro — share decks privately, control downloads, hide ads and more …

機械学習における
ハイパーパラメータ最適化の理論と実践
 / hpo_theory_practice

Masahiro Nomura
September 16, 2019

機械学習における
ハイパーパラメータ最適化の理論と実践
 / hpo_theory_practice

Masahiro Nomura

September 16, 2019
Tweet

More Decks by Masahiro Nomura

Other Decks in Research

Transcript

  1. 自己紹介
 • 野村 将寛
 • 株式会社サイバーエージェント AI Lab
 ◦ ハイパーパラメータ最適化


    • 産総研 特定集中研究専門員
 • 東工大小野研究室 博士後期課程1年
 ◦ 進化計算
 • kaggle master
 2
  2. ベイズ最適化
 15 • ハイパーパラメータ最適化において一番人気のある手法
 • 最もベーシックかつOSSとして利用しやすい2手法(✴)を解説
 ◦ GP-EI [Snoek et

    al., 2012]
 ◦ TPE [Bergstra et al., 2011]
 
 
 
 
 (✴) SMAC [Hutter et al., 2011]はOSSとして利用がしづらいため,発表では省略

  3. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 16 •

    ガウス過程(GP)によって目的関数をモデル化
 • 評価値の改善量の期待値(EI)が最大となる点を選択

  4. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 17 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  5. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 18 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  6. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 19 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  7. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 20 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  8. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 21 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  9. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 22 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  10. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 23 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  11. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 24 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  12. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 25 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  13. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 26 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  14. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 27 1.

    GPにより目的関数を予測
 2. EIを計算して最適化
 3. 2.で得られた点を評価
 4. 1.〜3.を繰り返す

  15. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 評価値の改善量の期待値であるEIの計算式:
 


    
 
 目的関数がGPに従う場合は解析的に計算が可能
 28
  16. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 評価値の改善量の期待値であるEIの計算式:
 


    
 
 目的関数がGPに従う場合は解析的に計算が可能
 29 評価値の改善量

  17. ベイズ最適化 : GP-EI [Snoek et al., 2012] 
 評価値の改善量の期待値であるEIの計算式:
 


    
 
 目的関数がGPに従う場合は解析的に計算が可能
 • ただ,多峰性関数のため最適化は容易ではない (ベイズ最適化一般の話)
 ◦ カテゴリカル,離散変数にはEDA,連続変数はCMA-ES [Bergstra et al., 2011]
 ◦ DIRECT + CMA-ES [Wang et al., 2016]
 ◦ DIRECT + L-BFGS [Calandra et al., 2014]
 31 ガウス過程によるモデル化

  18. ベイズ最適化 : TPE [Bergstra et al., 2011] 
 32 •

    Hyperopt, Optunaがデフォルトで採用しているアルゴリズム
 • EIを使うところまではGP-EIと同じだが,
 GP-EIとは目的関数に対するモデル化の方法が異なる(✴)
 
 (✴)正確には,目的関数に対するモデル化は行わない 

  19. ベイズ最適化 : TPE [Bergstra et al., 2011] 
 33 p(y|x)を直接モデル化する代わりにp(x|y)とp(y)でモデル化する


    p(y|x) = p(x|y)p(y)/p(x)
 ある閾値y✴を用いて,評価値上位と下位からなるp(x|y)を定義
 
 
 
 y✴は分位点γにより決定
 

  20. ベイズ最適化 : TPE [Bergstra et al., 2011] 
 34 これらの式を用いると,


    
 
 つまり,l(x)/g(x)を最大とするxを選択すれば良い.
 xに依存する部分

  21. ベイズ最適化 : TPE [Bergstra et al., 2011] 
 35 引用:

    http://neupy.com/2016/12/17/hyperparameter_optimization_for_neural_netw orks.html
 
 
 l(x)
 g(x)
 (✴)こちらもl(x)/g(x)の(厳密な)最適化は困難 
 
 Hyperopt, Optunaでは,
 l(x)からサンプルを一定数生成して 
 もっともl(x)/g(x)を大きくするxを選択 

  22. GP-EI vs. TPE : カテゴリカル変数
 36 TPE
 • カテゴリカル変数を直接扱うことが可能
 GP-EI


    • ガウス過程を利用するためには工夫が必要
 • 扱うためには
 ◦ one-hot encoding (OSSではこちらが多い)
 ◦ カテゴリカル変数用のカーネルを設計
   などを行う必要がある

  23. GP-EI vs. TPE : 次元数
 37 [Eggensperger et al., 2013]において,


    LR, SVM, LDAのtuningを含む多数のタスクにてGP-EI, TPEを比較.
 結果として,
 • 低次元(~6)の場合
 ◦ GP-EI > TPE
 • 高次元(10~)の場合
 ◦ GP-EI < TPE

  24. GP-EI vs. TPE : 次元数
 38 [Eggensperger et al., 2013]において,


    LR, SVM, LDAのtuningを含む多数のタスクにてGP-EI, TPEを比較.
 結果として,
 • 低次元(~6)の場合
 ◦ GP-EI > TPE
 • 高次元(10~)の場合
 ◦ GP-EI < TPE
 GP-EI :
 探索空間全体に対するモデル化が必要
 次元数の増加で探索空間の体積も指数的に増加 → スケールしづらい
 
 TPE :
 すでに存在する点から評価値上位のpdfを推定
 直感的には有望な点付近の部分空間を探せる

  25. CMA-ES
 39 • 進化計算における最も有力な手法の1つ [Hansen and Ostermeier, 1996]
 • ハイパーパラメータ最適化への適用例も存在


    ◦ CNN [Loshchilov and Hutter, 2016]
 ◦ SVM [Friedrichs and Igel, 2005]
 ◦ HMM, LDA, DNN [Watanabe and Le Roux, 2014]
 • 多変量正規分布から解を生成することで最適化を行う
 ◦ 更新式の一部は自然勾配法に対応 [Akimoto et al., 2010]

  26. CMA-ES
 47 1. 正規分布から解を生成
 2. 全ての解を評価して重み付けする
 3. 正規分布のパラメータを更新
 4. 1.〜3.を繰り返す


    正規分布からサンプルされる点の
 期待評価値に対する自然勾配方向
 への更新に対応 (一部)

  27. GP-EI vs. CMA-ES : 評価回数
 49 [Hutter et al., 2013]において,


    様々なベンチマーク関数を用いてGP-EIとCMA-ESを比較(✴).
 結果として,
 • 評価回数が少ない(10×次元数)場合 : GP-EI > CMA-ES
 • 評価回数が多い(100×次元数)場合 : GP-EI < CMA-ES 
 
 (✴) 論文ではSMACを用いたとあるが,ガウス過程を用いたSMACとあるので実質GP-EIと同じ

  28. GP-EI vs. CMA-ES : 評価回数
 50 [Hutter et al., 2013]において,


    様々なベンチマーク関数を用いてGP-EIとCMA-ESを比較(✴).
 結果として,
 • 評価回数が少ない(10×次元数)場合 : GP-EI > CMA-ES
 • 評価回数が多い(100×次元数)場合 : GP-EI < CMA-ES 
 
 (✴) 論文ではSMACを用いたとあるが,ガウス過程を用いたSMACとあるので実質GP-EIと同じ
 GP-EI :
 探索空間全体に対してモデル化をしている
 評価回数が増えても局所的な収束性はそれほど上 がらない
 
 CMA-ES :
 現在の正規分布をどんどん移動&更新させるだけ
 評価回数が増えると収束性up

  29. ベイズ最適化 vs. CMA-ES : 時間計算量
 51 iteration数tに対する時間計算量について,
 • GP-EI :

    O(t^3) … ガウス過程による推論にカーネル行列の逆行列が必要 (✴)
 • TPE : O(t)
 • CMA-ES : O(1) … iteration数に依存しない
 
 評価回数が膨大にある場合はCMA-ESのほうが良い
 
 (✴) 計算量を抑えたガウス過程の推論も多々研究があるが,今回は省略

  30. 注意
 53 ノーフリーランチ定理 [Lockett and Miikkulainen, 2016] より,
 全ての関数に対する最適化手法の平均的な性能はランダムサーチと同じ
 


    特にハイパーパラメータ最適化では
 ユーザが設定した探索空間の定義によって関数の構造が変わる
 → 「この手法がいい!」と一概に言うのは難しい

  31. Hyperband [Li et al., 2018]
 75 絞り込み方を変えながらSuccessive Halvingを行う
 • 積極的に絞り込みをするターン


    • もう少しゆっくり絞り込むターン
 • 全く絞り込まないターン
 • ...
 というトレードオフを考慮
 引用: [Li et al., 2018]

  32. BOHB [Falkner et al., 2018]
 76 Hyperband(HB)とベイズ最適化(BO)両方のメリットを取り入れた手法
 • Hyperband
 ◦

    絞り込み方を変えながら
 Successive Halvingを実行
 • ベイズ最適化
 ◦ これまでに得られたデータから
 有望な領域へ解を生成
 
 引用: [Falkner et al., 2018]

  33. Population Based Training (PBT) [Jaderberg et al., 2017]
 77 Sequential

    SearchとRandom Searchのいいとこ取り

  34. Sequential Search (ベイズ最適化など)
 
 
 78 • メリット : 効率的


    • デメリット : 並列化が難しく時間がかかる
 [Jaderberg et al., 2017]
  35. Population Based Training (PBT) [Jaderberg et al., 2017] 
 80

    各ポイントで最良のNNモデルを複製 + ハイパラをちょっと変えて実行

  36. Population Based Training (PBT) [Jaderberg et al., 2017] 
 81

    各ポイントで最良のNNモデルを複製 + ハイパラをちょっと変えて実行

  37. Population Based Training (PBT) [Jaderberg et al., 2017] 
 82

    各ポイントで最良のNNモデルを複製 + ハイパラをちょっと変えて実行

  38. 今日紹介した手法すべてにPython OSSが存在
 88 • GP-EI : GpyOpt
 • TPE :

    Optuna
 • CMA-ES : pycma
 • Successive Halving : Optuna
 • Hyperband : Ray
 • BOHB : HpBandSter
 • PBT : Ray
 • MTBO : Ax (BoTorch)

  39. 今日紹介した手法すべてにPython OSSが存在
 89 • GP-EI : GpyOpt
 • TPE :

    Optuna
 • CMA-ES : pycma
 • Successive Halving : Optuna
 • Hyperband : Ray
 • BOHB : HpBandSter
 • PBT : Ray
 • MTBO : Ax (BoTorch)
 • Define-by-Runスタイル

  40. 今日紹介した手法すべてにPython OSSが存在
 90 • GP-EI : GpyOpt
 • TPE :

    Optuna
 • CMA-ES : pycma
 • Successive Halving : Optuna
 • Hyperband : Ray
 • BOHB : HpBandSter
 • PBT : Ray
 • MTBO : Ax (BoTorch)
 • Facebookが5月にF8で発表

  41. 今日紹介した手法すべてにPython OSSが存在
 91 • GP-EI : GpyOpt
 • TPE :

    Optuna
 • CMA-ES : pycma
 • Successive Halving : Optuna
 • Hyperband : Ray
 • BOHB : HpBandSter
 • PBT : Ray
 • MTBO : Ax (BoTorch)
 • 強化学習のRLlibとの相性が良い

  42. まとめ
 93 問題の構造について
 • 利用できない場合(Black-box最適化)
 • 利用できる場合(Gray-box最適化)
 の枠組みと代表的な手法を紹介
 
 手法に対する妥当な評価を行うための研究が急速に進んでいる(✴)


    • ベンチマーク問題が急速に準備されつつある[Klein and Hutter, 2019],[Ying et al., 2019]
 → 解きたい問題に応じた適切な手法選択が可能になることを期待
 
 (✴) ランダムサーチがSOTAと変わらないというのがNASであったりする [Li and Talwalkar, 2019],[Sciuto et al., 2019]

  43. 参考文献 (1)
 94 • [Eggensperger et al., 2013] K. Eggensperger,

    M. Feurer, F. Hutter, J. Bergstra, J. Snoek, H. Hoos, and K. Leyton-Brown, “Towards an Empirical Foundation for Assessing Bayesian Optimization of Hyperparameters,” NIPS workshop on Bayesian Optimization in Theory and Practice, vol.10, p.3, 2013. 
 • [Hutter et al., 2013] F. Hutter, H. Hoos, and K. Leyton-Brown, “An Evaluation of Sequential Model-based Optimization for Expensive Blackbox Functions,” Proceedings of the 15th annual conference companion on Genetic and evolutionary computation, ACM, pp.1209–1216 2013. 
 • [Snoek et al., 2012] J. Snoek, H. Larochelle, and R.P. Adams, “Practical Bayesian Optimization of Machine Learning Algorithms,” Advances in neural information processing systems, pp.2951–2959, 2012. 
 • [Bergstra et al., 2011] J.S. Bergstra, R. Bardenet, Y. Bengio, and B. Kégl, “Algorithms for Hyper-Parameter Optimization,” Advances in neural information processing systems, pp.2546–2554, 2011. 
 • [Hutter et al., 2011] F. Hutter, H.H. Hoos, and K. Leyton-Brown, “Sequential Model-Based Optimization for General Algorithm Configuration,” International Conference on Learning and Intelligent Optimization, Springer, pp.507–523 2011. 
 • [Wang et al., 2016] Z. Wang, F. Hutter, M. Zoghi, D. Matheson, and N. de Feitas, “Bayesian optimization in a billion dimensions via random embeddings,” Journal of Artificial Intelligence Research, vol.55, pp.361–387, 2016. 

  44. 参考文献 (2)
 95 • [Calandra et al., 2014] R. Calandra,

    A. Seyfarth, J. Peters, and M.P. Deisenroth, “An experimental comparison of bayesian optimization for bipedal locomotion,” 2014 IEEE International Conference on Robotics and Automation (ICRA)IEEE, pp.1951–1958 2014. 
 • [Hansen and Ostermeier, 1996] N. Hansen and A. Ostermeier, “Adapting Arbitrary Normal Mutation Distributions in Evolution Strategies: The Covariance Matrix Adaptation,” Proceedings of IEEE international conference on evolutionary computation, IEEE, pp.312–317 1996. 
 • [Loshchilov and Hutter, 2016] I. Loshchilov and F. Hutter, “CMA-ES for Hyper- parameter Optimization of Deep Neural Networks,” ICLR Workshop, 2016. 
 • [Friedrichs and Igel, 2005] F. Friedrichs and C. Igel, “Evolutionary Tuning of Multiple SVM Parameters,” Neurocomputing, vol.64, pp.107–117, 2005. 
 • [Watanabe and Le Roux, 2014] S. Watanabe and J. Le Roux, “Black box optimization for automatic speech recognition,” 2014 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)IEEE, pp.3256–3260 2014. 
 • [Akimoto et al., 2010] Y. Akimoto, Y. Nagata, I. Ono, and S. Kobayashi. Bidirectional relation between CMA evolution strategies and natural evolution strategies. In Parallel Problem Solving from Nature (PPSN), 2010. 

  45. 参考文献 (3)
 96 • [Jamieson and Talwalkar, 2016] K. Jamieson

    and A. Talwalkar, “Non-stochastic best arm identification and hyperparameter optimiza- tion,” AISTATS, pp.240–248, 2016.
 • [Li et al., 2018] L. Li, K. Jamieson, G. DeSalvo, A. Rostamizadeh, and A. Talwalkar, “Hyperband: A Novel Bandit- Based Approach to Hyperparameter Optimization,” Journal of Machine Learning Research, vol.18, no.185, pp.1–52, 2018. 
 • [Falkner et al., 2018] S. Falkner, A. Klein, and F. Hutter, “BOHB: Robust and efficient hyperparameter optimization at scale,” ICML, pp.1437–1446, 2018. 
 • [Domhan et al., 2015] T. Domhan, J.T. Springenberg, and F. Hutter, “Speeding up automatic hyperparameter optimization of deep neural networks by extrapolation of learning curves,” Twenty-Fourth International Joint Conference on Artificial Intelligence, 2015. 
 • [Klein et al., 2017] A. Klein, S. Falkner, J.T. Springenberg, and F. Hutter, “Learning Curve Prediction with Bayesian Neural Networks,” International Conference on Learning Representations (ICLR) 2017 Conference Track, April 2017. 
 • [Lockett and Miikkulainen, 2016] A. Lockett and R. Miikkulainen, “A probabilistic re-formulation of no free lunch: Continuous lunches are not free”, Evolutionary Computation, 2016. 

  46. 参考文献 (4)
 97 • [Jaderberg et al., 2017] M. Jaderberg,

    V. Dalibard, S. Osindero, W. M Czarnecki, J. Donahue, A. Razavi, O. Vinyals, T. Green, I. Dunning, K. Simonyan, et al, “Population based training of neural networks,” arXiv preprint arXiv:1711.09846, 2017. 
 • [Swersky et al., 2013] K. Swersky, J. Snoek, R. Adams, “Multi-Task Bayesian Optimization,” In Advances in neural information processing systems, pages 2004–2012, 2013.
 • [Akiba et al., 2019] T. Akiba, S. Sano, T. Yanase, T. Ohta, and M. Koyama. Optuna: “A next generation hyperparameter optimization framework,” in Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, 2019. 
 • [Li and Talwalkar, 2019] L. Li and A. Talwalkar, “Random Search and Reproducibility for Neural Architecture Search,” arXiv:1902.07638, 2019. 
 • [Sciuto et al., 2019] C. Sciuto, K. Yu, M. Jaggi, C. Musat, M. Salzmann, “Evaluating the search phase of neural architecture search,” arXiv:1902.08142, 2019. 
 • [Klein and Hutter, 2019] A. Klein and F. Hutter, “Tabular benchmarks for joint architecture and hyperparameter optimization”, arXiv:1905.04970, 2019. 
 • [Ying et al., 2019] C. Ying, A. Klein, E. Christiansen, E. Real, K. Murphy, and F. Hutter. NAS-Bench-101: Towards reproducible neural architecture search. ICML, volume 97 of Proceedings of Machine Learning Research, pp. 7105–7114, 2019. 

  47. 102

  48. facebook/Ax
 104 • 縮小推定 + Thompson Sampling (https://ax.dev/tutorials/factorial.html)
 • 良い選択肢に対し多数のトラフィックを流せる

    → A/Bテストの効率化
 • 今後FBの他ツールとの連携が予定 (https://github.com/facebook/Ax/issues/77)

  49. 注意点 : pfnet/optuna
 107 1. 低Budget時にSuccssive Halvingの絞り込みが積極的すぎるかも
 • https://github.com/pfnet/optuna/pull/404
 •

    スナップショットを使わないので計算リソースとしてはメリットがある
 
 2. 数万回評価する場合などにCMA-ESを使うと計算コストが大きい
 • 現状の実装は毎iterationで正規分布を1から更新する
 ◦ 本来のCMA-ESは評価回数に計算量は依存しない
 • 高Budget時にはpycmaの利用がおすすめ