2016-05-12 30 views
-1

我有一個其中描述對象之間的距離的2維數組:例如距離(A,B)= 1,距離(B,C)clastering具有未知距離度量一個維數據

A B C 
A 0 1 2 
B 1 0 3 
C 2 3 0 

= 3,distance(A,C)= 2, distance(x,y)= distance(x,y)。我對這個距離沒有更多的瞭解,它不是歐幾里得距離或任何公知的距離函數。

如何查找組數和分區點數(x,y)?

+1

可能與http://stats.stackexchange.com/questions/2717/clustering-with-a-distance-matrix – gdlmx

+0

複製在我的問題importent是距離不是Euklides,更不用說我對距離有什麼想法。 K均值算法和我發現谷歌需要Euklides點之間的距離。 –

回答

1

我已經找到解決方案:

D =[x][y] #two dimencion array with distances between x and y 
sorted_distance = sorted_distance(D) # all values apears in D, delete duplicates and sort from max to min value 

for distance in sorted_distance: 
    V = D.keys() 
    E = [] 
    for x in V: 
     for y in V: 
      if x==y: continue 
      if D[x][y]<=distance: 
       E.append((x,y)) 
    G = Grapth(V,E) 
    connected_components = get_connected_components(G) 
    if len(connected_components)>1: # this value could be increase if result is not rewarding 
     return connected_components 
相關問題