distributions.py 文件源码

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

项目:pyprob 作者: probprog 项目源码 文件源码
def __init__(self, values, log_weights=None):
        self.length = len(values)
        if log_weights is None:
            log_weights = np.full(len(values), -math.log(len(values))) # assume uniform
        else:
            log_weights = np.array(log_weights)
        weights = np.exp(log_weights - logsumexp(log_weights))
        self.distribution = collections.defaultdict(float)
        for i in range(self.length):
            self.distribution[values[i]] += weights[i]
        self.distribution = collections.OrderedDict(sorted(self.distribution.items()))
        self.values = np.array(list(self.distribution.keys()))
        self.weights = np.array(list(self.distribution.values()))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号