math icon indicating copy to clipboard operation
math copied to clipboard

Add a signed log_sum_exp

Open andrjohns opened this issue 4 years ago • 3 comments

Description

When using log_sum_exp, it would be useful to be able specify a 'sign' for the variables being aggregated - such that some inputs are added and some subtracted.

I'm currently needing this for the gradients of hyper_pFq function, which are all computed on the log scale and the signs tracked through the infinite sum.

Example

The function would be:

log_sum_exp_signed(input_container, signs_container)

Which would be equivalent to:

log(sum(exp(input_container) .* signs_container))

But with the log_sum_exp approach to avoiding overflow

Current Version:

v4.1.0

andrjohns avatar Oct 01 '21 03:10 andrjohns

I'm finding this will be better as an internal function for just grad_pFq, since it needs to track the sign of the returned sum as well. Will close for now

andrjohns avatar Oct 01 '21 05:10 andrjohns

Belay that last request---this answered all my questions! Thanks for commenting the basis for the decision.

bob-carpenter avatar Oct 04 '21 16:10 bob-carpenter

Re-opening this since I'm finding it's needed for other functions which aggregate on the log-scale but still track the sign

andrjohns avatar Oct 20 '22 06:10 andrjohns