-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Adds var<mat> specializations for lower/upper bounds #2285
Conversation
…4.1 (tags/RELEASE_600/final)
Nice. This will make a placeholder
I think that makes sense. Some variables constrained and some not. Will have to check the code to make sure I'm reading that right tho. |
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.
Had a closer look. You're right that the ifs are handling infinities incorrectly.
I think we'll just have to write autodiff for each of these things manually.
Since these constraints are only eigen types and this is only a few functions, this shouldn't be too hard to do. I can do it tomorrow if you've got other stuff to keep you busy. If we do this we can also ditch the new infinity checks unless you want to keep them.
…4.1 (tags/RELEASE_600/final)
…nite inputs (Issue #2101)
…/math into feature/varmat-bound-constrains
…4.1 (tags/RELEASE_600/final)
…/math into feature/varmat-bound-constrains
…4.1 (tags/RELEASE_600/final)
@SteveBronder I removed the infinite checks and cleaned this up. I thought a little more about #2291 -- this already wasn't working right for vector constraints so I'm not gonna worry about supporting this in the future. The only case this worked was if someone had a scalar constraint that was a infinite, and so I added failing error checks for that. It is hopefully not more expensive than the infinite checks that were already there. Should be ready to review if tests pass. |
Just added some stuff that went a little loco with the moves. But if we need to move things sometimes and we need to use |
The other issue is we can't do stuff like return make_holder([&x](const auto& lb_ref) { return add(exp(x), lb_ref); },
lb_ref); Since return make_holder([](auto& lb_ref, const auto& xx) { return add(exp(xx), lb_ref); },
lb_ref, x); |
…4.1 (tags/RELEASE_600/final)
I don't think we need to forward through
My assumption is that input arguments don't need held, but the expression semantics aren't clear to me (when we need holder and when we don't). |
As an example of not holding inputs: https://github.com/stan-dev/math/blob/develop/stan/math/prim/fun/transpose.hpp Edit: So I think we're making the assumption that inputs don't need held, since certainly if they did then we'd need a holder there. |
…4.1 (tags/RELEASE_600/final)
…4.1 (tags/RELEASE_600/final)
…4.1 (tags/RELEASE_600/final)
I think this and stan-dev/stan#2995 are ready to go. @SteveBronder you good with this? If so @rok-cesnovar can do the mergin'. |
Yep! |
Oh, this two PRs need to go in in-sync? |
Restarted with proper branches, please approve both and I can handle merging this once it passes. |
Yep! Thanks will do! |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Nice! @bbbales2 if you hit the approve button I think we are good to go! @rok-cesnovar I think this was the last piece we needed for the stance impl! First thing we need to do is use the matrix specializations for the constraints then we can add varmat! |
Summary
This adds specializations for lower / upper / lower_upper constraints to work with var. I had to do a few other things for this to work.
To test this I had to write a specialization for
[lb/up/lub]_constrain
that worked forMatrix<var>
andvar_value<Eigen::Matrix>
. That means that a few things likecheck_less
etc have to now take / iterate over general matrices.I had to fix
elt_multiply()
to allow for multiplying a scalar and matrixI'm not sure how to handle the negative and positive infinity checks for the matrix versions. Previously this was checked on a per coefficient basis. But now if you have a vector representing the bounds for a vector, if any of them are +/- infinity then it returns back the input vector without the transformation. I feel like I'm not understanding how this is used. If a vector represents the bound then will it ever be expected that some of those values in the vector would be infinite and some would not be? If that's the case then I need to write specific var specializations which isn't that bad but it would be nice to not have to.
Tests
Tests added for matrix versions. It looks like
lub_constrain()
has not tests? So I added ones for testing those as well.Side Effects
Yes see (3) above
Release notes
Adds bound constraint functions for
var<matrix>
functionsChecklist
Math issue How to add static matrix? #1805
Copyright holder: Steve Bronder
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
./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