ガウス過程モデルとベイズ最適化
▶ 問題設定1:関数推定 関数f を精度良く推定したい
f∗= arg min
fˆ∈F
∑n i=1
(f(xi)−f(xˆ i))2
▶ 問題設定2:最適化
関数f を最大化するパラメータxを求めたい x∗i = arg max
x∈{x1,...,xn} f(x)
Input
Output
Step 0
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 1
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 2
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 3
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 4
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 5
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 6
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 7
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 8
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 9
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 0
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 1
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 2
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 3
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 4
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 5
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 6
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 7
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 4
Objective
Prediction Observations
Next Sample Uncertainty
予測分布
▶ 線形モデル
y=Xw+ε, ε∼N(0, σ2I)
▶ ラベルありデータとラベルなしデータ
(XL,yL)← {(xi, yi)}i∈L, (XU, )← {(xi, )}i∈U
▶ 事前予測分布
wU ∼N(0, σ02I) ⇒ yˆU ∼N(µU,ΣU)
▶ 事後予測分布
w|(XL,yL)∼N(wL, SL) ⇒ yˆU |(XL,yL)∼N(µU|L,ΣU|L)
(前回の講義より)
w = (X⊤X +σ2
I)−1X y , S = ( 1
X⊤X + 1 I
)−1
▶ ベイズ線形モデルの事前予測分布:yˆU ∼N(µU,ΣU) µU =0,
ΣU =σ20XUXU⊤+σ2I
▶ ベイズ線形モデルの事後予測分布:
ˆ
yU |(XL,yL)∼N(µU|L,ΣU|L)
µU|L=σ02XUXL⊤(σ20XLXL⊤+σ2I)−1yL
ΣU|L=σ02XUXU⊤+σ2I−σ20XUXL⊤(σ20XLXL⊤+σ2I)−1XLXU⊤
(導出には条件付き正規分布の公式を利用)
多次元正規分布が [ za
zb
]
∼N ([ µa
µb
] ,
[ Σaa Σab
Σba Σbb
])
と表されているとき,条件付き分布 za|zb∼N(
µa|b,Σa|b)
の期待値µa|b と分散共分散行列Σa|b は以下のように書ける:
µa|b=µa+ ΣabΣ−bb1(zb−µb), Σa|b= Σaa−ΣabΣ−bb1Σba
(証明は,例えば,「パターン認識と機械学習」2.3.1節を参照)
▶ ベイズ線形モデル
yU =XUw+ε, w∼N(0, σ02I), ε∼N(0, σ2I), w⊥ε.
における予測値yU の期待ベクトルと分散共分散行列が,それ ぞれ,
E[yU] =0,
Cov[yU] =E[(yU −E[yU])(yU−E[yU])⊤] =σ20XUXU⊤+σ2I と表されることを示せ.
ガウス過程モデル
▶ カーネル関数:2つの事例xとx′の類似度を表す関数 k(x,x′)
▶ 内積カーネル
k(x,x′) =x⊤x′
▶ (q次)多項式カーネル
k(x,x′) = (x⊤x′+ 1)q
▶ ガウシアンカーネル
k(x,x′) = exp (
−∥x−x′∥22
2s2 )
▶ ラベルありデータとラベルなしデータ
XL ∈RnL×d, XU ∈RnU×d
▶ カーネル行列
K(XL,XU) =
k(x1,x1) k(x1,x2) · · · k(x1,xnU) k(x2,x1) k(x2,x2) · · · k(x2,xnU)
... ... . .. ... k(xnL,x1) k(xnL,x2) · · · k(xnL,xnU)
∈RnL×nU
▶ カーネルベクトル
k(XL,xi) =
k(x1,xi) k(x2,xi)
...
∈RnL
▶ ガウス過程モデル(Gaussian Process Model)
ベイズ線形モデルのカーネル化
▶ ガウス過程モデルの事前予測分布:yˆU ∼N(µU,ΣU)
µU=0,
ΣU=σ02K(XU,XU) +σ2I
▶ ガウス過程モデルの事後予測分布:
ˆ
yU |(XL,yL)∼N(µU|L,ΣU|L)
µU|L=σ02K(XU,XL)(σ20K(XL,XL) +σ2I)−1yL
ΣU|L=σ02K(XU,XU) +σ2I−σ20K(XU,XL)(σ02K(XL,XL) +σ2I)−1K(XL,XU)
(導出には条件付き正規分布の公式を利用)
Input
Output
Step 4
Objective
Prediction Observations
Next Sample Uncertainty
▶ ガウス過程モデルの事後予測分布:ˆyi|(XL,yL)∼N(µi|L,Σi|L)
µi|L=σ20k(XL,xi)⊤(σ02K(XL,XL) +σ2I)−1y
⊤ −
ベイズ最適化
▶ ラベルありデータ集合L:{(xi, yi)}i∈L
▶ ラベルなしデータ集合U:{(xi,yi)}i∈U
▶ アルゴリズム
Input: {(xi, yi)}i∈L, {(xi,yi)}i∈U
1: while実験リソース(予算や時間)があるdo 2: for i∈ U do
3: 獲得関数a(xi)を計算 4: end for
5: i′←arg maxi∈Ua(xi)
6: (実験などにより)yi′を求める 7: L ← L ∪ {i′},U ← U \ {i′} 8: end while
9: ibest←arg maxi∈Lyi
Output: 最適な入出力(xibest, yibest)
▶ Probability of Improvement (PI) a(xi) =Pi|L(yi≥max
h∈L yh), i∈ U
ただし,maxh∈Lyh はラベルあり事例の中で最大の出力値
▶ Expected Improvement (EI)
a(xi) =E[f(xi)−max
h∈Lyh] i∈ U
ただし,maxh∈Lyh はラベルあり事例の中で最大の出力値
▶ Exploration(探索)とExploitation(搾取)のトレードオフ
Input
Output
Step 0
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 1
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 2
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 3
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 4
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 5
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 6
Objective
Prediction Observations
Next Sample Uncertainty
Input
Output
Step 7
Objective
Prediction Observations
Next Sample Uncertainty
▶ ロジスティック回帰分析
ˆP(y= 1|x) =fsigmoid(w0+
∑d j=1
wjxj), fsigmoid(z) = 1 1 + exp(−z)
−5 0 5
0.00.20.40.60.81.0
Logistic Function
0.0 0.2 0.4 0.6 0.8 x
0.0 0.2 0.4 0.6 0.8 1.0
y,p(y=1)
Mean Truth Data Confidence
0.0 0.2 0.4 0.6 0.8
x
−1.5
−1.0
−0.5 0.0 0.5 1.0 1.5
f(x)
Mean Truth Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
0.0 0.2 0.4 0.6 0.8 1.0
y,p(y=1)
Mean Truth Data Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
−2 0 2 4
f(x)
Mean Truth Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
0.0 0.2 0.4 0.6 0.8 1.0
y,p(y=1)
Mean Truth Data Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
−4
−2 0 2 4
f(x)
Mean Truth Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
0.0 0.2 0.4 0.6 0.8 1.0
y,p(y=1)
Mean Truth Data Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
−4
−2 0 2 4
f(x)
Mean Truth Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
0.0 0.2 0.4 0.6 0.8 1.0
y,p(y=1)
Mean Truth Data Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
−4
−2 0 2 4
f(x)
Mean Truth Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
0.0 0.2 0.4 0.6 0.8 1.0
y,p(y=1)
Mean Truth Data Confidence
−0.2 0.0 0.2 0.4 0.6 0.8 1.0 x
−3
−2
−1 0 1 2 3 4
f(x)
Mean Truth Confidence
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ 通常のガウス過程モデルのフィッティングにはO(n3)の計算が必要
▶ nが大きいときはRandom Feature Map法による近似を利用化
▶ カーネル関数に対応する特徴ベクトルをランダムにサンプリング
0 1 2 3 4 5 6
X
1.5 1.0 0.5 0.0 0.5 1.0 1.5
Y
Bayesian Regression (D=1000)
true(sin) predict train
▶ トンプソンサンプリングが手軽
確率モデル
▶ プール型に比べ,さまざまな面で困難
▶ 獲得関数の最大化=複雑な非凸関数の最大化
PI EI
▶ Random Feature Map +トンプソンサンプリングがよい
▶ ハイパーパラメータの決定
周辺尤度が最大となるハイパーパラメータを選択(通常は,ガウ ス過程モデルのパッケージにそのような機能あり)
▶ ウォームスタート
ブラックボックス関数の近似関数が得られるときは,両者の差を ガウス過程モデルでモデル化すると効率がよい
▶ 停止基準
ガウス過程モデルがブラックボックス関数をうまく表現できてい るならば,PIやEIの値が一定以下になれば終了
▶ ベイズ線形モデルをカーネル化した非線形モデルはガウス過程モ デルと呼ばれており,様々な分野で利用されている
▶ ガウス過程モデルは逐次的な能動学習における不確実性のモデル 化に有用であり,ベイズ最適化と呼ばれている
▶ ベイズ最適化は材料情報学分野の実験計画で着目されており,さ まざまな拡張・発展がみられる