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

Add JAX implementation for InvGammaRV #1368

Closed
Tracked by #1425
rlouf opened this issue Dec 13, 2022 · 12 comments · Fixed by #1480
Closed
Tracked by #1425

Add JAX implementation for InvGammaRV #1368

rlouf opened this issue Dec 13, 2022 · 12 comments · Fixed by #1480
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed JAX Involves JAX transpilation random variables Involves random variables and/or sampling

Comments

@rlouf
Copy link
Member

rlouf commented Dec 13, 2022

No description provided.

@rlouf rlouf added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed JAX Involves JAX transpilation random variables Involves random variables and/or sampling labels Dec 13, 2022
@manish-p-gupta
Copy link

Hey, I'm new here but I have some idea of working with JAX. Is this up for contributions?

@rlouf
Copy link
Member Author

rlouf commented Jan 22, 2023

By all means!

@manish-p-gupta
Copy link

Great! Can you point me to any starting documentation that'll be helpful. I am aware about the contributing guidelines. Let me know if you think I should do anything else. I'll open a draft PR to discuss things in detail there too!

@rlouf
Copy link
Member Author

rlouf commented Jan 23, 2023

Here's an explanation I gave in a related issue. This should be enough to get you started: #1335 (comment)

@manish-p-gupta
Copy link

Okay thanks! I'll go over it and start the work.

@PaulScemama
Copy link

PaulScemama commented Feb 25, 2023

@rlouf I've been taking a look at this and may have come across a small notational choice that may cause confusion with users.

In aesara/tensor/random/basic.py, there exists an Inverse Gamma random variable. In it's documentation, it says "the probability density function for invgamma in terms of its shape parameter $\alpha$ and $\text{scale}$ parameter $\beta$ is:

$$ f(x; \alpha, \beta) = \frac{\beta^\alpha}{\Gamma(\alpha)} x^{-(\alpha+1)} \exp\left(-\frac{\beta}{x}\right) $$

".

This, however, creates a confusing discrepancy between Aesara's documentation of the Gamma random variable.In it's documentation, says "the probability density function for gamma in terms of the shape parameter $\alpha$ and $\text{rate}$ parameter $\beta$ is:*

$$ f(x; \alpha, \beta) = \frac{\beta^\alpha}{\Gamma(\alpha)}x^{\alpha-1}e^{-\beta x} $$

".

I think the InvGamma documentation should follow the Gamma, and the rate parameter ($\beta$) should be passed in, and then transformed to the scale by its reciprocal.

BTW: @manish-p-gupta are you still working on this? If not, I don't mind taking a stab at it. Let me know what you both think! Thanks.

@rlouf
Copy link
Member Author

rlouf commented Feb 25, 2023

I agree with the fact that it is confusing; I actually made a mistake because of this when using Aesara in a project. I believe that we were blindly following SciPy when implementing this. But now the issue is that downstream code may be relying on this API so we have to be cautious.

You can get a stab at the JAX implementation if you'd like!

@PaulScemama
Copy link

In terms of the parameter name thing: Ah I see. I can take a peek and see how much downstream code is reliant on it. I agree that being cautious is the best plan.

Also sounds good, thanks! I have to get public release permission (from work) if I were to literally contribute so it may take a week or so.

@PaulScemama
Copy link

PaulScemama commented Mar 7, 2023

Hi @rlouf @brandonwillard just checking in here.

To review: the InvGammaRV in aesara/tensor/random/basic.py has some confusing variable naming and documentation that doesn't align with GammaRV in the same file. You mentioned we should be cautious in fixing this in case downstream code depends on it.

Here's what I've found regarding the downstream code dependence on InvGammaRV:

In conclusion, the files affected by a change in InvGammaRV are...

  1. the file it is defined in aesara/tensor/random/basic.py
  2. the file testing it tests/tensor/random/test_basic.py

Note, invgamma shows up in doc/reference/random/index.rst, but I don't think changing anything about InvGammaRV will change this?

Let me know what you think.

@brandonwillard
Copy link
Member

Let me know what you think.

I think the bigger issue is user-written code and other packages that depend on the current parameterization.

@PaulScemama
Copy link

PaulScemama commented Mar 10, 2023

@brandonwillard makes sense. So should I go ahead then and give the JAX implementation a go with how our Inverse-Gamma currently stands?

And I totally forgot about the other "children" packages of Aesara 😅, that is definitely not just 2 files then.

@brandonwillard
Copy link
Member

So should I go ahead then and give the JAX implementation a go with how our Inverse-Gamma currently stands?

Yeah, feel free to create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed JAX Involves JAX transpilation random variables Involves random variables and/or sampling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants