最小二乗法が使えると人生が捗る

最小二乗法が使えると人生が捗る!!

{ \displaystyle
{\bf A} {\bf x} = {\bf y}
}

という数式があったとき({ \displaystyle \bf A } は行列、{ \displaystyle {\bf x}, {\bf y} } はベクトル)

{ \displaystyle \bf x } は擬似逆行列 { \displaystyle \bf A^+ } を使って、

{ \displaystyle
{\bf x} = {\bf A^+} {\bf y}
}

で表せる。
なぜかはよくわからないけど、これで解を求めるといい感じに最小二乗法っぽくなっている。

もっと具体的な例をあげる。
ある長さ2のベクトル { \displaystyle \bf a } に対して、2x2の正方行列 { \displaystyle \bf X } をかけたやつ { \displaystyle \bf y } を考える

{ \displaystyle
{\bf X} {\bf a} = {\bf y}
}

{ \displaystyle \bf a } を求めるなら、{ \displaystyle \bf X }逆行列{ \displaystyle \bf y } にかければよいが、
{ \displaystyle \bf X } の要素を求めたいケースがある。

そういうときは、一度行列の掛け算を展開する

{ \displaystyle
\begin{bmatrix}
x_1 & x_2 \\
x_3 & x_4
\end{bmatrix}
\begin{bmatrix}
a_1 \\
a_2
\end{bmatrix} = 
\begin{bmatrix}
y_1 \\
y_2
\end{bmatrix}
}

2本の式に直す

{ \displaystyle
a_1 x_1 + a_2 x_2 = y_1 \\
a_1 x_3 + a_2 x_4 = y_2
}

これを { \displaystyle \bf X } の要素を並べるように行列に戻す
{ \displaystyle
\begin{bmatrix}
a_1 & a_2 & 0 & 0\\
0 & 0 & a_1 & a_2
\end{bmatrix}
\begin{bmatrix}
x_1 \\
x_2 \\
x_3 \\
x_4
\end{bmatrix} = 
\begin{bmatrix}
y_1 \\
y_2
\end{bmatrix}
}

{ \displaystyle
{\bf A} {\bf x} = {\bf y}
}

独立している式が4本(パラメータの数)以上立てば { \displaystyle \bf X } の要素が最小二乗法で解ける。

{ \displaystyle
{\bf x} = {\bf A^+} {\bf y}
}