2013-07-14 65 views
-1

我必須集:聚類平均鏈路

A = {(2, 3, 4), (3, 1, 3), (2, 5, 4)} 
B = {(4, 4, 4), (3, 7, 3)} 

我現在想知道的平均-Link的,但實際上我不 知道哪些設置與計算。

dist_al(A, B) = 1/(|A| * |B|) * SUM dist(x, y) 

在這個例子中|A| * |B|是什麼?它是3 * 2(集合A *集合B集合)還是9 * 6(每個數字)?

如果其第i個得到:

1/6 * (2 + 2+ 2+ 1+ 5+ 1+ 1+ 1+ 1+ 4+ 1+ 3+ 1+ 1+ 1+ 1+ 4+ 3+ 3+ 3+ 2+ 6+ 2+ 1+ 1+ 1+ 4+ 2+ 2+ 2+ 1+ 5+ 1+ 1+ 1+ 1+ 2+ 2+ 2+ 1+ 3+ 1)

=> 14,16

如果其第二i得到

1/54 * (2 + 2+ 2+ 1+ 5+ 1+ 1+ 1+ 1+ 4+ 1+ 3+ 1+ 1+ 1+ 1+ 4+ 3+ 3+ 3+ 2+ 6+ 2+ 1+ 1+ 1+ 4+ 2+ 2+ 2+ 1+ 5+ 1+ 1+ 1+ 1+ 2+ 2+ 2+ 1+ 3+ 1)

=> 1,5

回答

2

在共同的數學符號,|A|是集合A元件的數量。
I.e. |{ Apple, Banana, Obama }| = 3,假設這些是三個不同的對象。

由於有6個成對距離,除以6也是明顯的選擇。

請注意,存在兩種不同的「平均」關聯。每本書的名字略有不同。 UPGMA和WPGMA有一些明確的定義,請看這些!

哦,並且注意到在實施分層聚類時,通常使用而不是使用此公式計算它,而是使用基於先前結果的更新公式。因此

平均連鎖(使用歐幾里得距離)是:

sum(2.2360679775 4.24264068712 3.31662479036 
    6.0   2.2360679775 2.44948974278)/6 
= 3.4134818625433332 
+0

我知道| {Apple,Banana,Obama} | = 3 我不知道什麼| {(蘋果,香蕉,奧巴馬),(一,二,三)} |在我上面的例子中是 postet。如果它是6或2,它會產生很大的差別 – Mulgard

+0

使用數學定義,而不是自己編寫定義。 –

+0

我的問題仍然沒有回答。你是否也忽略了數學定義:「由於有6個成對距離,除以6也是明顯的選擇。「 所以你不能肯定嗎? – Mulgard

0

爲了找到在一個顯示的平均鏈接算法兩個羣集之間的距離,必須計算在集合A的每個數據點的歐幾里得距離針對集合B中的每個數據點。然後取所有距離的平均值。 ((euclidinDistance((2,3,4),(4,4,4))+ euclidinDistance((3,1,3),(4,4,4))+ euclidinDistance((())(+ (2,5,4),(4,4,4))+ ... +歐幾里德距離((2,5,4),3,7,3)))/(歐幾里得距離調用的數量))

看看下面的代碼:

public static double findClusterDistance(ClusterObject cluster1, 
     ClusterObject cluster2) { 
    double distance = 0.0; 
    int itt = 0; 
    for (DataObject data1 : cluster1.getClusterList()) { 
     for (DataObject data2 : cluster2.getClusterList()) { 
      itt++; 
      distance += getEuclidianDistance(data1.getDimensions(), 
        data2.getDimensions()); 
     } 
    } 
    return distance/itt; 
} 

public static double getEuclidianDistance(List<Double> list1, 
     List<Double> list2) { 
    double euclidianDistance = 0.0; 
    double partialDistance = 0.0; 
    for (int i = 0; i < list1.size(); i++) { 
     partialDistance += Math.pow(list2.get(i) - list1.get(i), 2); 
    } 
    euclidianDistance = Math.sqrt(partialDistance); 
    return euclidianDistance; 
}