constrainted_hartigan.py 文件源码

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

项目:ecml17 作者: gmum 项目源码 文件源码
def init_link_labels(self, x0, x1, p):

        pdfs = [multivariate_normal(mean=m, cov=c, allow_singular=True) for m, c in zip(self.means, self.covs)]

        neglog_costs = np.zeros((2, self.means.shape[0]))

        for i in xrange(len(self.means)):
            neglog_costs[0, i] = -np.log(pdfs[i].pdf(x0))
            neglog_costs[1, i] = -np.log(pdfs[i].pdf(x1))

        neglog_link_costs = np.clip(neglog_costs, 0, 9999999999)

        def _cost(k, l):
            return (-np.log(self.weights[k]) * neglog_link_costs[0, k]) + (-np.log(self.weights[l]) * neglog_link_costs[1, l])

        must = must_consistent(self.partition)
        cannot = cannot_consistent(self.partition)

        if p == 1:  # must link
            return must[np.argmin([_cost(k, l) for k, l in must])]
        elif p == -1:  # cannot link
            return cannot[np.argmin([_cost(k, l) for k, l in cannot])]
        else:
            raise ValueError("At this point link is expected to be -1 or 1 only!")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号