[Numpy-discussion] vectorized version of logsumexp? (from scipy.maxentropy)

Charles R Harris charlesr.harris at gmail.com
Sat Oct 17 15:02:09 EDT 2009


On Sat, Oct 17, 2009 at 12:59 PM, Charles R Harris <
charlesr.harris at gmail.com> wrote:

>
>
> On Sat, Oct 17, 2009 at 12:40 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
>
>> Somewhat offtopic, but is there a generalization of the logsumexp shortcut
>> to more than 2 variables?
>>
>> IIRC, it's this for 2 variables:
>> log (exp (a) + exp (b)) = max (a,b) + log (1 + exp (-abs (a-b)))
>>
>>
> logaddexp.reduce will apply it along array rows. The reduce loop could
> probably be optimized a bit using the methods that Dale used to optimize the
> reduce case for add. Hmm,  the reduce loop would need to be implemented for
> the generic loops. The logaddexp case could possibly be optimized further by
> writing a specialized loop for the reduce case.
>
>
Example:

In [1]: x = arange(9).reshape(3,3)

In [2]: logaddexp.reduce(x, axis=1)
Out[2]: array([ 2.40760596,  5.40760596,  8.40760596])

In [3]: logaddexp.reduce(x, axis=0)
Out[3]: array([ 6.05094576,  7.05094576,  8.05094576])

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20091017/598ec4ac/attachment.html>


More information about the NumPy-Discussion mailing list