What exception do you throw when a derivative fails a sign restriction?

29 views
Skip to first unread message

Ben Goodrich

unread,
Jun 6, 2016, 8:16:17 PM6/6/16
to stan development mailing list
If you are calculating a derivative with respect to a var using doubles, but the calculation is not numerically accurate and could result in a negative sign when the derivative is theoretically positive what (if any) exception should you throw?

Michael Betancourt

unread,
Jun 7, 2016, 3:03:26 AM6/7/16
to stan...@googlegroups.com
We haven’t established any convention.  I’ve tried to make all of my
implementations accurate as close to machine precision as possible
with exceptions thrown in case any loops exceed some very large,
preset value.  Technically trying to treat numerical issues with
exceptions (and hence a Metropolis rejection) can bias the Markov
chain, but I haven’t seen any of these exceptions thrown in 
production code (or at least not after improving implementations).

On Jun 7, 2016, at 1:16 AM, Ben Goodrich <goodri...@gmail.com> wrote:

If you are calculating a derivative with respect to a var using doubles, but the calculation is not numerically accurate and could result in a negative sign when the derivative is theoretically positive what (if any) exception should you throw?

--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bob Carpenter

unread,
Jun 7, 2016, 11:05:49 AM6/7/16
to stan...@googlegroups.com
I still occasionally get numerical exceptions with
parameters underflowing or overflowing after warmup.
Derivatives aren't really any different here, are they?

Is there something you'd suggest rather than rejecting?
I'm not even sure at this point if this just counts as
a U-turn or whether it rejects the whole tree being built.

We need to refactor our exception types to make them follow
something like this:

http://www.boost.org/doc/libs/1_61_0/libs/math/doc/html/math_toolkit/error_handling.html

For now, you can just throw a std::domain_error, which we throw
all over the place when we should probably be throwing a std::range_error
for these situations:

http://stackoverflow.com/questions/22978863/differences-between-out-of-range-range-error-and-over-underflow-error

It only matters for users of the Math library --- the exceptions
all work the same way in Stan as long as they inherit from std::exception.

- Bob
Reply all
Reply to author
Forward
0 new messages