スキップしてメイン コンテンツに移動

Theorem of kernel K-means

Introduction

Today, I will write about a theorem of kernel K-means. The kernel K-means cover the weak point of K-means. I will explain this weak point of K-means and strong point of kernel K-means. If you have not looked yet, please look at the Theorem of K-means.
I implement kernel K-means. Its post is Implement kernel K-means.

Overview

  •  A weak point of K-means
  • Kernel trick 
  • kernel K means
  • Algorithm


A weak point of K-means

For example, I prepare the following dataset.

It is impossible for this dataset to cluster by K-means because this data is distributed shape of the circle. K-means classify data in accordance with the Euclid distance between data and prototype. The prototype is representative of each class. A Prototype of K-means is mean vector. Thus, K-means classify dataset as follows.

K-means does not work, if not so this like dataset.
The dataset which is able to classify by K-means is consist of mass for each class. For example,


Kernel K-means cover this weak point of K-means.

Kernel Trick
Firstly, I explain Kernel Trick.
If dataset $X$ is not able to classify linear hyperplane. Then, the map $\phi$ send to space which is able to classify linear hyperplane.


Kernel is defined as follows.
$$K(x,y) = \phi(x)^T \phi(y)$$

It is difficult to compute $\phi$, but It is easy to compute $K(x,y)$.
This method is called kernel trick.

kernel K means

I review the objective function of K-means.

$$J = \sum_{n=1}^{N} \sum_{k=1}^{K} r_{nk} ||x_n-\mu_k||^2$$

here, prototype is $\mu_i ~\forall k \in K$.
$r_n$ is the 1 of K coding scheme and $r_{nk}$ is k'th element of $r_n$
then
$$\mu_k = \frac{\sum_{n} r_{n_k} x_n}{\sum_n r_{n_k}}$$
and
$$k = \arg \min_{j} || x_n - \mu_{j} || \implies r_{nk} = 1$$

$$else \implies r_{n_k} = 0$$


I rewrite this objective function as follows.

$$J = \sum_{n=1}^{N} \sum_{k=1}^{K} r_{nk} ||\phi(x_n)-\mu_k||^2$$

then
$$\mu_k = \frac{\sum_{n} r_{n_k} \phi(x_n)}{\sum_n r_{n_k}}$$


Thus, distance between $x_n$ and prototype $\mu_k$ is
$$||\phi(x_n) - \frac{\sum_{m}^{N} r_{m_k} \phi(x_m)} {\sum_{m}^{N} r_{m_k}} ||^2$$
$$= \phi(x_n)^T \phi(x_n) - \frac{2 \sum_{m}^{N} r_{n_k} \phi(x_n)^T \phi(x_m)}{\sum_{m}^{N} r_{n_k}} + \frac{\sum_{m,l}^{N} r_{n_k} r_{n_k} \phi(x_m)^T \phi(x_l)}{ \{ \sum_{m}^{N} r_{n_k} \}^2 }$$

kernel K-means compute $\phi(x_n)^T \phi(x_m)$ as $K(x_n,x_m)$

Algorithm

  1. make initial value of prototype. input K: number of clusters.
  2. for iteration in iteration times.
  3. for $n \in N$ do 
  4. for $k \in K$ do
  5. Compute distance $x_n$ and prototype of class k.
  6. end for k
  7. Pick up class $k_n \in {1,2,..,K}$ which make distance  $x_n$ and prototype of class k minimizing.
  8. divide $x_n$ in class $k_n$
  9. end for n
  10. if there is no change, finish repeating iteration.


Reference
http://www.cs.utexas.edu/users/inderjit/public_papers/kdd_spectral_kernelkmeans.pdf

コメント

このブログの人気の投稿

グラフ理論

Introduction sorry, this page is Japanese only. いよいよ私も三回生になり、グラフ理論の授業が始まりました。ということで、グラフ理論の基本的な定義を書いていこうと思います。 最後に説明する隣接行列については実装を行いましたので、以下の記事もよろしければご覧ください。 隣接行列の実装 グラフのイメージ グラフ理論のグラフとは高校数学で習う二次関数などとは違います。 例えば駅などを創造してください。各駅間に線路が通っていますね。このような、駅、線路の集まりのことをグラフといいます。次の絵で確認してもらえるとイメージしやすいかと思います。 このようなものをグラフといいます。グラフは二点間がどうつながっているかだけを保存し、実際の距離や位置関係は保存しません。 このような向きのない(各駅を行き来でき、一方通行ではない)グラフを無向グラフをいいます。反対に向きのある(一方通行しかできない)グラフを有向グラフといいます。 グラフの定義 グラフではある空でない集合E,Vを考えます。Eの要素をedge(辺)、Vの要素をvertex(頂点)といいます。 ここで以下のような写像を考えます。 $$g:E \rightarrow V \times V$$ この時(E,V,g)で定義される空でない空間のことをグラフといいます。 写像で捉えるグラフ 写像gというのは、Eの要素、つまり辺を対応する(始点、終点)というV×Vの集合の要素に送ります。gは写像ですので、写像の定義より、Eのどの要素の始点と終点が対応していることになります。つまり、辺がどこにもつながっていないということはあり得ません。反対にすべてのV×Vの要素がEの要素のどれかに対応しているのであればgは全射になります。 隣接行列 隣接行列とはどのvertexと、どのvertexがつながっているかを行列で表します。例を見るのが理解するのには早いと思うので、例を挙げて説明します。 上のグラフのイメージで出てきたグラフの例を考えましょう。隣接行列は以下のようになります。 $$ \[  adj = \left( \begin{array}{cccccc} 0 &

Entropy

Introduction sorry, this page is Japanese only.   今日はエントロピーについて書こうと思います。これは確率論や統計学で死ぬほど大事なKLダイバージェンスといものを理解するために必要な知識です。 この記事ではエントロピーについてしか書きませんが、今度KLダイバージェンスについても書こうと思います。 KLダイバージェンスの記事はこちら Entropy 直観的な話 ある事象、「例えば明日大学の講義にX分遅刻する」という事象を考えます。 この事象に対する確率がP(X)が与えられているとしましょう。P(1)は一分遅刻する確率です。この時確率分布P(X)が持つ情報量はどれだけのものかとうことを考えたいとします。 明日の講義はテストを受けるとします。そのテストを受けないと単位を落としてしまします。しかし、テスト前日はすごく寝不足としましょう。遅刻する確率が99パーセントとわかった時、ほとんどどうあがいても遅刻するのであれば単位を落とすのはほぼ確実といえます。 よって前日に徹夜で勉強するよりも、睡眠不足を解消するために寝る方がよっぽど効率的であることがわかります。しかし、遅刻をする確率が50パーセントとわかった時、前日にテスト勉強をすればよいのか、せずに睡眠をとればよいのかわかりません。このように、確率が偏っているほど何が起こるか予測しやすく、対策を立てやすいのです。遅刻する確率が99パーセントとわかる時は遅刻する確率が50パーセントとわかった時に比べて圧倒的に多いはずです。 確率P(X)に対してこの情報量のことをP(X)の 自己エントロピー といいます。 そして、自己エントロピーの期待値のことを 平均エントロピー といいます。 立式 性質 ではこの情報量を数式で表していきましょう。まず自己エントロピーには大事な性質が二つあります。それが 互いに独立な確率変数の自己エントロピーはそれぞれの情報量の和で表される。 自己エントロピーは減少関数である。 の二つです。 自己エントロピーの加法性 互いに独立な確率変数の情報慮はそれぞれの情報量の和でなければいけません。例えば「明日の講義がY分早く終わる」という事象を考えます。この確率変数Yはあなたが何分講義に遅刻しようが

二次元空間の直線

Introduction English ver 今日は、次の定理を証明します。 二次元空間の直線は次のように表せる \[\{x|<x,v> = 0\}\] ただし、vは直線に直行し、ゼロでないベクトルとします。 証明 \[\forall k \in \{x|<x,v> = 0\},\] \[<k,v> = 0\] k と vは二次元空間のベクトルなので、それぞれのベクトルは次のように表せます。 \[k = (k_1,k_2)\] \[v = (v_1,v_2)\] よって \(<k,v>=k_1v_1 + k_2v_2=0\) 方程式を\(k_2\)について解くと \[k_2 = -\frac{v_1}{v_2} k_1\] これはまさしく、傾き\(-\frac{v_1}{v_2}\)の直線です。 Q.E.D