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

Possible bug in gate_logits of ZeroInflatedDistribution #3301

Closed
reemagit opened this issue Dec 5, 2023 · 5 comments
Closed

Possible bug in gate_logits of ZeroInflatedDistribution #3301

reemagit opened this issue Dec 5, 2023 · 5 comments
Labels

Comments

@reemagit
Copy link

reemagit commented Dec 5, 2023

=== UPDATE ===
corrected typos in code
=== UPDATE ===

When I use the gate_logits parameter of ZeroInflatedPoisson I get unexpected behavior in the number of zeros sampled by the distribution. This doesn't happen if I use the gate parameter.

import torch
import pyro.distributions as dist

N=1000 # num samples
rate=torch.tensor(100.) ## arbitrary rate
p = torch.tensor(0.3) # inflation probability
logit = torch.log(p / (1-p)) # logit of inf. prob.

x1 = (dist.ZeroInflatedPoisson(rate=rate, gate_logits=logit).sample([N])==0).sum()/N 
x2 = (dist.ZeroInflatedPoisson(rate=rate, gate=p).sample([N])==0).sum()/N 

print(x1) # prints approximately 0.3
print(x2) # prints 1.

I would expect that both x1 and x2 are close to 0.3 (the inflation probability). Am I missing something or is this a bug?

@fritzo fritzo added the bug label Dec 5, 2023
@fritzo
Copy link
Member

fritzo commented Dec 5, 2023

@reemagit is there a typo? x1 and x2 appear to be identical?

@reemagit
Copy link
Author

reemagit commented Dec 5, 2023

@fritzo I apologize, I corrected a couple of typos, thanks.

@ordabayevy
Copy link
Member

@reemagit can you check and see if #3303 fixes the bug?

@reemagit
Copy link
Author

reemagit commented Dec 7, 2023

I currently don't have the development version installed, so I can't check, sorry. However, looking at the fix I think that that was the problem, since I've had similar issues with logits_to_probs and probs_to_logits in the past.
Thanks

@ordabayevy
Copy link
Member

Closed via #3303

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants