思考ノイズ

無い知恵を絞りだす。無理はしない。

<はじパタ> 6.1.1 超平面の方程式

はじめてのパターン認識 6.1.1 超平面の方程式に関してのメモです。

はじめてのパターン認識

はじめてのパターン認識

ここでは超境界面の数式  f(\mathbf{x}) = \mathbf{w} \mathbf{x} + w_0 を単位法線ベクトル  n と位置ベクトル P の関係に変形して、  f(\mathbf{x}) = \mathbf{n}^T (\mathbf{x} - \mathbf{P}) としている。

境界面へのベクトル P とそこからのびる、単位法線ベクトル  n を分離することにより、 n (x-P)内積の計算結果の正負を考えると、境界面のどちら側にいるかの識別が可能となる。 例題6.1の計算で  n = (\frac{2}{\sqrt{5}}, -\frac{1}{\sqrt{5}}), P = ( 1, 0) という値が計算された。

ここで、以下の3つの点について考えてみた。


a = (0, 3),
b = (2, 2),
c = (2, -1)

この三点と、ベクトル  n, P をプロットしてみる。

plt.axes().set_aspect('equal', 'datalim')

x = np.linspace(-1, 3)
y = 2*x - 2
plt.plot(x, y, "r-")

plt.plot(0, 3, "bo")
plt.text(0.2, 3, "a")

plt.plot(2, 2, "bo")
plt.text(2.2,2, "b")

plt.plot(2, -1, "bo")
plt.text(2.2,-1, "c")

plt.text(1.2,0, "P")
plt.text(2,-0.5, "n")

plt.quiver(0, 0, 1, 0, angles='xy',scale_units='xy',scale=1)
plt.quiver(1, 0, 2.0/np.sqrt(5), -1.0/np.sqrt(5), angles='xy',scale_units='xy',scale=1)

plt.grid()
plt.xlim(-2, 3)
plt.ylim(-2, 4)
plt.show()

f:id:bython-chogo:20180127235115p:plain

 \mathbf{n} (x - P)  x  a, b, c をそれぞれ代入すると以下のようになる。

 f(a) = \frac{2}{\sqrt{5}}  f(b) = 0  f(c) = \frac{-1}{\sqrt{5}}

この正負の結果は  (\mathbf{x}-\mathbf{P}) \mathbf{n} のつくる角度がそれぞれ、鋭角、直角、鈍角であるので、それぞれの結果は正、ゼロ、負となるわけである。

わかりやすくするために、 nベクトルを平行移動させて、図で表すと以下のようになる。

plt.axes().set_aspect('equal', 'datalim')

x = np.linspace(-1, 3)
y = 2*x - 2

plt.plot(0, 3, "bo")
plt.text(0.2, 3, "a")
plt.quiver(0, 3, 1, -3, angles='xy',scale_units='xy',scale=1)
plt.quiver(0, 3, 2.0/np.sqrt(5), -1.0/np.sqrt(5), angles='xy',scale_units='xy',scale=1)

plt.plot(2, 2, "bo")
plt.text(2.2,2, "b")
plt.quiver(2, 2, -1, -2, angles='xy',scale_units='xy',scale=1)
plt.quiver(2, 2, 2.0/np.sqrt(5), -1.0/np.sqrt(5), angles='xy',scale_units='xy',scale=1)

plt.plot(2, -1, "bo")
plt.text(2.2,-1, "c")
plt.quiver(2, -1, -1, 1, angles='xy',scale_units='xy',scale=1)
plt.quiver(2, -1, 2.0/np.sqrt(5), -1.0/np.sqrt(5), angles='xy',scale_units='xy',scale=1)

plt.text(1.2,0, "P")

plt.grid()
plt.xlim(-2, 3)
plt.ylim(-2, 4)
plt.show()

f:id:bython-chogo:20180127235323p:plain

お気づきかとは思いますが、正負が逆になってしまう。2クラスの識別なら正負が反転していても問題がないんだけど、気持ちが悪い。 本文の例題にもこっそり引き算を逆にして正負を反転させているような記述がみえるのだが、ごまかしているのか、私のベクトル計算の考え方がちがうのか判断がつかない。