関数Gaussian_multiDimension_multi_eigen マニュアル

(The documentation of function Gaussian_multiDimension_multi_eigen)

Last Update: 2021/12/1


◆機能・用途(Purpose)

多次元ガウス分布 \[\begin{equation} f(\posx) =\frac{1}{\sqrt{(2\pi)^D|\myvector{\Sigma}|}} \exp\left[ -\frac{1}{2}(\posx-\myvector{x_{ave}})^T \myvector{\Sigma}^{-1} (\posx-\myvector{x_{ave}}) \right] \label{eq.definition} \end{equation}\] の複数の\(\posx\)における値を一括で求める。 計算に分散・共分散行列\(\myvector{\Sigma}\)の固有値分解を使用する。 ここで\(D\)は次元、\(\posx\)は\(D\)次元ベクトル、 \(\myvector{x_{ave}}\)はガウス分布の平均値(\(D\)次元ベクトル)、 \(\myvector{\Sigma}\)はガウス分布の共分散行列(サイズ:\(D\times D\))である。
Compute the values of a multi-dimension Gaussian distribution (eq. \ref{eq.definition}) for multiple \(\posx\) values using the eigenvalue decomposition of the variance-covariance matrix \(\myvector{\Sigma}\), where \(D\) is the dimension, \(\posx\) is a \(D\)-dimension vector, \(\myvector{x_{ave}}\) is an average of the Gaussian distribution which is also a \(D\)-dimension vector, and \(\myvector{\Sigma}\) is a covariance matrix of the Gaussian distribution which has a size of \(D\times D\).


◆形式(Format)

#include <gaussian.h>
inline double ∗Gaussian_multiDimension_multi_eigen
(const struct columnvector average,const struct matrix covariance,
  const int N,const struct columnvector ∗x)


◆引数(Arguments)

average ガウス分布の平均値ベクトル\(\myvector{x_{ave}}\)。
The average value vector \(\myvector{x_{ave}}\) of the Gaussian distribution.
covariance ガウス分布の共分散行列\(\myvector{\Sigma}\)。
The covariance matrix \(\myvector{\Sigma}\) of the Gaussian distribution.
N ガウス分布の値を求めたい変数値ベクトル\(\posx\)の個数。
The number of variable value vectors \(\posx\) for which the values of the Gaussian distribution are needed.
x ガウス分布の値を求めたい変数値ベクトル\(\posx\)を並べた配列。
An array composed of the variable value vectors \(\posx\) for which the values of the Gaussian distribution are needed.


◆戻り値(Return value)

(\ref{eq.definition})式に基づいて計算される\(f(\posx)\)の値を \(\posx=\)x[0],\(\cdots\),x[N-1]について並べた配列。
An array composed of the values of \(f(\posx)\) for \(\posx=\)x[0],\(\cdots\),x[N-1] calculated based on eq. (\ref{eq.definition}).


◆使用例(Example)

struct columnvector x[5];
struct columnvector average;
struct matrix covariance;
double ∗value =Gaussian_multiDimension_multi_eigen(average,covariance,5,x);


◆計算方法(Computation method)

\(\myvector{\Sigma}\)の固有値を\(\sigma_0^2,\cdots,\sigma_{D-1}^2\)、 対応する固有ベクトルを\(\myvector{v_0},\cdots,\myvector{v_{D-1}}\)とする。 \[\begin{equation} \myvector{\Sigma}= \begin{pmatrix} \myvector{v_0} & \cdots & \myvector{v_{D-1}} \end{pmatrix} \begin{pmatrix} \sigma_0^2 & 0 & \cdots & 0 \\ 0 & \ddots & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 0 & \cdots & 0 & \sigma_{D-1}^2 \end{pmatrix} \begin{pmatrix} \myvector{v_0}^T \\ \vdots \\ \myvector{v_{D-1}} \end{pmatrix} \label{eq.Sigma.eigen} \end{equation}\] \[\begin{equation} \myvector{\Sigma}^{-1}= \begin{pmatrix} \myvector{v_0} & \cdots & \myvector{v_{D-1}} \end{pmatrix} \begin{pmatrix} 1/\sigma_0^2 & 0 & \cdots & 0 \\ 0 & \ddots & \ddots & \vdots \\ \vdots & \ddots & \ddots & 0 \\ 0 & \cdots & 0 & 1/\sigma_{D-1}^2 \end{pmatrix} \begin{pmatrix} \myvector{v_0}^T \\ \vdots \\ \myvector{v_{D-1}} \end{pmatrix} =\sum_{i=0}^{D-1}\frac{\myvector{v_i}\myvector{v_i}^T}{\sigma_i^2} \label{eq.Sigma_inv.eigen} \end{equation}\] \[\begin{equation} |\myvector{\Sigma}|=\prod_{i=0}^{D-1}\sigma_i^2 \label{eq.detSigma} \end{equation}\] であるので(\ref{eq.definition})式は \[\begin{eqnarray} f(\posx) &=& \frac{1}{\sqrt{(2\pi)^D\prod_{i=0}^{D-1}\sigma_i^2}} \exp\left[ -\frac{1}{2}(\posx-\myvector{x_{ave}})^T\left( \sum_{i=0}^{D-1} \frac{\myvector{v_i}\myvector{v_i}^T}{\sigma_i^2} \right)(\posx-\myvector{x_{ave}})\right] \nonumber \\ &=& \frac{1}{\sqrt{(2\pi)^D}\prod_{i=0}^{D-1}\sigma_i} \exp\left[ -\frac{1}{2}\sum_{i=0}^{D-1} \frac{(\posx-\myvector{x_{ave}})^T\myvector{v_i} \myvector{v_i}^T(\posx-\myvector{x_{ave}})}{\sigma_i^2}\right] \nonumber \\ &=& \prod_{i=0}^{D-1}\left\{ \frac{1}{\sqrt{2\pi}\sigma_i} \exp\left[ -\frac{1}{2}\frac{(\posx-\myvector{x_{ave}})^T\myvector{v_i} \myvector{v_i}^T(\posx-\myvector{x_{ave}})} {\sigma_i^2} \right]\right\} \label{eq.use} \end{eqnarray}\] と書ける。この関数では
  1. \(\myvector{\Sigma}\)の固有値・固有ベクトルを求める (関数singularvalue_decomposition (matrix/inverse.h)使用)
  2. 各\(i\)について\(\myvector{v_i}^T(\posx-\myvector{x_{ave}})\)を求める
  3. (\ref{eq.use})式を用いて\(f(\posx)\)を求める
という手順で\(f(\posx)\)の計算を行う。
Let \(\sigma_0^2,\cdots,\sigma_{D-1}^2\) and \(\myvector{v_0},\cdots,\myvector{v_{D-1}}\) be eigenvalues and corresponding eigenvectors of \(\myvector{\Sigma}\), respectively. Then eq. (\ref{eq.definition}) can be rewritten as (\ref{eq.use}), where eqs (\ref{eq.Sigma.eigen})-(\ref{eq.detSigma}) were used. In this function, \(f(\posx)\) values are calculated with the following steps:
  1. eigenvalues and eigenvectors of \(\myvector{\Sigma}\) are determined (using function singularvalue_decomposition in matrix/inverse.h),
  2. the values of \(\myvector{v_i}^T(\posx-\myvector{x_{ave}})\) are computed for each \(i\), and
  3. the \(f(\posx)\) values are calculated using eq. (\ref{eq.use}).


◆検証(Validation)

この関数で求めた値が正しいことについては 関数Gaussian_multiDimensionと同じ検証によって確認した。
The values obtained by this function are validated by the same tests as those performed for function Gaussian_multiDimension.