question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FR] add betaincinv

See original GitHub issue

Summary

Requesting the betaincinv function be added to jax.scipy.special. This is the inverse of the regularized incomplete beta function, or the PPF / quantile function for the Beta distribution.

Use case

I’m coming to JAX from numpyro, in which I’m trying to implement Gaussian copula models (example here). I’m looking for models with Beta marginals, which requires the inverse CDF / quantile function for the Beta distribution. After betainc was added in #1998, we have the CDF, but not the quantile function.

Having both the betainc and betaincinv functions would allow the addition of CDF and PPF methods to jax.scipy.stats.beta, much like the norm class and the scipy implementation. The betaincinv in particular would allow one to transform correlated uniform samples into correlated Beta samples (but the details are unrelated).

Other thoughts

I have no idea how much work this would take. On one hand, PR #1998 didn’t seem like a hugely complex change (though still far above my understanding of JAX, so above all thank you for your hard work). On the other, the SciPy implementation of betainvinc is nasty and I have no idea if this has to be re-implemented in JAX or something like that.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
derekpowellcommented, Apr 20, 2021

Just commenting to say I would also really value this feature and, though you are all most likely already aware, to point out that Stan has gradients implemented for their inc_beta function. I believe this is the implementation.

3reactions
srvasudecommented, Mar 12, 2020

Hi! Yep I am planning on adding to both TF and XLA the betaincinv function. I should be getting to this hopefully soon (I have a proto-type written in TF C++, so I should be sending that out shortly. Translating to XLA will take a bit of time, but I’ll have an implementation to compare against 😃 ).

In case you want to get something running sooner, I might recommend using Kumaraswamy marginals: https://en.wikipedia.org/wiki/Kumaraswamy_distribution. Kumaraswamy CDFs / Inverse CDFs are very easy to compute, and it has very similar shapes to a Beta distribution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tfp.math.betaincinv - Probability
Computes the inverse of tfp.math.betainc with respect to x.
Read more >
scipy.special.betaincinv — SciPy v1.9.3 Manual
This function is the inverse of betainc for fixed values of a and b . >>> a, b = 1.2, 3.1 ...
Read more >
MATLAB betaincinv
This MATLAB function computes the inverse incomplete beta function for corresponding elements of y, z, and w, such that y = betainc(x,z,w).
Read more >
mars.tensor.special.betaincinv
out (ndarray, optional) – Optional output array for function values. Returns. Value of the inverse of the incomplete beta function. Return type. array-like....
Read more >
bug #60528: betaincinv throws error for some valid inputs
So I would propose to add here only tests of the kind assert(betaincinv(betainc(x)),x,eps(x)) or the other way around. You can use trial and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found