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))
评论列表
文章目录