logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False)
NumPy has a logaddexp function which is very similar to logsumexp, but only handles two arguments. logaddexp.reduce is similar to this function, but may be less stable.
Input array.
Axis or axes over which the sum is taken. By default axis is None, and all elements are summed.
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the original array.
If this is set to True, the result will be a pair containing sign information; if False, results that are negative will be returned as NaN. Default is False (no sign information).
The result, np.log(np.sum(np.exp(a)))
calculated in a numerically more stable way. If b is given then np.log(np.sum(b*np.exp(a)))
is returned.
If return_sign is True, this will be an array of floating-point numbers matching res and +1, 0, or -1 depending on the sign of the result. If False, only one result is returned.
Compute the log of the sum of exponentials of input elements.
import numpy as np
from scipy.special import logsumexp
a = np.arange(10)
logsumexp(a)
np.log(np.sum(np.exp(a)))
a = np.arange(10)
b = np.arange(10, 0, -1)
logsumexp(a, b=b)
np.log(np.sum(b*np.exp(a)))
logsumexp([1,2],b=[1,-1],return_sign=True)
a = np.ma.array([np.log(2), 2, np.log(3)],
mask=[False, True, False])
b = (~a.mask).astype(int)
logsumexp(a.data, b=b), np.log(5)
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them