def _propose_anchors(self, num_anchors):
if num_anchors != 2:
raise Exception('PointInformedSplitMergeSetupKernel only works for 2 anchors')
anchor_1 = np.random.randint(0, self.num_data_points)
if anchor_1 not in self.data_to_clusters:
self._set_data_to_clusters(anchor_1)
log_p_anchor = self.data_to_clusters[anchor_1].copy()
u = np.random.random()
alpha = np.random.beta(1, 9) * 100
if u <= 0.5:
x = np.percentile(log_p_anchor, alpha)
log_p_anchor[log_p_anchor > x] = float('-inf')
log_p_anchor[log_p_anchor <= x] = 0
else:
x = np.percentile(log_p_anchor, 100 - alpha)
log_p_anchor[log_p_anchor > x] = 0
log_p_anchor[log_p_anchor <= x] = float('-inf')
log_p_anchor[anchor_1] = float('-inf')
if np.isneginf(np.max(log_p_anchor)):
idx = np.arange(self.num_data_points)
idx = list(idx)
idx.remove(anchor_1)
anchor_2 = np.random.choice(idx)
else:
idx = np.where(~np.isneginf(log_p_anchor))[0].flatten()
anchor_2 = np.random.choice(idx)
return anchor_1, anchor_2
评论列表
文章目录