# Custom likelihood from a python function

**URL:** <https://discourse.pymc.io/t/custom-likelihood-from-a-python-function/11637>\
**Category:** v5\
**Tags:** modeling\
**Created:** [March 17, 2023, 10:32am UTC](https://discourse.pymc.io/t/custom-likelihood-from-a-python-function/11637 "2023-03-17T10:32:33Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![BaptisteDE](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@BaptisteDE](https://discourse.pymc.io/u/BaptisteDE)\
**Post date:** [May 16, 2024, 9:26am UTC](https://discourse.pymc.io/t/custom-likelihood-from-a-python-function/11637/4 "2024-05-16T09:26:31Z")

</div>

> [@BrynWalton](#):
>
> custon

Hello !  
I have a similar problem, I would like to use the result of an FMU (Fuctional Mockup Unit) calculation as the mean of my likelyhood function. I already wrapped the FMU in a python function, but it doesn’t accept Pytensors.

I think this is similar to this discussion:

> [@Using PyMC3 with external functions](https://discourse.pymc.io/t/using-pymc3-with-external-functions/6403):
>
> I am trying to use PyMC3 to replace emcee as my MCMC sampler of choice. However, I depend on external functions to draw the model curves, which I import from existing packages that are not compatible with Theano’s style. How can I still use PyMC3 as a sampler? For example: #::: Option 1: How the external fct currently looks def external\_fct\_1(x, xmid, depth): y = np.zeros\_like(x) y[(x\>xmid-0.1) & (x\<xmid+0.1)] = -depth return y #::: Option 2: Rewriting the external fct in Theano…

I tried to find the tutorials listed here :  
_“Specifically, the tutorial on using a [blackbox likelihood function](https://www.pymc.io/projects/examples/en/latest/case_studies/blackbox_external_likelihood_numpy.html), the tutorial on [custom distributions](https://www.pymc.io/projects/examples/en/latest/howto/custom_distribution.html), the tutorial on [wrapping jax functions into PyTensor Ops](https://www.pymc.io/projects/examples/en/latest/case_studies/wrapping_jax_function.html).”_  
from [Likelihood Approximations with Neural Networks in PyMC - PyMC Labs](https://www.pymc-labs.com/blog-posts/likelihood-approximations-through-neural-networks/)

The one you mention @jessegrabowski is among them, but all the links seem to be broken.

Do you have any idea where I should look ?

Thank you !

---

_[View the full topic](https://discourse.pymc.io/t/custom-likelihood-from-a-python-function/11637)._
