[Numpy-discussion] New ufuncs

Charles R Harris charlesr.harris@gmail....
Wed Nov 5 01:13:29 CST 2008

```On Tue, Nov 4, 2008 at 11:41 PM, Anne Archibald
<aarchiba@physics.mcgill.ca>wrote:

> On 05/11/2008, Charles R Harris <charlesr.harris@gmail.com> wrote:
> >
> >
> > On Tue, Nov 4, 2008 at 11:05 PM, T J <tjhnson@gmail.com> wrote:
> > > On Tue, Nov 4, 2008 at 9:37 PM, Anne Archibald
> > >
> > > <aarchiba@physics.mcgill.ca> wrote:
> > >
> > > > 2008/11/5 Charles R Harris <charlesr.harris@gmail.com>:
> > > >> Hi All,
> > > >>
> > > >> I'm thinking of adding some new ufuncs. Some possibilities are
> > > >>
> > > >> expadd(a,b) = exp(a) + exp(b) -- For numbers stored as logs:
> > > >
> > > > Surely this should be log(exp(a)+exp(b))? That would be extremely
> > useful, yes.
> > > >
> > >
> > > +1
> > >
> > > But shouldn't it be called 'logadd', for adding values which are stored
> as
> > logs?
> > >
> >
> > Hmm... but I'm thinking one has to be clever here because the main reason
> I
> > heard for using logs was that normal floating point numbers had
> insufficient
> > range. So maybe something like
> >
> > logadd(a,b) = a + log(1 + exp(b - a))
> >
> > where a > b ?
>
> That's the usual way to do it, yes. I'd use log1p(exp(b-a)) for a
> little extra accuracy, though it probably doesn't matter.  And yes,
> using logadd.reduce() is not the most efficient way to get a logsum();

But probably the best bet here. So, should I add this function? T J's link
also mentioned a logsub, which might be more problematic because taking logs
of negatives isn't going to work... Although that shouldn't happen if the
probability logic is right and roundoff error is small.

>
> no reason it can't be a separate function. As T J says, a logdot()
> would come in handy too. A python implementation is a decent first
> pass, but logdot() in particular would benefit from a C
> implementation.
>

Are these likely to be big arrays? It shouldn't be too hard to make a logdot
once a logadd function is out there.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081105/be598859/attachment.html
```