stan-dev / nomad

Fast autodiff.
Other
19 stars 2 forks source link

Domain Errors #14

Open betanalpha opened 10 years ago

betanalpha commented 10 years ago

What should we do with domain errors? The easiest solution would be to use std::nan() for the values and gradients, but then errors could not be traced back to their source. Alternatively, we can throw domain exceptions and be careful about wrapping the autodiff methods in try/catch blocks.

Functions with constrained domain:

To Do:

bob-carpenter commented 10 years ago

If there's going to be only one hard-coded behavior (which I'm fine with), I'm in favor of throwing exceptions with informative messages.

Alternatively, if you supply exception handling traits as in Boost, then you can configure what you do on an error programatically. Boost built-in behaviors include (1) throw an exception, (2) return NaN silently, (3) return NaN silently and log an error message somewhere static, and (4) call a custom handler.

The other issue is what to do with infinite values in outputs. That is, what's log(0)? And what about infinite values in inputs, as in exp(-infinity). We have not been good in Stan so far about keeping this all consistent.

One issue is whether you want the double versions to behave the same way, in which case we need to use our versions rather than versions from the std:: lib which don't throw exceptions. There's also all the arithmetic operators like / that have ill-defined edge cases, like 1/0 and 0/0, as well as overflow with + or * and underflow with *.

I think you want atanh.hpp, not atahn.hpp.

On Aug 9, 2014, at 6:04 PM, Michael Betancourt notifications@github.com wrote:

What should we do with domain errors? The easiest solution would be to use std::nan() for the values and gradients, but then errors could not be traced back to their source. Alternatively, we can throw domain exceptions and be careful about wrapping the autodiff methods in try/catch blocks.

Functions with constrained domain:

• src/scalar/functions/smooth_functions/acos.hpp • src/scalar/functions/smooth_functions/acosh.hpp • src/scalar/functions/smooth_functions/asin.hpp • src/scalar/functions/smooth_functions/atahn.hpp • src/scalar/functions/smooth_functions/inv_sqrt.hpp • src/scalar/functions/smooth_functions/log_diff_exp.hpp • src/scalar/functions/smooth_functions/log.hpp • src/scalar/functions/smooth_functions/log1p.hpp • src/scalar/functions/smooth_functions/log2.hpp • src/scalar/functions/smooth_functions/log10.hpp • src/scalar/functions/smooth_functions/multiply_log.hpp • src/scalar/functions/smooth_functions/pow.hpp • src/scalar/functions/smooth_functions/sqrt.hpp To Do:

• Select and implement error strategy. • Domain tests following finite difference functor pattern. — Reply to this email directly or view it on GitHub.