Processing math: 100%
スキップしてメイン コンテンツに移動

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 English ver 今日は、ヘッセ行列を用いたテイラー展開について書こうと思います。 これは最適化を勉強するにあたって、とても大事になってくるので自分でまとめて残しておくことにしました。とくに、機械学習では最適化を必ず行うため、このブログのタイトルにもマッチした内容だと思います。 . 概要 ヘッセ行列の定義 ベクトルを用いたテイラー展開 関数の最適性 ヘッセ行列の定義 仮定 f は次のような条件を満たす関数です。. f はn次元ベクトルから実数値を出力します。 このベクトルは次のように表せます。 x = [x_1,x_2,,,,x_n]
\forall x_i , i \in {1,2,,,n}, f は二回偏微分可能です。 定義 ヘッセ行列は \frac{\partial^2}{\partial x_i \partial x_j}を (i,j)要素に持ちます。 よってヘッセ行列は次のように表せます。 \[ H(f) = \left( \begin{array}{cccc} \frac{\partial^ 2}{\partial x_1^2} & \frac{\partial^2 f}{\partial x_1 \partial x_2} & &\ldots \frac{\partial^2 f}{\partial x_1 \partial x_n} \\ \frac{\partial^ 2 f}{\partial x_1 \partial x_2} & \frac{\partial^ 2 f}{\partial x_2^ 2} & \ldots & \frac{\partial^2 f}{\partial x_2 \partial x_n} \\ \vdots & \vdots & \ddots & \vdots \\ \frac{\partial^ 2 f}{\partial x_n \partial x_2} & \frac{\partial^ 2 f}{\partial x_n \partial x_2} & \ldo...

Implementation of Robbins monro

Robbins monro の実装 sorry, this page is Japanese only.   今回はRobbins monro の実装をしてみました。 Robbins monroは確率勾配降下法の学習率を入りテーション回数の逆数で割っていくものです。 使っているprogram言語はpython 3です。osはwindowsです。(macほしい...) アルゴリズム 確率勾配降下方とは目的関数の最適解を求めるアルゴリズムです。目的関数をf(X)とすると、手順は以下のようになっています。 初期学習率n_0を決めます。訓練データDを用意します。この訓練データは複数の初期値の集まりです。 訓練データから一つ初期値をランダムに取り出し、これをx_0とし、最初の予測値とします。 次の式に現在の予測値x_0を代入し、新たな予測値x_{n+1}を得ます。x_{n+1} = x_{n} - \frac{n_0}{n} grad f(X_n)
収束して入れば4へ、収束していなければ2で得られた値x{n+1}を新たにx_nとしてもう一度2を行う。 訓練データを一周していなければ2へ、一周していれば各初期値から得られた解の中から目的関数を最も小さくするものを選ぶ。   実装例 以下の目的関数を最小化させてみましょう。 f(x,y) = (x-2)^2 + (y-3)^2
コマンドラインでpythonを実行していきます。 予想通り、(2,3)という解を導き出してくれました。目的関数が簡単だったので、初期値をどの値でとってもばっちり正解にたどり着いてくれました。 CODE 以下にRobbins monroの関数だけ置いておきます。 こちら にすべてのコードを載せています。 def Robbins_monro(function,grad,number_variable_gradient): init_learning_rate = 1.5 stepsize = 1000 init_value = np.array([range(-1000,1020,20) for i in range(number_v...

大学院試験 -外部への道しるべ-

始めに この度、 京都大学大学院情報学研究科システム科学専攻 に合格することができました!!! 僕は現在、立命館大学という関西の私立大学に通っているので、外部受験をしたことになります。 さらに、学部は数学専攻で、大学院からは情報学(の中でも機械学習)専攻になるので、専門も変えることになります。 この記事では、外部の大学院、もしくは専攻替えを考えている人向けに書こうと思っているので、目次で気になった項目があれば、ぜひ、読んでいってくださいませ。( *´艸`) ちなみに、予測点数は線形微積6~7割、専門科目満点、英語かなり低いので内緒です。(笑) 得点開示を要求するので、得点がわかったら、また追記します。 目次 外部受験を目指すまで、目指したきっかけ 外部受検の大変さ 専攻替えの大変さ 合格するために 英語が苦手な人へ 数学科の学部から情報学(機械学習)の大学院を目指す人へ 応援 外部受検を目指すまで、目指したきっかけ ここでは、自分の大学生活がどんなだったかを書いてるだけなので、興味のない人は飛ばしましょう。(笑) 僕が学部二回生頃に、当時数理科には機械学習の研究をされている先生が一人だけ所属されていました。その先生に、直接弟子入りさせていただき、僕の機械学習への道は始まりました。。。(メインは遺伝統計学の研究でした。) 弟子入りした直後は、タイピングもなめくじのように遅かったですし、gitもpullする前にpushしたこともありました。。。 しかし、その先生は、目的に最先端で届く道のりを用意してくださいました。 プログラミングを初めて一か月ほどで、t-SNEの実装をしたり(遺伝統計学の研究で必要だった)、四か月ほどで、カーネルc-SVMの実装をしたり(やってみなとゆわれて(笑))することができました。その後も、学部二回生、三回生ながら、論文を読んで実装してきました。 学部二回生冬には、遺伝統計学の研究を 株式会社パーソルキャリア さん主催のハッチングフェスというデータサイエンティストのためのイベントで、発表しました。 このイベントでは、企業の方もたくさん来られて、知り合えるチャンスがかなりあります!! (名刺を作っておくと、「えっ、学生なのに名刺持ってるの?!」ってなるので、覚えてもらえます。...