def dist(a, b): """ 输入:向量A, 向量B 输出:两个向量的欧式距离 """ a_new = copy.deepcopy(a) b_new = copy.deepcopy(b) return LCS.get_lcs_distance(a_new, b_new)
def dist(a, b): """ 输入:向量A, 向量B 输出:两个向量的欧式距离 """ a_new = copy.deepcopy(a) b_new = copy.deepcopy(b) if operator.eq(a_new,b_new) == True: return 0 return LCS.get_lcs_distance(a_new,b_new)
def CalculateSilhouetteCoefficient(result): """ 计算聚类结果的轮廓系数 :param result: 聚类结果 :return: 轮廓系数 """ S = 0 num_global = 0 if len(result) == 1: return -1 for i in range(len(result)): if len(result[i]) == 1: S = S + 0 num_global = num_global + 1 else: for j in range(len(result[i])): a = 0 b_list = [] num_global = num_global + 1 for k in range(len(result[i])): if j == k: continue a = a + LCS.get_lcs_distance(result[i][j],result[i][k]) a = a/(len(result[i])-1) for i_tmp in range(len(result)): if i == i_tmp: continue for j_tmp in range(len(result[i_tmp])): b_list.append(LCS.get_lcs_distance(result[i][j],result[i_tmp][j_tmp])) if len(b_list) == 0: return 0 b = min(b_list) if max(a,b) == 0: break S = S + (b - a)/max(a,b) S = S/num_global return S