Just My Life & My Work

總算知道【馬氏距離】的意義,
加上實際操作MATLAB來驗證理論,
真正瞭然於心。
話說MATLAB真是一個強大的工具呢!

Mahalanobis distance

From WiKi (http://en.wikipedia.org/wiki/Mahalanobis_distance)

In statistics, Mahalanobis distance is a distance measure introduced by P. C. Mahalanobis in 1936. It is based on correlations between variables by which different patterns can be identified and analyzed. It is a useful way of determining similarity of an unknown sample set to a known one. It differs from Euclidean distance in that it takes into account the correlations of the data set and is scale-invariant. In other words, it is a multivariate effect size.

Definition

Formally, the Mahalanobis distance of a multivariate vector from a group of values with mean and covariance matrix S is defined as:

Test in MATLAB

#data

>> m %(covariance matrix)

m =

1.2000    0.4000

0.4000    1.8000

>> m1 %(mean vector1)

m1 =

0.1000

0.1000

>> m2 %(mean vector2)

m2 =

2.1000

1.9000

>> m3 %(mean vector3)

m3 =

1.5000

2.0000

>> av %(feature vector a)

av =

1.6000

1.5000

>> bv %(feature vector b)

bv =

1

1

>> cv %(feature vector c)

cv =

2

0

#result

>> a1=(av-m1)’*inv(m)*(av-m1)

%(compute the Mahalanobis distances from av to m1)

a1 =

2.3610

>> a2=(av-m2)’*inv(m)*(av-m2)

%(compute the Mahalanobis distances from av to m2)

a2 =

0.2410

>> a3=(av-m3)’*inv(m)*(av-m3)

%(compute the Mahalanobis distances from av to m3)

a3 =

0.1790

>> b1=(bv-m1)’*inv(m)*(bv-m1)

%(compute the Mahalanobis distances from bv to m1)

b1 =

0.8910

>> b2=(bv-m2)’*inv(m)*(bv-m2)

%(compute the Mahalanobis distances from bv to m2)

b2 =

1.1790

>> b3=(bv-m3)’*inv(m)*(bv-m3)

%(compute the Mahalanobis distances from bv to m3)

b3 =

0.6250

>> c1=(cv-m1)’*inv(m)*(cv-m1)

%(compute the Mahalanobis distances from cv to m1)

c1 =

3.3310

>> c2=(cv-m2)’*inv(m)*(cv-m2)

%(compute the Mahalanobis distances from cv to m2)

c2 =

2.0990

>> c3=(cv-m3)’*inv(m)*(cv-m3)

%(compute the Mahalanobis distances from cv to m3)

c3 =

3.0250

總結:有三個feature vector,分別為a、b、c,各去計算三個mean vector,紅色變數就是D(m)2,取結果為小者,亮紅色數字即答案(a3、b3、c2),表示a、b、c的類別分別為3、3、2。

Comments on: "[MatLab] 馬氏距離的理論與實做 (Mahalanobis Distance)" (2)

  1. 未知 的大頭貼

    […] 至於Mahalanobis Distance和Discriminant Function定義可參考上一篇。 […]

隨意留個言吧:)~

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲