| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
@SteveBronder Apologies for the delay! Reviving the conversation, I'm mainly concerned about the templates. This has led me to temporarily create tests in two places: mix and rev. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
This PR implements reverse-mode automatic differentiation for the max() and min() function inside stan::math. It introduces the binary scalar overload max(x, y) and min(x, y) as well as container/matrix overloads.
Gradient Propagation ($dx$ and $dy$)
During the backward pass, the upstream adjoint (vi.adj()) is distributed based on the comparative values of the inputs:
For max(x, y):
For min(x, y):
NaN Check & Propagation
The binary max(x, y) and min(x, y) functions handle NaN identically:
Tests
1. Matrix and Vector Variates (mix)
To guarantee that the functions handle Stan’s specialized memory layouts efficiently, the matrix tests wrap execution using both standard types and specialized matrix-variate structures:
2. Edge Case & Boundary Verification
3. Subgradient Tie Resolution
Because max and min contain non-differentiable where values tie, the tests verifies the subgradient approach:
4. Comprehensive NaN Framework Diagnostics
NaN handling is tested in multiple arrangements:
Side Effects
Release notes
Checklist
Copyright holder: (fill in copyright holder information)
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