0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【E資格対策ノート】最適化手法

Posted at

🔰 最適化手法とは

最適化手法(Optimizer)は、ニューラルネットワークの学習において損失関数を最小化するためのアルゴリズム。
勾配降下法をベースに、学習の収束速度や安定性を向上させる様々な手法が開発されている。

最適化手法の役割

  1. パラメータ更新:重みとバイアスを適切に調整
  2. 学習効率の向上:収束速度の改善
  3. 局所解からの脱出:より良い解の探索
  4. 学習の安定化:振動や発散の抑制

基本的な勾配降下法の考え方

損失関数の勾配に基づいてパラメータを更新する:

\theta \leftarrow \theta - \eta \frac{\partial L}{\partial \theta}
  • $\theta$:パラメータ(重み・バイアス)
  • $\eta$:学習率
  • $\frac{\partial L}{\partial \theta}$:損失関数の勾配

✅ 主要な最適化手法

🔸 SGD(Stochastic Gradient Descent)

数式

\theta_{t+1} = \theta_t - \eta \frac{\partial L}{\partial \theta_t}

特徴・問題点

  • 最もシンプルな勾配降下法の実装
  • 学習率が固定のため、適切な調整が困難
  • 谷間で振動しやすく、収束が遅い
  • 鞍点で停滞する可能性

使用場面

  • 計算資源が限られている場合
  • 単純なモデルや小規模データ

🔸 Momentum

数式

\begin{align}
v_{t+1} &= \alpha v_t + \eta \frac{\partial L}{\partial \theta_t} \\
\theta_{t+1} &= \theta_t - v_{t+1}
\end{align}

特徴・改善点

  • 慣性項によりSGDの振動問題を改善
  • 一定方向への勾配を蓄積して収束を加速
  • $\alpha = 0.9$が一般的

問題点

  • ハイパーパラメータが増加
  • 最適解で行き過ぎることがある

使用場面

  • 一般的な深層学習
  • 収束速度を重視する場合

🔸 ネステロフのモーメンタム(Nesterov Accelerated Gradient, NAG)

数式

\begin{align}
v_{t+1} &= \alpha v_t + \eta \frac{\partial L}{\partial (\theta_t - \alpha v_t)} \\
\theta_{t+1} &= \theta_t - v_{t+1}
\end{align}

この更新式をそのまま用いると実装が大変になるため、通常は $\hat{\theta}{t+1} = \theta{t+1} - \alpha v_{t+1}$ を更新する。

\begin{align}
\hat{\theta}_{t+1} &= \theta_{t+1} - \alpha v_{t+1} \\
&= (\theta_t - v_{t+1}) - \alpha v_{t+1} \\
&= \theta_t - (1 + \alpha) v_{t+1} \\
&= \theta_t + (1 + \alpha) (\alpha v_t - \eta \frac{\partial L}{\partial \hat{\theta_t}}) \\
&= \theta_t + \alpha ^2 v_t - (1 + \alpha) \eta \frac{\partial L}{\partial \hat{\theta_t}}
\end{align}

特徴

  • Momentumの改良版
  • 先読み勾配(予測位置での勾配) を使用

利点

  • Momentumより収束速度が速い
  • 最適解付近での振動を抑制し、行き過ぎを防ぐ

問題点

  • モーメンタムと比べて計算コストがわずかに増加
  • 実装がやや複雑

使用場面

  • Momentumの上位互換として使用
  • 高精度が求められる場合

🔸 AdaGrad

数式

\begin{align}
h_{t+1} &= h_t + \frac{\partial L}{\partial \theta_t} \odot \frac{\partial L}{\partial \theta_t} \\
\theta_{t+1} &= \theta_t - \frac{\eta}{\sqrt{h_{t+1} + \epsilon}} \odot \frac{\partial L}{\partial \theta_t}
\end{align}

ただし、

\begin{cases}
h_t & \text{:勾配の二乗の累積} \\
\epsilon & \text{:ゼロ除算防止(通常 $10^{-8}$)}
\end{cases}

$\odot$ はアダマール積といい、要素ごとの積を表す。

特徴

  • 適応的学習率を導入
  • パラメータごとに学習率を調整
  • 過去の勾配の累積を利用

利点

  • 学習率を自動的に調整可能
  • スパースなデータに有効
  • 各パラメータの更新頻度を考慮

問題点

  • 学習率の単調減少
  • 長時間学習で勾配が消失
  • 後半で学習が停止

使用場面

  • スパースなデータの学習
  • 自然言語処理(語彙が大きい場合)

🔸 RMSprop

数式

\begin{align}
h_{t+1} &= \rho h_t + (1-\rho)\frac{\partial L}{\partial \theta_t} \odot \frac{\partial L}{\partial \theta_t}  \\
\theta_{t+1} &= \theta_t - \frac{\eta}{\sqrt{h_{t+1} + \epsilon}} \odot \frac{\partial L}{\partial \theta_t}
\end{align}

ただし、

\begin{cases}
h_t & \text{:勾配の二乗の累積} \\
\rho & \text{:減衰率(通常0.9)} \\
\epsilon & \text{:ゼロ除算防止(通常 $10^{-8}$)}
\end{cases}

特徴

  • AdaGradの改良版
  • 指数移動平均で勾配の累積を制御
  • 学習率の単調減少を回避

利点

  • 長時間学習が可能
  • AdaGradの学習率減少問題を解決
  • 安定した学習

問題点

  • ハイパーパラメータの調整が必要
  • Momentum項がない

使用場面

  • RNN(Recurrent Neural Network)
  • 長時間の学習が必要な場合

🔸 Adam(Adaptive Moment Estimation)

数式

モーメントの更新式:

\begin{align}
\begin{cases}
m_{t+1} &= \rho_1 m_t + (1-\rho_1)\frac{\partial L}{\partial \theta_t} \\
v_{t+1} &= \rho_2 v_t + (1-\rho_2) \frac{\partial L}{\partial \theta_t} \odot \frac{\partial L}{\partial \theta_t} \\
\end{cases}
\end{align}

および、バイアスの修正式:

\begin{align}
\begin{cases}
\hat{m}_{t+1} &= \frac{m_{t+1}}{1-\rho_1^{t+1}} \\
\hat{v}_{t+1} &= \frac{v_{t+1}}{1-\rho_2^{t+1}}
\end{cases}
\end{align}

を用いて次のようにパラメータを更新する:

\theta_{t+1} = \theta_t - \frac{\eta}{\sqrt{\hat{v}_{t+1}} + \epsilon} \odot \hat{m}_{t+1}

ただし、

\begin{cases}

m & \text{:一次モーメント(勾配の平均)} \\
v & \text{:二次モーメント(勾配の分散)} \\
\rho_1 & \text{:一次モーメント減衰率(通常0.9)} \\
\rho_2 & \text{二次モーメント減衰率(通常0.999)} \\
\eta & \text{:学習率(通常0.001)} \\
\hat{m} & \text{:バイアス補正後の一次モーメント} \\
\hat{v} & \text{:バイアス補正後の二次モーメント} \\
\epsilon & \text{:ゼロ除算防止(通常 $10^{-8}$)}
\end{cases}

特徴

  • MomentumとRMSpropの組み合わせ
  • 一次モーメント(勾配の平均)
  • 二次モーメント(勾配の分散)
  • バイアス補正

利点

  • 高い汎用性
  • 安定した学習
  • デフォルト設定で良好な性能
  • 幅広いタスクで有効

問題点

  • メモリ使用量が多い
  • 場合によってはSGDより劣る

使用場面

  • 最も一般的に使用される
  • 深層学習の標準的な選択肢

🎯 最適化手法の比較

手法 収束速度 安定性 メモリ使用量 適用場面
SGD 遅い 低い 少ない シンプルなモデル
Momentum 中程度 中程度 少ない 一般的な深層学習
NAG 速い 中程度 少ない Momentumの上位版
AdaGrad 中程度 高い 中程度 スパースデータ
RMSprop 速い 高い 中程度 RNN
Adam 速い 高い 多い 汎用的

収束速度と安定性のトレードオフ

  • 収束速度が速い手法は、安定性が低い場合がある
  • 逆に、安定性が高い手法は収束速度が遅くなる傾向がある
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?