Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does scipy logsumexp() deal with the underflow challenge?

Does the scipy's logsumexp() implementation include the hack that prevents underflow by subtracting the maximum found value in the array from each element?

The one explained here below, where m = maxval:

enter image description here

like image 976
user961627 Avatar asked Sep 03 '14 18:09

user961627


People also ask

What does logsumexp do?

Returns the log of summed exponentials of each row of the input tensor in the given dimension dim . The computation is numerically stabilized.

What is Logsumexp in Python?

Compute the log of the sum of exponentials of input elements. Input array. Axis or axes over which the sum is taken.


1 Answers

You can inspect the source code defining logsumexp here. (Note that there is a link to the source on the doc page).

You'll see:

a_max = a.max(axis=0)
...
out = log(sum(exp(a - a_max), axis=0))

So yes, scipy's logsumexp is subtracting the maximum from each element.

like image 194
unutbu Avatar answered Sep 19 '22 01:09

unutbu