On 05/11/2008, Charles R Harris
On Tue, Nov 4, 2008 at 11:05 PM, T J
wrote: On Tue, Nov 4, 2008 at 9:37 PM, Anne Archibald
wrote: 2008/11/5 Charles R Harris
: 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(); 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. Anne