split_merge_setup.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:pgsm 作者: aroth85 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号