Skip to content

Convert zero-inflated distributions to Mixture subclasses #2231

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

Closed
wants to merge 40 commits into from

Conversation

fonnesbeck
Copy link
Member

Added the ZIB distribution to discrete.py, along with tests.

fonnesbeck and others added 16 commits May 27, 2017 14:46
* Make spacing more compliant to PEP8

* Raise NotImplementedError from SplineWrapper grad operation

Fixes #2209

* Instantiate SplineWrapper recursively to simplify the architecture

* Create spline derivatives lazily

* Move grad_op to a separate property

* Add tests for SplineWrapper

* Fix style issues
* add draft

* add draft

* move and rename

* better docstring

* added tests
WIP: replace Hessian scaling guessing by an identity matrix
…tity"

This reverts commit eb6042f, reversing
changes made to c3afa00.
@@ -591,6 +591,10 @@ def test_zeroinflatednegativebinomial(self):
self.checkd(ZeroInflatedNegativeBinomial, Nat,
{'mu': Rplusbig, 'alpha': Rplusbig, 'psi': Unit})

def test_zeroinflatedbinomial(self):
self.checkd(ZeroInflatedBinomial, Nat,
Copy link
Member

@junpenglao junpenglao May 29, 2017

Choose a reason for hiding this comment

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

You forgot to import ZeroInflatedBinomial in the test_distributions.py

@twiecki
Copy link
Member

twiecki commented May 29, 2017

Too bad we still haven't figured out how to do this with the Mixture class.

@fonnesbeck
Copy link
Member Author

Let me look into it. Might not be worth the overhead just to use Mixture, but I will see if that's true.

@fonnesbeck
Copy link
Member Author

Actually, its pretty easy. Hold off on merging this for the moment; I will convert all the zero-inflated distributions over and move them to distributions/mixture.

@twiecki
Copy link
Member

twiecki commented May 29, 2017

Is it? I think we tried it but it wasn't easy to define a 0-distribution. CC @AustinRochford

@fonnesbeck
Copy link
Member Author

Just used a Constant.dist(0).

Here is the zero-inflated Poisson in action.

@twiecki
Copy link
Member

twiecki commented May 29, 2017

#1459

@fonnesbeck
Copy link
Member Author

And here is zero-inflated binomial. Seems to work. Let me know if I am missing something (I very well could be).

@fonnesbeck
Copy link
Member Author

Please test.

@fonnesbeck fonnesbeck changed the title Zero-inflated Binomial Convert zero-inflated distributions to Mixture subclasses May 29, 2017
"""

def __init__(self, psi, theta, *args, **kwargs):
self.theta = theta = tt.as_tensor_variable(theta)
Copy link
Member

Choose a reason for hiding this comment

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

you should also cast psi into tensor (same below), although might not necessary after #2233 is merge

Copy link
Member Author

Choose a reason for hiding this comment

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

That happens in the superclass init (Line 48)

@fonnesbeck
Copy link
Member Author

fonnesbeck commented May 29, 2017

Since these are always 2-component mixtures, I've changed the psi to import a scalar rather than a vector (e.g. a Beta rather than a Dirichlet). This is consistent with the API of the existing zero-inflateds.

@fonnesbeck
Copy link
Member Author

Seems to have a problem generating random draws with a multidimensional size. Not sure why.

@AustinRochford
Copy link
Member

AustinRochford commented May 30, 2017

Looks good overall. I had similar problems matching scipy and with random draws when I tried this before. Will give some thought as to possible problems.

twiecki and others added 2 commits May 30, 2017 17:06
* Change sample() to use live_plot_kwargs instead of **kwargs.

* Pass kwargs of sample to _sample.

* Typo wargs -> kwargs.

* Re-add kwargs to _sample().
* [WIP] clean up GLM doc

* pm.glm.glm -> pm.glm.GLM.from_formula
* pm.glm.plot_posterior_predictive -> pm.plot_posterior_predictive_glm
* remove find_MAP and used default init

* More clean up

* more clean up

* GLM doc clean up

last notebook. change to a slidely different example.
@AustinRochford
Copy link
Member

Passing broadcast_conditions=False to bound in Mixture's logp method fixes the broken ZIP and ZINB tests for me, but the ZIB test is still failing.

This was the reason for broadcast_conditions, so I'll add that in a separate PR and keep investigating the ZIB failure.

Parameters
----------
psi : float
Expected proportion of Poisson variates (0 < psi < 1)
Copy link
Member

Choose a reason for hiding this comment

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

Should say Binomial

@AustinRochford
Copy link
Member

@fonnesbeck the broadcast_conditions change is merged to master, rebasing should get more (but not all) tests to pass.

@fonnesbeck
Copy link
Member Author

Well, I rebased instead of merged, so this branch is irrevocably messed up. Closing in favor of #2246

@fonnesbeck fonnesbeck closed this May 31, 2017
@junpenglao junpenglao deleted the zero_inflated_binomial branch May 31, 2017 05:21
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 this pull request may close these issues.

8 participants