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

Implement grad for GammaInc #74

Closed
MrinankSharma opened this issue Oct 4, 2020 · 3 comments · Fixed by #513
Closed

Implement grad for GammaInc #74

MrinankSharma opened this issue Oct 4, 2020 · 3 comments · Fixed by #513

Comments

@MrinankSharma
Copy link

The Gamma logcdf does not have a gradient function implemented.

Example:

self.GI_mean = pm.Normal('GI_mean', gi_mean_mean, gi_mean_sd)
self.GI_sd = pm.Normal('GI_sd', gi_sd_mean, gi_sd_sd)

gi_beta = self.GI_mean / self.GI_sd ** 2
gi_alpha = self.GI_mean ** 2 / self.GI_sd ** 2

GI_dist = pm.Gamma.dist(alpha=gi_alpha, beta=gi_beta)

bins = np.zeros(gi_truncation + 1)
bins[1:] = np.arange(gi_truncation)
bins[2:] += 0.5
bins[:2] += 1e-5

cdf_vals = T.exp(GI_dist.logcdf(bins))
pmf = cdf_vals[1:] - cdf_vals[:-1]
GI_rev = T.repeat(T.reshape(pmf[::-1] / T.sum(pmf), (1, 1, gi_truncation)), 2, axis=0)

Trying to sample from this raises an error:

MethodNotDefined: ('grad', <class 'theano.scalar.basic_scipy.GammaInc'>, 'GammaInc')

Note: the logcdf derivative should be available as a function of the logpdf. It would be great to have this implemented. For example, this would mean my use case above (generating a discretised distribution) can be implemented.

@twiecki
Copy link
Contributor

twiecki commented Oct 4, 2020

Thanks for reporting -- want to do a PR?

@MrinankSharma
Copy link
Author

Thanks for reporting -- want to do a PR?

I'd be up for working on a PR, but I've never submitted a PR on the PyMC3 codebase before. If you think this can be tackled by a newcomer, I can give it a go.

@twiecki
Copy link
Contributor

twiecki commented Oct 4, 2020

I think you'd learn a lot and we'll definitely help out.

@brandonwillard brandonwillard changed the title Implement Gamma logcdf Derivative Implement grad for Gamma/GammaLn and GammaInc Oct 12, 2020
@brandonwillard brandonwillard changed the title Implement grad for Gamma/GammaLn and GammaInc Implement grad for GammaInc Oct 12, 2020
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 a pull request may close this issue.

2 participants