Skip to content
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

Incomplete Beta Function Inverse #2637

Merged
merged 17 commits into from
Mar 26, 2022
Merged

Incomplete Beta Function Inverse #2637

merged 17 commits into from
Mar 26, 2022

Conversation

andrjohns
Copy link
Collaborator

Summary

This PR adds the inverse of the incomplete beta function, will be needed for some of the quantile/icdf functions to come.

Tests

Individual rev/fwd/mix tests have been added, as the gradients use the F32 hypergeometric series and the autodiff finite-differencing tests are not stable.

Side Effects

The F32 templating has been relaxed to allow each of the inputs to be different types

Release notes

Add the incomplete beta function inverse

Checklist

  • Math issue Incomplete Beta Inverse #2513

  • Copyright holder: Andrew Johnson

    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

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • the code is written in idiomatic C++ and changes are documented in the doxygen

  • the new changes are tested

@spinkney
Copy link
Collaborator

spinkney commented Dec 31, 2021

Wow, so fast, thanks @andrjohns!

Do you mind if I put in the latex formulas for the partials in the rev file documentation?

@andrjohns
Copy link
Collaborator Author

Ah good point forgot about those! Yeah feel free to add them, otherwise I can do it tonight/tomorrow

@andrjohns
Copy link
Collaborator Author

@serban-nicusor-toptal it looks like the downstream tests for this are failing due to some odd git errors, would you mind having a look when you get a minute?

@serban-nicusor-toptal
Copy link
Contributor

serban-nicusor-toptal commented Jan 3, 2022

Hey, checking!

Edit: Should be fine now.

@andrjohns
Copy link
Collaborator Author

Thanks for sorting this so quickly!

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.52 3.51 1.0 0.28% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.04 4.02% faster
eight_schools/eight_schools.stan 0.09 0.09 0.99 -0.92% slower
gp_regr/gp_regr.stan 0.14 0.14 1.0 -0.3% slower
irt_2pl/irt_2pl.stan 5.78 5.73 1.01 1.01% faster
performance.compilation 93.32 91.94 1.01 1.48% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.15 8.09 1.01 0.76% faster
pkpd/one_comp_mm_elim_abs.stan 31.42 31.71 0.99 -0.92% slower
sir/sir.stan 119.43 118.71 1.01 0.61% faster
gp_regr/gen_gp_data.stan 0.03 0.04 0.94 -5.94% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.0 2.96 1.01 1.16% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.39 0.39 1.0 0.38% faster
arK/arK.stan 2.07 2.09 0.99 -0.85% slower
arma/arma.stan 0.23 0.23 0.99 -0.6% slower
garch/garch.stan 0.59 0.63 0.94 -6.75% slower
Mean result: 0.996282562232

Jenkins Console Log
Blue Ocean
Commit hash: 085f8ea


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@spinkney
Copy link
Collaborator

spinkney commented Jan 4, 2022

I don't feel comfortable reviewing the cpp but the derivatives and tests look good to me. Maybe @SteveBronder can take a look?

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.62 3.55 1.02 1.92% faster
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.01 0.8% faster
eight_schools/eight_schools.stan 0.09 0.09 1.01 0.71% faster
gp_regr/gp_regr.stan 0.14 0.14 0.98 -2.3% slower
irt_2pl/irt_2pl.stan 5.77 5.71 1.01 0.92% faster
performance.compilation 93.4 91.94 1.02 1.55% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 8.04 8.12 0.99 -0.99% slower
pkpd/one_comp_mm_elim_abs.stan 30.77 32.9 0.94 -6.9% slower
sir/sir.stan 120.99 121.56 1.0 -0.47% slower
gp_regr/gen_gp_data.stan 0.03 0.04 0.99 -1.23% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.01 2.97 1.01 1.29% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.38 0.39 0.98 -2.34% slower
arK/arK.stan 2.07 2.11 0.98 -2.14% slower
arma/arma.stan 0.23 0.23 1.0 -0.38% slower
garch/garch.stan 0.58 0.61 0.95 -4.96% slower
Mean result: 0.990959384528

Jenkins Console Log
Blue Ocean
Commit hash: 5803eea


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@spinkney
Copy link
Collaborator

will it be possible to get this in to the 2.29 release? We can then do student_t copulas

@andrjohns
Copy link
Collaborator Author

@serban-nicusor-toptal looks like the jenkins for this one is having trouble with clang-format, if you wouldn't mind having a look when you've got a minute:

git checkout -b feature/ibeta_inv
Switched to a new branch 'feature/ibeta_inv'
+ clang-format --version
/home/jenkins/workspace/Stan_Math_PR-2637@tmp/durable-c616a978/script.sh: line 4: clang-format: command not found
+ xargs -n20 -P8 clang-format -i
+ find stan test -name '*.hpp' -o -name '*.cpp'
xargs: clang-format: No such file or directory
++ git diff
+ [[ '' != '' ]]

@rok-cesnovar
Copy link
Member

Can you try merging in the latest develop, there were quite a few changes in the Jenkinsfile and test machine since then. Hopefully that will help.

@andrjohns
Copy link
Collaborator Author

Can you try merging in the latest develop, there were quite a few changes in the Jenkinsfile and test machine since then. Hopefully that will help.

Ah thought I had but it hadn't triggered a new CI run for some reason

@andrjohns
Copy link
Collaborator Author

@rok-cesnovar or @SteveBronder would either of you have a minute to review this one? @spinkney has signed off on the math, so it's just the c++ to be checked

@rok-cesnovar
Copy link
Member

I can do it today. We wont be able to merge after we do the patch release (stan-dev/cmdstan#1086) which should be in a day or two.

@andrjohns
Copy link
Collaborator Author

Thanks! There's no rush at all on this, so just whenever you get the time

Copy link
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I only have one question in two places.

stan/math/prim/fun/inv_inc_beta.hpp Show resolved Hide resolved
stan/math/fwd/fun/inv_inc_beta.hpp Show resolved Hide resolved
@andrjohns
Copy link
Collaborator Author

@rok-cesnovar This should be all ready for another look

Copy link
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go! Thanks Andrew!

@andrjohns
Copy link
Collaborator Author

Thanks!

@andrjohns andrjohns merged commit cd230dc into stan-dev:develop Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants