| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…most of the template function for offset_multiplier to simplify
|
Does this affect stan-dev/stan#3330 or is it unrelated? |
Sorry, something went wrong.
|
This is just #3146 I'm writing a separate PR for stan-dev/stan#3330 |
Sorry, something went wrong.
Jenkins Console Log Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: G++: Clang: |
Sorry, something went wrong.
Jenkins Console Log Machine information No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: G++: Clang: |
Sorry, something went wrong.
|
@nhuurre or @andrjohns would either of you mind taking a look at this? @nhuurre Brian pointed out you handled #3033 which is very similar |
Sorry, something went wrong.
|
Can these scalar/matrix/etc overloads all be condensed? They all follow a similar pattern/logic (afaict). We have as_array_or_scalar() as well as the vectorised select(), so the functions can be scalar/container agnostic (examples of their usage in bernoulli_cdf) |
Sorry, something went wrong.
|
Does lmultiply need to also be considered? |
Sorry, something went wrong.
|
Huh, I didn't realize lmultiply even really existed in the math library. I'm pretty sure the stan compiler still just rewrites it to multiply_log. They definitely should be consistent between the two |
Sorry, something went wrong.
…inations of matrices and scalars
…inations of matrices and scalars
There was a problem hiding this comment.
Brian pointed out you handled #3033 which is very similar
You mean similar to the part that handles 0*log(0) corner case. Most of this PR is if-constexpr-template magic that goes way over my head.
Sorry, something went wrong.
| * NOTE: We do not test values of (0.0, 0.0) as inputs. | ||
| * This is because the testing framework uses | ||
| * finite difference as the comparison. The small finite | ||
| * purtubations lead to cases where the value of the | ||
| * function inputs is either slightly negative or slightly positive, | ||
| * which can lead to the function returning NaN when we would expect a | ||
| * value of 0. |
There was a problem hiding this comment.
Some testing is still technically possible. On #3033 I added a test that tricks the finite difference calculation by extending the function symmetrically.
Here that would be
return multiply_log((x1 >= 0) ? x1 : -x1, (x2 >= 0) ? x2 : -x2);(i.e. multiply_log(|x1|,|x2|) without using stan::math::abs since it would overwrite the autodiff derivatives)
However, I do not like this hack. The value added by such a test is low compared to the effort required to understand what it does and why it works.
It's better to extend the test framework. stan::test::test_ad needs both positive and negative perturbations because it compares autodiff to central finite differences. It shouldn't be hard to work out the equations for lateral finite differences which need perturbations only in one direction (but are less accurate). I can try and add something like stan::test::test_ad_positive if you want.
Positive-perturbation-only test can handle multiply_log(0, x). But the derivative of multiply_log(x, 0) is formally infinite so finite difference is going to blow up anyway. Maybe we need a stan::test::test_ad variant that just checks the autodiff derivatives are finite but does not compare them with any reference value.
Sorry, something went wrong.
This is, luckily, the part that I feel comfortable reviewing, so between the two of us it seems likely we will be able to make it work |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #3146 by making the deduction for branch logic be compile time using if constexpr. This also cleans up a lot of the code for offset_multiply_constrain. Instead of having all combinations of signatures for vector inputs we just use a little if constexpr to deduce which inputs need iterated over.
Tests
There is 1 new test in rev for testing issue #3146 specifically. You can run all tests associated with this PR via
Side Effects
Nope
Release notes
Fix issue so that rep_matrix can be used inside of offset_multiplier constraints.
Checklist
Copyright holder: Simons Foundation
The copyright holder is typically you or your assignee, such as a university or company. 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
the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested