# Weibull Adstock Function

**URL:** <https://discourse.pymc.io/t/weibull-adstock-function/13273>\
**Category:** v5\
**Tags:** modeling\
**Created:** [November 12, 2023, 1:42am UTC](https://discourse.pymc.io/t/weibull-adstock-function/13273 "2023-11-12T01:42:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faycal](https://avatars.discourse-cdn.com/v4/letter/f/e19adc/32.png) [@Faycal](https://discourse.pymc.io/u/Faycal)\
**Post date:** [November 12, 2023, 1:42am UTC](https://discourse.pymc.io/t/weibull-adstock-function/13273/1 "2023-11-12T01:42:58Z")

</div>

Hi, I am using PYMC 5, for marketing modeling. One of the steps during the model is to transform the variables using an adstock function. I am trying to use Weibull Probability Density Function (PDF) here:

```python
def weibull_pdf(x, lambda_, k):
    x = np.asarray(x)
    pdf = (k / lambda_) * (x / lambda_)**(k - 1) * np.exp(-((x / lambda_)**k))
    return pdf

```

This function is giving me an error message and I think with aesara there is an issue where this cannot be into the adequate variable type during the process.

```python
import aesara.tensor as at

def weibull_pdf(x, lambda_, k):
    x = at.as_tensor_variable(x)
    pdf = (k / lambda_) * (x / lambda_)**(k - 1) * at.exp(-((x / lambda_)**k))
    return pdf

```

A fake model to test the function:

```python
with pm.Model() as model:
    
    lambda_ = pm.Exponential('lambda_', 1.0)
    k = pm.Exponential('k', 1.0)
    x = np.linspace(0, 5, 100)

    weibull = weibull_pdf(x, lambda_, k)
    y_obs = pm.Normal('y_obs', mu=weibull, sigma=0.1, observed=np.random.normal(weibull, 0.1))

    trace = pm.sample(1000)

```

```auto
NotImplementedError: Cannot convert lambda_ to a tensor variable.

```

PS: Chatgpt cannot help on this…  
Thank you

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [November 12, 2023, 2:27am UTC](https://discourse.pymc.io/t/weibull-adstock-function/13273/2 "2023-11-12T02:27:43Z")

</div>

Welcome!

A couple of things. First, if you are using PyMC v5.x, you should not have aesara installed. Second, you shouldn’t need to convert it to a tensor in your `weibull_pdf()` function. Hopefully that helps. Your function works just fine for me on PyMC 5.8 and 5.9.

---

<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:** [November 12, 2023, 9:16am UTC](https://discourse.pymc.io/t/weibull-adstock-function/13273/3 "2023-11-12T09:16:18Z")

</div>

Converting is fine, if it’s already a TensorVariable nothing will happen. Just chabge your inport to `import pytensor.tensor as pt` and replace every `at` for a `pt`

---

<div class="post-metadata">

**Author:** ![Faycal](https://avatars.discourse-cdn.com/v4/letter/f/e19adc/32.png) [@Faycal](https://discourse.pymc.io/u/Faycal)\
**Post date:** [November 12, 2023, 1:46pm UTC](https://discourse.pymc.io/t/weibull-adstock-function/13273/4 "2023-11-12T13:46:49Z")

</div>

Thank you! you are right, no need for aesara, after removing aesara I just replaced the at.exp by pm.math.exp.
