def compute_distance_of_cluster_heads(self):
# list all possible combinations of two cluster heads
num_combination = self.nCr(self.ndim_y, 2)
# a_labels
# [0, 1, 0, 0]
# [0, 0, 1, 0]
# [0, 0, 1, 0]
# [0, 0, 0, 1]
# [0, 0, 0, 1]
# [0, 0, 0, 1]
a_labels = np.zeros((num_combination, self.ndim_y), dtype=np.float32)
for i in range(1, self.ndim_y):
for n in range(i):
j = int(0.5 * i * (i - 1) + n)
a_labels[j, i] = 1
# b_labels
# [1, 0, 0, 0]
# [1, 0, 0, 0]
# [0, 1, 0, 0]
# [1, 0, 0, 0]
# [0, 1, 0, 0]
# [0, 0, 1, 0]
b_labels = np.zeros((num_combination, self.ndim_y), dtype=np.float32)
for i in range(1, self.ndim_y):
for n in range(i):
j = int(0.5 * i * (i - 1) + n)
b_labels[j, n] = 1
xp = self.xp
if xp is not np:
a_labels = cuda.to_gpu(a_labels)
b_labels = cuda.to_gpu(b_labels)
a_vector = self.cluster_head(a_labels)
b_vector = self.cluster_head(b_labels)
distance = functions.sqrt(functions.sum((a_vector - b_vector) ** 2, axis=1))
# clip
distance = functions.clip(distance, 0.0, float(self.cluster_head_distance_threshold))
return distance
评论列表
文章目录