# Using pymc3 NUTS sampler for an "external model" having its derivatives with respect to its parameters

**URL:** <https://discourse.pymc.io/t/using-pymc3-nuts-sampler-for-an-external-model-having-its-derivatives-with-respect-to-its-parameters/891>\
**Category:** Questions\
**Created:** [February 26, 2018, 6:45am UTC](https://discourse.pymc.io/t/using-pymc3-nuts-sampler-for-an-external-model-having-its-derivatives-with-respect-to-its-parameters/891 "2018-02-26T06:45:58Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [February 26, 2018, 7:12am UTC](https://discourse.pymc.io/t/using-pymc3-nuts-sampler-for-an-external-model-having-its-derivatives-with-respect-to-its-parameters/891/2 "2018-02-26T07:12:52Z")

</div>

The general route is to wrap the external model in theano, and implement a `grad` method for it as well.  
For example, this post shows you how to call an external model (from scipy) to do numerical integration:

> [@Custom theano Op to do numerical integration](https://discourse.pymc.io/t/custom-theano-op-to-do-numerical-integration/734):
>
> I am using PyMC3 for parameter estimation using a particular likelihood function which has to be defined. Here L is the analytic form of my Likelihood function. I have some observational data for the radial velocity(vr) and postion ® for some objects, which is imported from excel file. My priors are M and beta which is assumed to be a uniform distribution.I want to incorporate an integral integ(gamma, beta)into my likelihood function that actually is a function of one of my parameter. I tried us…

And here is two more examples from @aseyboldt:

> <https://gist.github.com/aseyboldt/57ebb66dd6597d6ea7a9d59f24f264e0>

> <https://gist.github.com/aseyboldt/9e7c8dafaec8325d5ec1f8b912d45b1b>

@aseyboldt is currently writing a blog post on the later one, but I think you should have enough information to give it a go 😉

---

_[View the full topic](https://discourse.pymc.io/t/using-pymc3-nuts-sampler-for-an-external-model-having-its-derivatives-with-respect-to-its-parameters/891)._
