logsum module¶
Safe addition in log-space, taken from scikit-learn.
Authors: G. Varoquaux, A. Gramfort, A. Passos, O. Grisel
License: BSD
-
wayward.logsum.
logsum
(x: numpy.ndarray) → numpy.ndarray[source]¶ Computes the sum of x assuming x is in the log domain.
Returns
log(sum(exp(x)))
while minimizing the possibility of over/underflow.Examples
>>> import numpy as np >>> a = np.arange(10) >>> np.log(np.sum(np.exp(a))) 9.4586297444267107 >>> logsum(a) 9.4586297444267107