Skip to content

Instantly share code, notes, and snippets.

@iphysresearch
Created April 10, 2018 13:42
Show Gist options
  • Save iphysresearch/e734dc3e3d6e3c649b853aee94181060 to your computer and use it in GitHub Desktop.
Save iphysresearch/e734dc3e3d6e3c649b853aee94181060 to your computer and use it in GitHub Desktop.
S_Dbw_part2.py
def density(self,density_list=[]):
"""
compute the density of one or two cluster(depend on density_list)
变量 density_list 将作为此函数的内部列表,其取值范围是0,1,2,... ,元素个数是聚类类别数目
"""
density = 0
if len(density_list) == 2: # 当考虑两个聚类类别时候,给出中心点位置
center_v = (self.cluster_centroids_[density_list[0]] +self.cluster_centroids_[density_list[1]])/2
else: # 当只考虑某一个聚类类别的时候,给出中心点位置
center_v = self.cluster_centroids_[density_list[0]]
for i in density_list:
temp = self.data[self.data_cluster == i]
for j in temp: # np.linalg.norm 是求范数(order=2)
if np.linalg.norm(j - center_v) <= self.stdev:
density += 1
return density
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment