math.py 文件源码

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

项目:factorix 作者: gbouchar 项目源码 文件源码
def c(vec):
    """Complement function for probabilities in the log-space: robustly computes 1-P(A) in the log-space
    Args:
        vec: vector of negative numbers representing log-probabilities of an event.

    Returns: the log-probabilities of (1-P(A)) were log(P(A)) are given in the vec numpy array

    Examples:
        >>> c(-1e-200)
        -460.51701859880916

        # >>> np.log(1 - np.exp(-1e-200)) raises a `RuntimeWarning: divide by zero` error
    """
    # return np.log1p(-np.exp(vec))  # Not robust to -1e-200
    if np.max(np.array(vec)) > 0:
        print('vec', vec)
    return np.log(-np.expm1(vec))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号