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

Support constraints.cat and CatTransform #1872

Open
adrn opened this issue Sep 30, 2024 · 4 comments
Open

Support constraints.cat and CatTransform #1872

adrn opened this issue Sep 30, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@adrn
Copy link
Contributor

adrn commented Sep 30, 2024

Hello!

I have a custom multi-dimensional distribution where the support may be truncated along some dimensions. In terms of constraints, some dimensions will either be real, greater_than, less_than, or interval. I naively was then implementing the support as, e.g.:

ivl = constraints.interval([0., -jnp.inf, 5.], [jnp.inf, 0., 10.])

Right now, this is not really supported by the numpyro.distributions.constraints.Interval class because of how feasible_like() works, or how the scale is computed in the unconstrained transform. Would you be open to making these things inf-safe? So far I instead implemented a custom subclass InfSafeInterval(constraints._Interval) to support this, but thought I would check in on this. Thanks!

@fehiepsi
Copy link
Member

fehiepsi commented Oct 4, 2024

Hi @adrn, for parameters with different domains, it is better to split them out, e.g. ivl0, ivl1, ivl2 in your case. We don't plan to support mixed-domain support.

@fehiepsi fehiepsi added the question Further information is requested label Oct 4, 2024
@adrn
Copy link
Contributor Author

adrn commented Oct 4, 2024

Thanks for the response! That makes sense. But hm, it's possible what I want to do is not supported at the moment. For my custom distribution, some pairs of the parameters are not independent and so I can't split them out easily. And some may have real support, some interval, and some greater_than/less_than. This is probably a hack, but I ended up implementing a custom Constraint and Transform that can handle the joint and independent parameters and their supports separately...

@fehiepsi
Copy link
Member

fehiepsi commented Oct 4, 2024

If you want to build a custom joint distribution then cat constraints and CatTransform might be helpful https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.CatTransform We can modify the title and make this a feature request I guess?

@fehiepsi fehiepsi added enhancement New feature or request and removed question Further information is requested labels Oct 5, 2024
@fehiepsi fehiepsi changed the title Make Interval safe to inf values? Support constraints.cat and CatTransform Oct 5, 2024
@fehiepsi fehiepsi added the good first issue Good for newcomers label Oct 5, 2024
@amifalk
Copy link
Contributor

amifalk commented Nov 3, 2024

We did something like this with the ConstraintCollection here: https://github.com/compmem/cognax/blob/main/cognax/joint/gaussian_copula.py - may be a helpful resource.

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
Projects
None yet
Development

No branches or pull requests

3 participants