Skip to content

Building a model that requires external function in pymc3? #377

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
bhayden53 opened this issue Oct 31, 2013 · 5 comments
Closed

Building a model that requires external function in pymc3? #377

bhayden53 opened this issue Oct 31, 2013 · 5 comments
Labels

Comments

@bhayden53
Copy link

Hello,

I have been anxiously awaiting HMC functionality in pymc3; thanks for all the work everyone has put in.

I am attempting to make a model in pymc3 which requires one of the free parameters of my model to be operated on by an external python package. For instance, one of my 'free' parameters is an unknown parameter of the cosmology of the universe, and a set of integrals needs to be performed on this parameter in order to estimate an observable quantity.

Perhaps I just don't understand what's going on in pymc3, but I can't figure out how to do this since pm.Uniform returns a Theano TensorVariable. The basic structure of what I'm trying to do looks like:

import pymc as pm
import cosmology_calculator

data = some_data_from_somewhere
with pm.Model() as model:
    cosmo_param = pm.Uniform( 'cosmo_param', lower=0.0, upper=1.0 )
    cosmo_observable = cosmology_calculator( cosmo_param ) 

The cosmology_calculator step immediately wants the input to be a float, which crashes because it's a Tensor.

Is there any way to construct a model in pymc3 that can do this?

@twiecki
Copy link
Member

twiecki commented Nov 8, 2013

Yeah, this is something we have to fix.

Unfortunately if your likelihood is a blackbox function there is no way to compute the gradient and you can't run HMC.

@jsalvatier
Copy link
Member

You can build a Theano Op which does the computation.

This is not too hard, but it's not trivial either. See here for some examples.

One goal of ours will be to make this pretty trivial for simple cases.

@twiecki
Copy link
Member

twiecki commented Jun 17, 2014

Closing this in favor of #507.

@twiecki twiecki closed this as completed Aug 17, 2014
@docyyz
Copy link

docyyz commented Aug 21, 2018

I'm interested to know this answer to this post as well, but the links posted above don't exist anymore.

@twiecki
Copy link
Member

twiecki commented Aug 21, 2018

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

4 participants