はしくれエンジニアもどきのメモ

情報・Web系技術・Englishの勉強メモ・備忘録です。

2つの正規分布の密度(pdf)の積から導出できる正規分布

2つの正規分布の密度(pdf)の積から導出できる正規分布

正規分布の積もまた正規分布になるので,その正規分布のパラメータ(平均,分散)を導出する.

(なお,確率変数の積ではない)

参考:

1次元正規分布の場合

導出

1次元正規分布に従う確率変数$x$について,平均と分散パラメータが異なる2つの正規分布を考える.


\begin{eqnarray}
\text{Norm}(x | \mu_{1}, \sigma_{1}^{2} ) \cdot \text{Norm}(x | \mu_{2}, \sigma_{2}^{2} )
&=&
\frac{1}{\sqrt{2 \pi \sigma_{1}^{2}}}\exp{[-0.5(x - \mu_{1})^{2} / \sigma_{1}^{2} ] }
\frac{1}{\sqrt{2 \pi \sigma_{2}^{2}}}\exp{[ -0.5(x - \mu_{2})^{2} / \sigma_{2}^{2} ] } \\\\
&=& \frac{1}{(2 \pi)^{ \frac{2}{2} } (\sigma_{1}^{2} \sigma_{2}^{2})^{\frac{1}{2}} } \exp{\left[- \frac{1}{2} \left( \frac{ ( x - \mu_{1} )^{2} }{ \sigma_{1}^{2} } + \frac{ ( x - \mu_{2} )^{2} }{ \sigma_{2}^{2} } \right) \right] }
\end{eqnarray}

結果として以下の正規分布の積になるのでこれを導出する.


\begin{eqnarray}
\text{Norm}(x | \mu_{1}, \sigma_{1}^{2} ) \cdot \text{Norm}(x | \mu_{2}, \sigma_{2}^{2} )
&=&
 \text{Norm}(\mu_{2} | \mu_{1}, \sigma_{1}^{2} + \sigma_{2}^{2} )
\cdot
\text{Norm}\left( x |(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1})((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}), ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} \right) \\\\
&=& \text{Norm}\left( \mu_{1} | \mu_{2} , \sigma_{1}^{2} + \sigma_{2}^{2} \right)
\cdot
\text{Norm}\left( x | ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1}((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}), ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} \right)
\end{eqnarray}

expの中を平方完成する


\begin{eqnarray}
(\sigma_{1}^{2})^{-1} (x^{2} - 2x \mu_{1} +\mu_{1}^{2})
+ (\sigma_{2}^{2})^{-1} (x^{2} - 2x \mu_{2} +\mu_{2}^{2})
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}) x^{2} -2((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}) x
+ ((\sigma_{1}^{2})^{-1}\mu_{1}^{2} + (\sigma_{2}^{2})^{-1} \mu_{2}^{2} ) \\\\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}) \left\{ x^{2} -2 \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}) x}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right\}
+ ((\sigma_{1}^{2})^{-1}\mu_{1}^{2} + (\sigma_{2}^{2})^{-1} \mu_{2}^{2} ) \\\\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ x^{2} -2 \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}) x}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} + \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})^{2}}{((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{2}} - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})^{2}}{((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{2}}
\right\}
+ ((\sigma_{1}^{2})^{-1}\mu_{1}^{2} + (\sigma_{2}^{2})^{-1} \mu_{2}^{2} ) \\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2} - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})^{2}}{((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{2}}
\right\}
+ ((\sigma_{1}^{2})^{-1}\mu_{1}^{2} + (\sigma_{2}^{2})^{-1} \mu_{2}^{2} ) \\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\}
- \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})^{2}}{((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})}
+ ((\sigma_{1}^{2})^{-1}\mu_{1}^{2} + (\sigma_{2}^{2})^{-1} \mu_{2}^{2} ) \\\\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\}
- \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})^{2}}{((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})}
+ \frac{((\sigma_{1}^{2})^{-1}\mu_{1}^{2} + (\sigma_{2}^{2})^{-1} \mu_{2}^{2} ) ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\}
- \frac{(\sigma_{1}^{2})^{-2}\mu_{1}^{2} + 2(\sigma_{1}^{2})^{-1}\mu_{1}(\sigma_{2}^{2})^{-1}\mu_{2} + (\sigma_{2}^{2})^{-2}\mu_{2}^{2} }{((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})}
+ \frac{(\sigma_{1}^{2})^{-2}\mu_{1}^{2} + (\sigma_{1}^{2})^{-1}(\sigma_{2}^{2})^{-1} (\mu_{1}^{2} + \mu_{2}^{2} ) + (\sigma_{2}^{2})^{-2}\mu_{2}^{2} }{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\}
+ \frac{ (\sigma_{1}^{2})^{-1}(\sigma_{2}^{2})^{-1} (\mu_{1}^{2} + \mu_{2}^{2} ) - 2(\sigma_{1}^{2})^{-1}\mu_{1}(\sigma_{2}^{2})^{-1}\mu_{2} }{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \\\\
&=& ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\}
+ \frac{ (\sigma_{1}^{2})^{-1}(\sigma_{2}^{2})^{-1} (\mu_{1} - \mu_{2} )^{2} }{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \\\\
\end{eqnarray}

これでexpを2つに分解できる.

元の式に代入して


\begin{eqnarray}
\text{Norm}(x | \mu_{1}, \sigma_{1}^{2} ) \cdot \text{Norm}(x | \mu_{2}, \sigma_{2}^{2} )
&=& \frac{1}{(2 \pi)^{ \frac{2}{2} } (\sigma_{1}^{2} \sigma_{2}^{2})^{\frac{1}{2}} } \exp{\left[- \frac{1}{2} \left( ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\}
+ \frac{ (\sigma_{1}^{2})^{-1}(\sigma_{2}^{2})^{-1} (\mu_{1} - \mu_{2} )^{2} }{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right) \right]} \\\\
&=& \frac{1}{(2 \pi)^{ \frac{2}{2} } (\sigma_{1}^{2} \sigma_{2}^{2})^{\frac{1}{2}} } \exp{\left( -\frac{1}{2}\frac{ (\sigma_{1}^{2})^{-1}(\sigma_{2}^{2})^{-1} (\mu_{1} - \mu_{2} )^{2} }{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)}  \exp{\left[- \frac{1}{2} \left( ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})
\left\{ \left( x - \frac{((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\} \right) \right]} \\\\
&=& \frac{1}{(2 \pi)^{ \frac{2}{2} } (\sigma_{1}^{2} \sigma_{2}^{2})^{\frac{1}{2}} }  \exp{\left( -\frac{1}{2}\frac{ (\mu_{1} - \mu_{2} )^{2} }{ \frac{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}}{(\sigma_{1}^{2})^{-1}(\sigma_{2}^{2})^{-1}} } \right)}
\exp{ \left[ - \frac{1}{2} \left( \frac{1}{ ( (\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} }
\left\{ \left( x - \frac{( ( \sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\} \right) \right]} \\\\
&=& \frac{1}{(2 \pi)^{ \frac{2}{2} } (\sigma_{1}^{2} \sigma_{2}^{2})^{\frac{1}{2}} }  \exp{\left( -\frac{1}{2}\frac{ (\mu_{1} - \mu_{2} )^{2} }{ \sigma_{1}^{2} + \sigma_{2}^{2} } \right)}
\exp{ \left[ - \frac{1}{2} \left( \frac{1}{ ( (\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} }
\left\{ \left( x - \frac{( ( \sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\} \right) \right]}
\end{eqnarray}

exp外の係数を式変形する. expの中の分散項は以下2つになる.


\sigma_{1}^{2} + \sigma_{2}^{2} \\\\
\frac{1}{ \frac{1}{\sigma_{1}^{2}} + \frac{1}{\sigma_{2}^{2}} } \\\\

 \sigma_{1}^{2} \sigma_{2}^{2} を式変形すると,以下のように2つに分解できる.


\begin{eqnarray}
\sigma_{1}^{2} \sigma_{2}^{2}
= \frac{\sigma_{1}^{2} \sigma_{2}^{2}}{ \sigma_{1}^{2} + \sigma_{2}^{2} }  (\sigma_{1}^{2} + \sigma_{2}^{2})
= \frac{1}{ (\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1} }  (\sigma_{1}^{2} + \sigma_{2}^{2}) \\\\
\end{eqnarray}

最終的に2つの正規分布に分けることができる.


\begin{eqnarray}
\text{Norm}(x | \mu_{1}, \sigma_{1}^{2} ) \cdot \text{Norm}(x | \mu_{2}, \sigma_{2}^{2} )
&=& \frac{1}{(2 \pi)^{ \frac{2}{2} } (\sigma_{1}^{2} \sigma_{2}^{2})^{\frac{1}{2}} }  \exp{\left( -\frac{1}{2}\frac{ (\mu_{1} - \mu_{2} )^{2} }{ \sigma_{1}^{2} + \sigma_{2}^{2} } \right)}
\exp{ \left[ - \frac{1}{2} \left( \frac{1}{ ( (\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} }
\left\{ \left( x - \frac{( ( \sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2})}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\} \right) \right]}  \\\\
&=& \frac{1}{(2 \pi)^{ \frac{1}{2} } (\sigma_{1}^{2} + \sigma_{2}^{2})^{\frac{1}{2}} } \exp{\left( -\frac{1}{2}\frac{ (\mu_{1} - \mu_{2} )^{2} }{ \sigma_{1}^{2} + \sigma_{2}^{2} } \right)}
\cdot
\frac{1}{(2 \pi)^{ \frac{1}{2} } (((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} )^{\frac{1}{2}} } \exp{ \left[ - \frac{1}{2} \left( \frac{1}{ ( (\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} }
\left\{ \left( x - \frac{ (\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}}{(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1}} \right)^{2}
\right\} \right) \right]} \\\\
&=& \text{Norm}\left[\mu_{2} | \mu_{1}, \sigma_{1}^{2} + \sigma_{2}^{2} \right]
\cdot
\text{Norm}\left[ x |(\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1})((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}), ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} \right] \\\\
&=& \text{Norm}\left[ \mu_{1} | \mu_{2} , \sigma_{1}^{2} + \sigma_{2}^{2} \right]
\cdot
\text{Norm}\left[ x |((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1}((\sigma_{1}^{2})^{-1}\mu_{1} + (\sigma_{2}^{2})^{-1} \mu_{2}), ((\sigma_{1}^{2})^{-1} + (\sigma_{2}^{2})^{-1})^{-1} \right]
\end{eqnarray}

 \text{Norm}( \mu_{2} | \mu_{1}, \sigma_{1}^{2} + \sigma_{2}^{2} ),\text{Norm}( \mu_{1} | \mu_{2} , \sigma_{1}^{2} + \sigma_{2}^{2} ) は,正規分布の密度だが,$x = \mu_{2}, x=\mu_{1}$ で固定したときで定数になる.

plot

import scipy as sp
from scipy import stats
import matplotlib.pyplot as plt

%matplotlib inline

x = sp.linspace(-5, 5, 1000)
mu1, s21 = (0, 1)
mu2, s22 = (0, 1)

N1 = stats.norm(loc=mu1, scale=sp.sqrt(s21))
N2 = stats.norm(loc=mu2, scale=sp.sqrt(s22))
prod = N1.pdf(x) * N2.pdf(x)
c = stats.norm(loc=mu1, scale=sp.sqrt(s21+s22)).pdf(mu2)
print("constant:", c)

prod_s2 = 1 / ( 1/s21 + 1/s22)
prod_m = prod_s2 * (mu1 / s21 + mu2 / s22)
print(f"prodN({prod_m},{prod_s2})")
prodN = stats.norm(loc=prod_m, scale=sp.sqrt(prod_s2))

plt.plot(x, N1.pdf(x), linestyle="--", label="N1")
plt.plot(x, N2.pdf(x), linestyle="--", label="N2")
plt.plot(x, prod, label="prod")
s = prod/c
plt.plot(x, s, label="prod/constant", linestyle="--", alpha=0.5)
print("sum prod/c:", sp.sum((s[:-1] + s[1:]) * sp.diff(x)/2))
plt.plot(x, prodN.pdf(x), label=f"prodN({prod_m: .2f}, {prod_s2: .2f})", alpha=0.5)

plt.legend()
plt.tight_layout()
plt.show()

1次元正規分布のpdfの積

多次元正規分布の場合

導出

参考:Completing the square

以下2つの正規分布を定義し,それらのpdfの積を考える.

$$ \text{Norm}(\vec{x}|\vec{a}, \mathbf{A}) = \frac{1}{(2 \pi)^{D/2} |\mathbf{A}|^{1/2} } \exp{[(\vec{x} - \vec{a})^{T}\mathbf{A}^{-1}(\vec{x} - \vec{a}) ]} $$

$$ \text{Norm}(\vec{x}|\vec{b}, \mathbf{B}) = \frac{1}{(2 \pi)^{D/2} | \mathbf{B}|^{1/2} } \exp{[ -\frac{1}{2}(\vec{x} - \vec{b})^{T} \mathbf{B}^{-1} (\vec{x} - \vec{b}) ] } $$


\begin{eqnarray}
\text{Norm}(\vec{x}|\vec{a}, \mathbf{A}) \cdot \text{Norm}(\vec{x}|\vec{b}, \mathbf{B})
&=& \frac{1}{(2\pi)^{D} |\mathbf{A}|^{1/2}  | \mathbf{B}|^{1/2} }
\exp{ \left\{ -\frac{1}{2} \left( (\vec{x} - \vec{a})^{T}\mathbf{A}^{-1}(\vec{x} - \vec{a}) +  (\vec{x} - \vec{b})^{T}\mathbf{B}^{-1}(\vec{x} - \vec{b}) \right) \right\} }
\end{eqnarray}

結果的に,以下の正規分布になるのでこれを導出する.


\begin{eqnarray}
\text{Normal}_{\vec{x}}\left[ \vec{a}, \mathbf{A} \right]\text{Normal}_{\vec{x}}\left[ \vec{b}, \mathbf{B} \right]
&=&
\kappa \cdot \text{Normal}_{\vec{x}}\left[ (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}(\mathbf{A}^{-1}\vec{a} + \mathbf{B}^{-1}\vec{b}), (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \right]
\end{eqnarray}

\begin{eqnarray}
\kappa
&=& \text{Normal}_{\vec{a}}\left[\vec{b}, \mathbf{A} + \mathbf{B} \right] \\\\
&=& \text{Normal}_{\vec{b}} \left[\vec{a}, \mathbf{A} + \mathbf{B} \right]
\end{eqnarray}

まず,expの中を展開する. 2次形式の平方完成が必要になる.


\begin{eqnarray}
x^{T} (\mathbf{A}^{-1} + \mathbf{B}^{-1}) \vec{x}
- \vec{x}^{T} (\mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b} )
- (\vec{a}^{T}\mathbf{A}^{-1} + \vec{b}^{T} \mathbf{B}^{-1} )\vec{x}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
\end{eqnarray}

共分散行列は対称行列, 対称行列の逆行列も対称行列より,以下の関係が成立することに注意する.

$$ (\mathbf{A}^{-1})^{T} = \mathbf{A}^{-1}\\ (\mathbf{B}^{-1})^{T} = \mathbf{B}^{-1}\\ $$

そして,以下の記号で置き換える.

$$ \mathbf{C} = \mathbf{A}^{-1} + \mathbf{B}^{-1} \\ \vec{d} = \mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b}\\ $$

代入すると,


\begin{eqnarray}
x^{T} (\mathbf{A}^{-1} + \mathbf{B}^{-1}) \vec{x}
- \vec{x}^{T} (\mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b} )
- (\vec{a}^{T}\mathbf{A}^{-1} + \vec{b}^{T} \mathbf{B}^{-1} )\vec{x}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
&=& x^{T} \mathbf{C} \vec{x}
- \vec{x}^{T} \vec{d}
- \vec{d}^{T}\vec{x}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
\end{eqnarray}

2次形をつくるために$+ \vec{d}^{T}\mathbf{C}^{-1}\vec{d} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d} = 0$を追加する.


\begin{eqnarray}
x^{T} \mathbf{C} \vec{x}
- \vec{x}^{T} \vec{d}
- \vec{d}^{T}\vec{x}
+  \vec{d}^{T}\mathbf{C}^{-1}\vec{d} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
\end{eqnarray}

$\mathbf{C}^{-1}\mathbf{C}=\mathbf{C}\mathbf{C}^{-1}=\mathbf{I}$とおいて各項に入れる.


\begin{eqnarray}
x^{T} \mathbf{C} \vec{x}
- \vec{x}^{T} \mathbf{C}\mathbf{C}^{-1} \vec{d}
- \vec{d}^{T} \mathbf{C}^{-1}\mathbf{C}\vec{x}
+ \vec{d}^{T} \mathbf{C}^{-1}\mathbf{C} \mathbf{C}^{-1}\vec{d} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
\end{eqnarray}

 \mathbf{C} = \mathbf{\Sigma}^{-1}, \mathbf{C}^{-1}\vec{d}=\vec{\mu} とおいて


\begin{eqnarray}
x^{T} \mathbf{\Sigma}^{-1}\vec{x}
- \vec{x}^{T} \mathbf{\Sigma}^{-1}\vec{\mu}
- \vec{\mu}^{T} \mathbf{\Sigma}^{-1} \vec{x}
+ \vec{\mu}^{T} \mathbf{\Sigma}^{-1} \vec{\mu} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
&=&
(x-\vec{\mu})^{T} \mathbf{\Sigma}^{-1}(\vec{x}
- \vec{\mu}) - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}
+ (\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b})
\end{eqnarray}

よって,expは,2つにわけることができる.


\exp{\left( -\frac{1}{2} (x-\vec{\mu})^{T} \mathbf{\Sigma}^{-1}(\vec{x}
- \vec{\mu}) \right)}
\exp{\left( -\frac{1}{2}(\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}) \right)}

1つの正規分布


\begin{eqnarray}
\vec{\mu}
&=& \mathbf{C}^{-1}\vec{d} = (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}
(\mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b}) \\\\
\mathbf{\Sigma}
&=& \mathbf{C}^{-1} = (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \\\\
\text{Norm}(\vec{x} | (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}
(\mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b}), (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1})
\end{eqnarray}

次に定数項に該当する正規分布を導出する. 以下を展開する.

$$ \exp{\left( -\frac{1}{2}(\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}) \right)} $$


\begin{eqnarray}
\vec{d}^{T}\mathbf{C}^{-1}\vec{d}
&=& ( \mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b})^{T}(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}( \mathbf{A}^{-1}\vec{a} + \mathbf{B}^{-1}\vec{b}) \\\\
&=& ( \vec{a}^{T}\mathbf{A}^{-1} + \vec{b}^{T}\vec{B}^{-1})(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}( \mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b})\\\\
&=& \vec{a}^{T}\mathbf{A}^{-1} (\mathbf{A}^{-1}+ \mathbf{B}^{-1})^{-1} \mathbf{A}^{-1}\vec{a}
+ \vec{a}^{T}\mathbf{A}^{-1} (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \mathbf{B}^{-1}\vec{b}
+ \vec{b}^{T}\mathbf{B}^{-1}(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \mathbf{B}^{-1}\vec{b}
+ \vec{b}^{T}\mathbf{B}^{-1}(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \mathbf{A}^{-1}\vec{a}
\end{eqnarray}

さらに各項を展開して変形していく.


\begin{eqnarray}
\vec{a}^{T} \mathbf{A}^{-1} (\mathbf{A}^{-1}+ \mathbf{B}^{-1})^{-1} \mathbf{A}^{-1}\vec{a}
&=& \vec{a}^{T}(\mathbf{A}\mathbf{A}^{-1}+ \mathbf{A}\mathbf{B}^{-1})^{-1} \mathbf{A}^{-1}\vec{a}\\\\
&=& \vec{a}^{T}(\mathbf{A}\mathbf{A}^{-1}+ \mathbf{A}\mathbf{B}^{-1})^{-1} \mathbf{B}^{-1}\mathbf{B}\mathbf{A}^{-1}\vec{a}\\\\
&=& \vec{a}^{T}(\mathbf{B} + \mathbf{A})^{-1} \mathbf{B}\mathbf{A}^{-1}\vec{a}\\\\
\end{eqnarray}

\begin{eqnarray}
\vec{b}^{T}\mathbf{B}^{-1}(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \mathbf{B}^{-1}\vec{b}
&=& \vec{b}^{T}(\mathbf{B}\mathbf{A}^{-1} + \mathbf{B}\mathbf{B}^{-1})^{-1} \mathbf{B}^{-1} \vec{b}\\\\
&=& \vec{b}^{T}(\mathbf{B}\mathbf{A}^{-1} + \mathbf{B}\mathbf{B}^{-1})^{-1} \mathbf{A}^{-1} \mathbf{A} \mathbf{B}^{-1} \vec{b}\\\\
&=& \vec{b}^{T}(\mathbf{B}\mathbf{A}^{-1}\mathbf{A} + \mathbf{B}\mathbf{B}^{-1}\mathbf{A})^{-1} \mathbf{A} \mathbf{B}^{-1} \vec{b}\\\\
&=& \vec{b}^{T}(\mathbf{B} + \mathbf{A})^{-1} \mathbf{A} \mathbf{B}^{-1} \vec{b}\\\\
\end{eqnarray}

\begin{eqnarray}
\vec{a}^{T}\mathbf{A}^{-1} (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \mathbf{B}^{-1}\vec{b}
&=& \vec{a}^{T} (\mathbf{A}\mathbf{A}^{-1}\mathbf{B} + \mathbf{A}\mathbf{B}^{-1}\mathbf{B})^{-1} \vec{b}\\\\
&=& \vec{a}^{T} (\mathbf{B} +\mathbf{A})^{-1} \vec{b}\\\\
\end{eqnarray}

\begin{eqnarray}
\vec{b}^{T}\mathbf{B}^{-1}(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} \mathbf{A}^{-1}\vec{a}
&=& \vec{b}^{T}(\mathbf{B}\mathbf{A}^{-1}\mathbf{A} + \mathbf{B}\mathbf{B}^{-1}\mathbf{A})^{-1} \vec{a} \\\\
&=& \vec{b}^{T}(\mathbf{B}+\mathbf{A})^{-1} \vec{a} \\\\
\end{eqnarray}

まとめて代入すると,


\begin{eqnarray}
\vec{a}^{T} \mathbf{A}^{-1} \vec{a} + \vec{b}^{T} \mathbf{B}^{-1} \vec{b} - \vec{d}^{T} \mathbf{C}^{-1} \vec{d}
&=& \vec{a}^{T} \mathbf{A}^{-1} \vec{a} + \vec{b}^{T} \mathbf{B}^{-1} \vec{b} - (\vec{a}^{T}(\mathbf{B} + \mathbf{A})^{-1} \mathbf{B}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T}(\mathbf{B} + \mathbf{A})^{-1} \mathbf{A} \mathbf{B}^{-1} \vec{b} + \vec{a}^{T} (\mathbf{B} +\mathbf{A})^{-1} \vec{b} + \vec{b}^{T}(\mathbf{B}+\mathbf{A})^{-1} \vec{a})\\\\
&=& \vec{a}^{T} (\mathbf{A}^{-1} - (\mathbf{B} + \mathbf{A})^{-1} \mathbf{B}\mathbf{A}^{-1}) \vec{a}
+ \vec{b}^{T} (\mathbf{B}^{-1} - (\mathbf{B} + \mathbf{A})^{-1} \mathbf{A} \mathbf{B}^{-1}) \vec{b}
- \vec{a}^{T} (\mathbf{B} +\mathbf{A})^{-1} \vec{b}
- \vec{b}^{T}(\mathbf{B}+\mathbf{A})^{-1} \vec{a} \\\\
\end{eqnarray}

右辺の2つ目までの項を変形する.


\begin{eqnarray}
\vec{a}^{T} (\mathbf{A} + \mathbf{B})^{-1}(\mathbf{A} + \mathbf{B})(\mathbf{A}^{-1} - (\mathbf{B} + \mathbf{A})^{-1} \mathbf{B}\mathbf{A}^{-1}) \vec{a}
&=& \vec{a}^{T} (\mathbf{A} + \mathbf{B})^{-1}((\mathbf{A} + \mathbf{B})\mathbf{A}^{-1} - \mathbf{B}\mathbf{A}^{-1}) \vec{a}\\\\
&=& \vec{a}^{T} (\mathbf{A} + \mathbf{B})^{-1} \vec{a}
\end{eqnarray}

\begin{eqnarray}
\vec{b}^{T} (\mathbf{B}^{-1} - (\mathbf{B} + \mathbf{A})^{-1} \mathbf{A} \mathbf{B}^{-1}) \vec{b}
&=& \vec{b}^{T} (\mathbf{B} + \mathbf{A})^{-1}(\mathbf{B} + \mathbf{A}) (\mathbf{B}^{-1} - (\mathbf{B} + \mathbf{A})^{-1} \mathbf{A} \mathbf{B}^{-1}) \vec{b}\\\\
&=& \vec{b}^{T} (\mathbf{B} + \mathbf{A})^{-1}((\mathbf{B} + \mathbf{A})\mathbf{B}^{-1} - \mathbf{A} \mathbf{B}^{-1}) \vec{b}\\\\
&=& \vec{b}^{T} (\mathbf{B} + \mathbf{A})^{-1}\vec{b}
\end{eqnarray}

よって,まとめると


\begin{eqnarray}
\vec{a}^{T} \mathbf{A}^{-1} \vec{a} + \vec{b}^{T} \mathbf{B}^{-1} \vec{b} - \vec{d}^{T} \mathbf{C}^{-1} \vec{d}
&=& \vec{a}^{T} (\mathbf{A} + \mathbf{B})^{-1} \vec{a}
- \vec{a}^{T} (\mathbf{B} +\mathbf{A})^{-1} \vec{b}
- \vec{b}^{T}(\mathbf{B}+\mathbf{A})^{-1} \vec{a}
+ \vec{b}^{T} (\mathbf{B} + \mathbf{A})^{-1}\vec{b} \\\\
&=& (\vec{a} - \vec{b})^{T} (\mathbf{A} + \mathbf{B})^{-1} (\vec{a} - \vec{b}) \\\\
\end{eqnarray}

expの式は,


\exp{\left( -\frac{1}{2}(\vec{a}^{T}\mathbf{A}^{-1}\vec{a} + \vec{b}^{T} \mathbf{B}^{-1}\vec{b} - \vec{d}^{T}\mathbf{C}^{-1}\vec{d}) \right)}
= \exp{\left( -\frac{1}{2}(\vec{a} - \vec{b})^{T} (\mathbf{A} + \mathbf{B})^{-1} (\vec{a} - \vec{b}) \right)}

よって,以下の正規分布の密度になる.


\begin{eqnarray}
\vec{\mu}_{0} &=& \vec{b}\\\\
\mathbf{\Sigma}_{0} &=& \mathbf{A} + \mathbf{B}\\\\
\text{Norm}(\vec{x}=\vec{b}| \vec{a}, \mathbf{A} + \mathbf{B})
&=& \text{Norm}(\vec{x}=\vec{a}| \vec{b}, \mathbf{A} + \mathbf{B}) \\\\
\end{eqnarray}

最後に,exp外の係数をまとめる.


\begin{eqnarray}
|\Sigma_{0}|
&=& |\mathbf{A} + \mathbf{B}| \\
&=& |\mathbf{A} + \mathbf{B}| |\mathbf{A}^{-1} + \mathbf{B}^{-1}|^{-1}|\mathbf{A}^{-1} + \mathbf{B}^{-1}|  \\\\
&=& |AB||AB|^{-1}|\mathbf{A} + \mathbf{B}| |(\mathbf{A}^{-1} + \mathbf{B}^{-1})|^{-1} |\mathbf{A}^{-1} + \mathbf{B}^{-1}|  \\\\
&=& |AB||B^{-1}A^{-1}||\mathbf{A} + \mathbf{B}| |(\mathbf{A}^{-1} + \mathbf{B}^{-1})|^{-1} |\mathbf{A}^{-1} + \mathbf{B}^{-1}|  \\\\
&=&|AB||A^{-1}||\mathbf{A} + \mathbf{B}||B^{-1}| |(\mathbf{A}^{-1} + \mathbf{B}^{-1})|^{-1} |\mathbf{A}^{-1} + \mathbf{B}^{-1}|  \\\\
&=&|AB||A^{-1}(\mathbf{A} + \mathbf{B})B^{-1}| |(\mathbf{A}^{-1} + \mathbf{B}^{-1})|^{-1} |\mathbf{A}^{-1} + \mathbf{B}^{-1}|  \\\\
&=&|AB||\mathbf{A}^{-1} + \mathbf{B}^{-1}| |(\mathbf{A}^{-1} + \mathbf{B}^{-1})|^{-1} |\mathbf{A}^{-1} + \mathbf{B}^{-1}|  \\\\
&=&|AB||\mathbf{A}^{-1} + \mathbf{B}^{-1}|
\end{eqnarray}

|\mathbf{\Sigma}|
= |(\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1} |
= |(\mathbf{A}^{-1} + \mathbf{B}^{-1})|^{-1}

|\Sigma_{0}||\mathbf{\Sigma}|  = |AB| = |A||B|

よって係数の分母の行列式が成立する.


|\Sigma_{0}|^{\frac{1}{2}}|\mathbf{\Sigma}|^{\frac{1}{2}}  = |AB|^{\frac{1}{2}} = |A|^{\frac{1}{2}}|B|^{\frac{1}{2}}

すべてをまとめると,


\begin{eqnarray}
\text{Norm}(\vec{x} | \vec{a}, \mathbf{A} ) \cdot \text{Norm}(\vec{x} | \vec{b}, \mathbf{B} )
&=& \text{Norm}(\vec{a}| \vec{b}, \mathbf{A} + \mathbf{B})
\text{Norm}(\vec{x} | (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}
(\mathbf{A}^{-1}\vec{a} + \vec{B}^{-1}\vec{b}), (\mathbf{A}^{-1} + \mathbf{B}^{-1})^{-1}) \\\\
\end{eqnarray}

n回の積の場合

n回積をとった場合は以下の資料にまとめられており,同様に正規分布になる.

P.A. Bromiley,"Products and Convolutions of Gaussian Probability Density Functions", http://www.tina-vision.net/docs/memos/2003-003.pdf