Skip to content

Reverse-mode grad_reg_inc_beta (part 2 of #3409) - #3489

Draft
SteveBronder wants to merge 1 commit into
stable-inc-betafrom
stable-inc-beta-rev
Draft

SteveBronder wants to merge 1 commit into
stable-inc-betafrom
stable-inc-beta-rev

Conversation

@SteveBronder

@SteveBronder SteveBronder commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part 2 of 3 of the split of #3409. Stacked on #3409 (base stable-inc-beta). Part 3, #3490, is stacked on this one.

Summary

Adds a reverse-mode grad_reg_inc_beta. For var arguments the values are computed in double by the prim overload. The reverse pass computes the a and b adjoints directly as H v, where H is the Hessian of I_z(a, b) in (a, b), from the power series or the continued fraction, instead of taping through the loop. The z adjoint is closed form. A one-sided request computes only H_aa or H_bb unless the cross term is needed. rev/fun/inc_beta.hpp is rewritten with make_callback_var. The GRAD_RIB overload of prim grad_reg_inc_beta now excludes var arguments, which go to the new rev overload. In #3409 alone it accepts every scalar type.

The algorithm, the accuracy study and the benchmarks are in the description of #3409.

Files

  • stan/math/rev/fun/grad_reg_inc_beta.hpp (new)
  • stan/math/rev/fun/inc_beta.hpp
  • stan/math/rev/fun.hpp
  • stan/math/prim/fun/grad_reg_inc_beta.hpp: the require_all_not_var_t on the GRAD_RIB overload
  • test/unit/math/rev/fun/inc_beta_test.cpp (new): shape gradients of inc_beta with var arguments at the defect points of More stable incomplete beta gradient roots #3409.
  • test/unit/math/mix/fun/grad_reg_inc_beta_test.cpp, test/unit/math/mix/fun/inc_beta_test.cpp: mix tests, with the upper-bound test started from an empty autodiff stack.

Release notes

See #3409.

Checklist

  • Copyright holder: Aalto University

    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

…pass

Add the rev specialization of grad_reg_inc_beta and use it in rev
inc_beta. The prim GRAD_RIB overload now excludes var arguments, which
go to the rev overload. Add the rev and mix tests.
@SteveBronder
SteveBronder added this pull request to stack #3491 October 26, 2026 19:14
SteveBronder added a commit that referenced this pull request Oct 26, 2026
Moves this branch onto the split of #3409 (#3409, #3489, #3490). The
conflicts are resolved to the tree of these commits replayed onto
stable-inc-beta-cdfs.
@avehtari avehtari added the numerics Numerical issues label Oct 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

numerics Numerical issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants