-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved behavior of expect_near_rel #1657
Improved behavior of expect_near_rel #1657
Conversation
…gs/RELEASE_500/final)
…gs/RELEASE_500/final)
…gs/RELEASE_500/final)
…gs/RELEASE_500/final)
@bob-carpenter could you review this? Or should I ask someone else? |
I can review it. Thanks for documenting so clearly what's going on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than naming of member values in the new class, this all looks great.
I don't want to lose the discussion of the issue. Could you put the developer-facing doc on how to use the new tolerances on the wiki here: https://github.com/stan-dev/stan/wiki/Testing-framework
I found the graphs particularly helpful.
…ect_near_rel_improvements
…stable/2017-11-14)
So I checked the coding guidelines and I realized |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
@bob-carpenter tests are passing, should be ready for re-review |
Summary
Improved the behavior of
expect_near_rel
as proposed in #1656.Wherever a tolerance of type
double
was used, there is a new structrelative_tolerance
that gathers relative (tol
) and minimal tolerance (tol_min
). The final tolerance is computed asstd::max(tol * fabs(x), tol_min)
wherex
is either an exact value to be tested against (I will use this in the precomputed tests) or average of the two values to be compared (this is whatexpect_near_rel
uses).To make the transition easy
relative_tolerance
has an implicit constructor from double (which is treated as relative tolerance), I instructed the linter to be quiet about it.Default
tol_rel
is1e-8
and defaulttol_min
isstd::max(tol_ * tol_, 1e-14)
. Thetol_min
default is slightly weird but it is a compromise between a desire to be strict by default while acknowledging that1e-16
tolerance is almost impossible to achieve in many cases.Tests
There is a test for
relative_tolerance
- since the tolerance code is decoupled fromexpect_near_rel
it can be tested more directly than in the previous version.I had to tweak the tolerances for a bunch of tests.
Side Effects
Most tests got stricter or stayed the same for all/most values, but some test/value combinations got a bit more relaxed. Specifically:
tol > 1e-7
and the tolerance was not explicitly touched in this PR is stricter forfabs(value) < tol
and the same forfabs(value) > tol
.1e-14 < tol < 1e-7
and the tolerance was not explicitly touched in this PR is stricter forfabs(value) < tol
, slightly relaxed fortol < fabs(value) < 1e-14/tol
and the same forfabs(value) > 1e-14/tol
.tol_min
above it's default, I would decreasetol
or vice versa. Mostly tests that modified their tolerance actually needed to modifytol_min
and nottol
.hessian_hessian_
andhessian_fvar_hessian_
used to be1e-3
. I noticed that this was necessary primarily because of bad behaviour around zero. The new default istol = 1e-4, tol_min = 1e-3
, so those tests got stricter above1e-1
and weaker between1e-3
and1e-1
.Most places where I had to tweak the tolerance already had tolerance tweaked before. The exceptions are
test/unit/math/mix/fun/matrix_exp_test.cpp
test/unit/math/mix/fun/quad_form_diag_test.cpp
where I had to slightly increase tolerances for at least one
test_ad
call that used default tolerance before. This was due to the change in default tolerance described above.I also removed functions
relative_diff
andexpect_near_relative
fromtest/unit/math/rev/fun/util.hpp
and replaced their use (only in 1 file) byexpect_near_rel
.Checklist
Math issue Make the relative tolerance in expect_near_rel continuous #1656
Copyright holder: Institute of Microbiology of the Czech Academy of Sciences
By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested