事後予測分布の式の書き換え

カーネルを用いた事後予測分布の計算による回帰直線の推定。実線は平均、エラーバンドは \pm 1 \sigma^2。回帰曲線が非常によくフィッティングできている。
事前分布として正規事前分布を仮定する場合のベイズ線形回帰では、事後予測分布は次式で与えられる。
\begin{aligned}
p(\bm y_\ast | \bm X_\ast, \bm X, \bm y)
=
\mathcal N_{D_\ast} (\bm y_\ast | \bm m_{y_\ast}, \bm V_{y_\ast})
\end{aligned}
\left\{\begin{aligned}
\bm m_{y_\ast}
={}&
\bm X_\ast \bm V_0 \bm X^\mathsf{T}
\left(
\bm X \bm V_0 \bm X^\mathsf{T} + \sigma^2 \bm I_D
\right)^{-1}
\bm y
\\ & +
\left(
\bm X_\ast
-
\bm X_\ast \bm V_0 \bm X^\mathsf{T}
(\bm X \bm V_0 \bm X^\mathsf{T} + \sigma^2 \bm I_D)^{-1}
\bm X
\right)
\bm m_0 \\
\bm V_{y_\ast}
={}&
\bm X_\ast \bm V_0 \bm X_\ast^\mathsf{T}
+
\sigma^2 \bm I_{D_\ast}
-
\bm X_\ast \bm V_0 \bm X^\mathsf{T}
( \bm X \bm V_0 \bm X^\mathsf{T} + \sigma^2 \bm I_D )^{-1}
\bm X \bm V_0 \bm X_\ast^\mathsf{T}
\\
\end{aligned}\right.
ここで、事前分布の期待値が \bm m_0 = \bm 0 である場合を考えよう。事後予測分布の期待値と共分散行列は
\begin{aligned}
\bm m_{y_\ast}
={}&
\bm X_\ast \bm V_0 \bm X^\mathsf{T}
(\bm X \bm V_0 \bm X^\mathsf{T} + \sigma^2 \bm I_D)^{-1}
\bm y \\
\bm V_{y_\ast}
={}&
\bm X_\ast \bm V_0 \bm X_\ast^\mathsf{T}
+
\sigma^2 \bm I_{D_\ast}
-
\bm X_\ast \bm V_0 \bm X^\mathsf{T}
( \bm X \bm V_0 \bm X^\mathsf{T} + \sigma^2 \bm I_D )^{-1}
\bm X \bm V_0 \bm X_\ast^\mathsf{T}
\\
\end{aligned}
となる。よく見ると、これはいくつかのかたまりに分けて解釈することができる。
\begin{aligned}
\bm m_{y_\ast}
={}&
\underbrace{ \bm X_\ast \bm V_0 \bm X^\mathsf{T} }_{\bm K_\ast^\mathsf{T}}
(\underbrace{ \bm X \bm V_0 \bm X^\mathsf{T}}_{\bm K} + \sigma^2 \bm I_D)^{-1}
\bm y \\
\bm V_{y_\ast}
={}&
\underbrace{ \bm X_\ast \bm V_0 \bm X_\ast^\mathsf{T}}_{\bm K_{\ast\ast}} + \sigma^2 \bm I_D
-
\underbrace{ \bm X_\ast \bm V_0 \bm X^\mathsf{T} }_{\bm K_\ast^\mathsf{T}}
(\underbrace{ \bm X \bm V_0 \bm X^\mathsf{T}}_{\bm K} + \sigma^2 \bm I_D)^{-1}
\underbrace{ \bm X \bm V_0 \bm X_\ast^\mathsf{T} }_{\bm K_\ast}
\\
\end{aligned}
これらをあらかじめ計算しておけば、事後予測分布を
p(\bm y_\ast | \bm X_\ast, \bm X, \bm y) = \mathcal N_{D_\ast} (\bm y_\ast | \bm m_y, \bm V_y)
\begin{aligned}
\bm m_{y_\ast}
={}&
\bm K_\ast^\mathsf{T} (\bm K + \sigma^2 \bm I_D)^{-1}
\bm y \\
\bm V_{y_\ast}
={}&
\bm K_{\ast\ast} + \sigma^2 \bm I_{D_\ast}
-
\bm K_\ast^\mathsf{T}
(\bm K + \sigma^2 \bm I_D)^{-1}
\bm K_\ast
\\
\end{aligned}
\left\{\begin{aligned}
\bm K ={}& \bm X \bm V_0 \bm X^\mathsf{T}
\\
\bm K_{\ast} ={}& \bm X \bm V_0 \bm X_\ast^\mathsf{T}
\\
\bm K_{\ast\ast} ={}& \bm X_\ast \bm V_0 \bm X_\ast^\mathsf{T}
\\
\end{aligned}\right.
と、かなりシンプルな形で記述することができる。
カーネルトリック
ここで、行列 \bm K, \bm K_\ast, \bm K_{\ast\ast} の成分を展開して見てみよう。
\begin{aligned}
\bm K
={}&
\left[\begin{darray}{llcl}
\bm x_1^\mathsf{T} \bm V_0 \bm x_1 & \bm x_1^\mathsf{T} \bm V_0 \bm x_2 & \cdots & \bm x_1^\mathsf{T} \bm V_0 \bm x_D \\
\bm x_2^\mathsf{T} \bm V_0 \bm x_1 & \bm x_2^\mathsf{T} \bm V_0 \bm x_2 & \cdots & \bm x_2^\mathsf{T} \bm V_0 \bm x_D \\
\vdots & \vdots & \ddots & \vdots \\
\bm x_D^\mathsf{T} \bm V_0 \bm x_1 & \bm x_D^\mathsf{T} \bm V_0 \bm x_2 & \cdots & \bm x_D^\mathsf{T} \bm V_0 \bm x_D \\
\end{darray}\right]
\\ \\
\bm K_\ast
={}&
\left[\begin{darray}{llcl}
\bm x_1^\mathsf{T} \bm V_0 \bm x_{1^\ast} & \bm x_1^\mathsf{T} \bm V_0 \bm x_{2^\ast} & \cdots & \bm x_1^\mathsf{T} \bm V_0 \bm x_{D^\ast} \\
\bm x_2^\mathsf{T} \bm V_0 \bm x_{1^\ast} & \bm x_2^\mathsf{T} \bm V_0 \bm x_{2^\ast} & \cdots & \bm x_2^\mathsf{T} \bm V_0 \bm x_{D^\ast} \\
\vdots & \vdots & \ddots & \vdots \\
\bm x_D^\mathsf{T} \bm V_0 \bm x_{1^\ast} & \bm x_D^\mathsf{T} \bm V_0 \bm x_{2^\ast} & \cdots & \bm x_D^\mathsf{T} \bm V_0 \bm x_{D^\ast} \\
\end{darray}\right]
\\ \\
\bm K_{\ast \ast}
={}&
\left[\begin{darray}{llcl}
\bm x_{1^\ast}^\mathsf{T} \bm V_0 \bm x_{1^\ast} &
\bm x_{1^\ast}^\mathsf{T} \bm V_0 \bm x_{2^\ast} &
\cdots &
\bm x_{1^\ast}^\mathsf{T} \bm V_0 \bm x_{D^\ast}
\\
\bm x_{2^\ast}^\mathsf{T} \bm V_0 \bm x_{1^\ast} &
\bm x_{2^\ast}^\mathsf{T} \bm V_0 \bm x_{2^\ast} &
\cdots &
\bm x_{2^\ast}^\mathsf{T} \bm V_0 \bm x_{D^\ast}
\\
\vdots & \vdots & \ddots & \vdots
\\
\bm x_{D^\ast}^\mathsf{T} \bm V_0 \bm x_{1^\ast} &
\bm x_{D^\ast}^\mathsf{T} \bm V_0 \bm x_{2^\ast} &
\cdots &
\bm x_{D^\ast}^\mathsf{T} \bm V_0 \bm x_{D^\ast}
\end{darray}\right]
\end{aligned}
大抵の場合は、もう少し端折って次のように書かれる。これにも慣れておきたい。
\begin{aligned}
\bm K
={}&
\left[\begin{darray}{c}
\bm x_i^\mathsf{T} \bm V_0 \bm x_j
\end{darray}\right]_{ij}
&& \in \R^{D \times D} \\
\bm K_{\ast}
={}&
\left[\begin{darray}{c}
\bm x_{i}^\mathsf{T} \bm V_0 \bm x_{j^\ast}
\end{darray}\right]_{ij^\ast}
&& \in \R^{D \times D^\ast} \\
\bm K_{\ast\ast}
={}&
\left[\begin{darray}{c}
\bm x_{i^\ast}^\mathsf{T} \bm V_0 \bm x_{j^\ast}
\end{darray}\right]_{i^\ast j^\ast}
&& \in \R^{D^\ast \times D^\ast}
\end{aligned}
これを纏めて次のように表すことにしよう。
\begin{aligned}
\left[\begin{darray}{c}
\bm K & \bm K_\ast \\
\bm K_\ast^\mathsf{T} & \bm K_{\ast\ast}
\end{darray}\right]
={}&
\left[\begin{darray}{c}
\bm x_i^\mathsf{T} \bm V_0 \bm x_j
\end{darray}\right]_{ij}
\in{} \R^{(D + D^\ast) \times (D + D^\ast)} \\
\end{aligned}
どうやら、同じ形の項 \bm x_i^\mathsf{T} \bm V_0 \bm x_j が何度も繰り返し出現するらしい。そこで、これを
k_{ij} = k(\bm x_i, \bm x_j) = \bm x_i^\mathsf{T} \bm V_0 \bm x_j
と書き直してしまう。すると次のようになる。
\begin{aligned}
\left[\begin{darray}{c}
\bm K & \bm K_\ast \\
\bm K_\ast^\mathsf{T} & \bm K_{\ast\ast}
\end{darray}\right]
={}&
\left[\begin{darray}{c}
k_{ij}
\end{darray}\right]_{ij}
\in{} \R^{(d + d^\ast) \times (d + d^\ast)} \\
\end{aligned}
さて、もとの定義どおりであれば
k_{ij}
= \bm x_i^\mathsf{T} \bm V_0 \bm x_j
= \sum_{k, l} {V_0}_{kl} x_{ik}x_{jl}
となるが、ここでカーネル法による線形回帰の場合と同様に、k としてもっと一般に \bm x_i と \bm x_j を入力とする関数を許す。
k_{ij} = k(\bm x_i, \bm x_j)
これにより、カーネル法と似たような理屈で、非常に表現力の高い回帰モデルを作成できる。
カーネル法の命名を借りて、この関数 k をカーネル関数 (kernel function) という。そしてカーネル関数を並べた行列 \bm K をカーネル行列 (kernel matrix) という。カーネル関数として要求される条件はカーネル法の場合と同じで、
- \bm K^\mathsf{T} = \bm K
- \bm u^\mathsf{T} \bm K \bm u \ge 0 \quad {}^\forall \bm u \in \mathbb R
すなわちカーネル行列が半正定値行列となる必要がある。
Discussion