# Input parameter distribution of an open-source modelling code using pymc

**URL:** <https://discourse.pymc.io/t/input-parameter-distribution-of-an-open-source-modelling-code-using-pymc/10304>\
**Category:** Questions\
**Created:** [September 3, 2022, 11:03pm UTC](https://discourse.pymc.io/t/input-parameter-distribution-of-an-open-source-modelling-code-using-pymc/10304 "2022-09-03T23:03:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amita](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/amita/32/4738_2.png) [@Amita](https://discourse.pymc.io/u/Amita)\
**Post date:** [September 3, 2022, 11:03pm UTC](https://discourse.pymc.io/t/input-parameter-distribution-of-an-open-source-modelling-code-using-pymc/10304/1 "2022-09-03T23:03:18Z")

</div>

Hi,

I want to estimate the probability distribution of the parameters for a spectral modelling code. The parameters goes as input to the spectral modelling code via a dictionary.

The code will look something like this:

```auto
# run_spec is the spectra modelling function, which returns the model spectrum1D object
import run_spec
import yaml
import pymc as pm

with pm.Model() as spec_model:
   # setting abundance distribution of the species O, Mg and Ne, 
   # the sum should be 1                      
    O = pm.Uniform("O", 
                   lower = 0., 
                   upper = 1.
                  )
    Mg = pm.Uniform("Mg", 
                    lower = 0., 
                    upper = 1.0-O
                   )
    Ne = pm.Deterministic('Ne', 1.0 - (Mg + O))

    #### par_list is a dictionary that contains all the model parameters
    par_list['model']['abundances']['O'] = O
    par_list['model']['abundances']['Mg'] = Mg
    par_list['model']['abundances']['Ne'] = Ne

    spec_01 = run_spec(par_list)

    mu = spec_01.flux

    y = pm.Normal("obs", mu, obs=flux)
    
    idata = pm.sample(tune=100,
            draws=100,
            cores=4,
            chains=2,
            random_seed=SEED, 
            target_accept=0.99,
            return_inferencedata=True
                     )

```

My primary concern is that if such kind of operation can be carried out in pymc. I am getting this obvoius error that the spectral modelling code was expecting a float argument but got a tensor variable.

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [September 4, 2022, 6:55am UTC](https://discourse.pymc.io/t/input-parameter-distribution-of-an-open-source-modelling-code-using-pymc/10304/2 "2022-09-04T06:55:27Z")

</div>

You will need to wrap your function in a Aesara Op and provide gradients if possible. Some examples here:

> **[Using a “black box” likelihood function (numpy)](https://www.pymc.io/projects/examples/en/latest/case_studies/blackbox_external_likelihood_numpy.html#blackbox_external_likelihood_numpy)**
>
> Introduction: PyMC is a great tool for doing Bayesian inference and parameter estimation. It has a load of in-built probability distributions that you can use to set up priors and likelihood functi...

> **[How to wrap a JAX function for use in PyMC](https://www.pymc.io/projects/examples/en/latest/case_studies/wrapping_jax_function.html)**
>
> Extra dependencies install instructions In order to run this notebook (either locally or on binder) you won’t only need a working PyMC installation with all optional dependencies, but also to insta...
