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

Truncated gamma #1187

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions numpyro/distributions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@
from numpyro.distributions.transforms import biject_to
from numpyro.distributions.truncated import (
LeftTruncatedDistribution,
LeftTruncatedGamma,
RightTruncatedDistribution,
RightTruncatedGamma,
TruncatedCauchy,
TruncatedDistribution,
TruncatedGamma,
TruncatedNormal,
TruncatedPolyaGamma,
TwoSidedTruncatedDistribution,
TwoSidedTruncatedGamma,
)

from . import constraints, transforms
Expand Down Expand Up @@ -141,6 +145,7 @@
"MultinomialLogits",
"MultinomialProbs",
"MultivariateNormal",
"LeftTruncatedGamma",
"LowRankMultivariateNormal",
"Normal",
"NegativeBinomialProbs",
Expand All @@ -152,16 +157,19 @@
"ProjectedNormal",
"PRNGIdentity",
"RightTruncatedDistribution",
"RightTruncatedGamma",
"SineBivariateVonMises",
"SineSkewed",
"SoftLaplace",
"StudentT",
"TransformedDistribution",
"TruncatedCauchy",
"TruncatedDistribution",
"TruncatedGamma",
"TruncatedNormal",
"TruncatedPolyaGamma",
"TwoSidedTruncatedDistribution",
"TwoSidedTruncatedGamma",
"Uniform",
"Unit",
"VonMises",
Expand Down
20 changes: 19 additions & 1 deletion numpyro/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
import jax.numpy as jnp
import jax.random as random
from jax.scipy.linalg import cho_solve, solve_triangular
from jax.scipy.special import betainc, expit, gammaln, logit, multigammaln, ndtr, ndtri
from jax.scipy.special import (
betainc,
expit,
gammainc,
gammaln,
logit,
multigammaln,
ndtr,
ndtri,
)

from numpyro.distributions import constraints
from numpyro.distributions.distribution import Distribution, TransformedDistribution
Expand Down Expand Up @@ -282,6 +291,15 @@ def mean(self):
def variance(self):
return self.concentration / jnp.power(self.rate, 2)

def cdf(self, value):
return gammainc(self.concentration, value * self.rate)

def icdf(self, q):
# https://github.com/pyro-ppl/numpyro/issues/969
from numpyro.distributions.util import gammaincinv
Copy link
Member

Choose a reason for hiding this comment

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

I think you can move this import to the top.


return gammaincinv(self.concentration, q) / self.rate


class Chi2(Gamma):
arg_constraints = {"df": constraints.positive}
Expand Down
Loading