Is it possible to sample from a user provided target measure in PyMC3 in an easy way? I.e. I want to be able to provide black box functions logposterior(theta)
and grad_logposterior(theta)
that and sample from those instead of specifying a model in PyMC3s modeling language.
Asked
Active
Viewed 299 times
5

devnull
- 147
- 1
- 5
-
Does this example meet your needs? https://github.com/pymc-devs/pymc3/blob/master/pymc3/examples/arbitrary_stochastic.py If not, please expand your question to show what you've tried and where you got stuck. – Abraham D Flaxman Jul 10 '15 at 18:09
-
1The problem with this example is that `logp` is still an expression (which PyMC3 can use to compute the symbolic gradient and hessian), while I am talking about _black box functions_ that can only be evaluated. Edited the question to be more clear here. The reasoning for this is that I already have a collection of target densities with accompanying gradient functions and would like to not have to transform them all into PyMC3/Theano expressions. – devnull Jul 13 '15 at 07:51
1 Answers
3
This is a bit clunky. You'd need to create a new Theano Op
. Here are a few examples: https://github.com/Theano/Theano/blob/master/theano/tensor/slinalg.py#L32
You then need to create a distribution class that evaluates the logp via your new Op
, for example: https://github.com/pymc-devs/pymc3/blob/master/pymc3/distributions/continuous.py#L70

twiecki
- 1,316
- 8
- 11
-
Yep, that seems to be the best way. Thanks a lot! But you're right its clunky, and easier to rewrite as Theono expressions after all. – devnull Aug 06 '15 at 09:48
-
If you have an example, please consider doing a PR as I'm sure it's not an overly uncommon use-case. – twiecki Aug 06 '15 at 13:56