math icon indicating copy to clipboard operation
math copied to clipboard

multiply_log(0, 0) has infinite gradient

Open jsocolar opened this issue 4 years ago • 12 comments

Description

For more details, see https://discourse.mc-stan.org/t/non-linear-modelling-michaelis-menten/22736/8

Example

The gradient for poisson_lpmf(0 | lambda) is infinite at lambda = 0.

Suggested fix

@nhuurre writes on discourse:

We should just special-case a=0.0 like we do with a=1.0

Current Version:

v4.0.1

jsocolar avatar May 28 '21 15:05 jsocolar

Ah interesting, it looks like for reverse mode we don't check this, but we do when working with doubles so we def should be doing it for reverse mode!

https://github.com/stan-dev/math/blob/develop/stan/math/rev/fun/multiply_log.hpp

SteveBronder avatar May 28 '21 21:05 SteveBronder

Any chance this could be addressed? I think accounting for this is making formulating complex HMMs on the log scale a bit more verbose than it needs to be.

mhollanders avatar May 04 '24 11:05 mhollanders