-
-
Notifications
You must be signed in to change notification settings - Fork 230
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
Unable to define Dirichlet prior #178
Comments
What sort of output are you seeing? Any warnings or error messages? Also, is there a reason for using PyMC2? We recommend new projects use PyMC3 for building statistical models. You don’t get gradient-based samplers in PyMC2, which is a big deal. |
Hi Chris Thanks for responding. I don't get any warnings other than the depreciation warning shown at the end of this comment. PyMC2 produces a trace, but all elements of the trace are the same as the starting value, i.e. [0.25, 0.25, 0.25, 0.25]. Since stats.dirichlet.logpdf(value, pms) will return an error unless sum(value)==1, I am guessing that proposals are being generated that do not satisfy this condition, hence are always rejected. As for PyMC3, I have been working on this also, but come up against the same problem. That is, if I enforce the condition sum(value)==1 in my function to return logpdf, eg:
then all proposals appear to be rejected. Presumably the PyMC code has some way of generating compliant proposals for the Dirichlet distribution, but I don't know how this is done. If I did, I might be able to emulate it. Following is the PyMC2 warning that I received:
|
As far as the PyMC2 implementation is concerned, you will probably have more success passing in k-1 parameters and let PyMC do the simplex for you, rather than all k probabilities. Sampling tends to be more successful this way. On the PyMC3 end, there are transformations that will automatically do the same thing (enforce a simplex). The Dirichlet distribution in PyMC3 uses a stick-breaking transformation for this, to ensure that the probabilities sum to one, without doing all the manual manipulation that you are coding. The best place to go for support in developing custom distributions is our Discourse site. We have several developers, along with hundreds of users, that read the site and will often chime in with feedback. They are particularly interested in helping folks do new things with PyMC3, so I expect you would get a fair bit of support. |
Thanks. The stick-breaking transormation did the job. If anyone else comes across this, the corrected code is as follows:
|
🎉 |
Hello
I am trying to build a simple model to estimate parameters of a multinomial distribution using a Dirichlet prior. Using the inbuilt Dirichlet distribution as in the following code seems to work OK as follows (JUpyter notebook also attached).
However, I am trying to replace the inbuilt Dirichlet distribution by a user-defined one (which I plan to modify later) as per below, and the samples never leave thee starting value. Am I doing something wrong? Environment is:
numpy version 1.11.3
pymc version 2.3.6
3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 12:43:10)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
The text was updated successfully, but these errors were encountered: