如何标记在二维图中形成的簇,并将其与其他类似的二维图关联



假设我对一个数据进行了聚类,并在2D图中识别了几个聚类。假设已识别的簇位于位置(2,5(、(4,10(、(6,15(。现在,我已经用其他类似的数据多次重复了这个过程。我想为第一个图中形成的每个簇提供一个唯一的ID。类似于簇(2,5(、(4,10(、(6,15(的1,2,3。现在,在对另一组数据进行集群之后,如果集群再次在相同的位置形成,它应该保留旧的ID,并且应该为新位置的集群分配新的ID。

任何关于这一实施的建议或线索都将是有益的。

考虑使用字典来存储集群位置和集群编号。例如:

### Some populated dictionary last_clust -> {(2, 5): 1, (4, 10): 2, ...} 
curr_clust = {}
##Cluster generating code, generates clust_num and clust_location each loop
clust_num = some_num
clust_location = (x,y)
if last_clust[clust_location] == clust_num:
# clusters are same
curr_clust[clust_location] = clust_num
else:
curr_clust[clust_location] = #some number above total number of clusters
# allows you to move to next cycle of clustering
last_clust = curr_clust



最新更新