# Evaluating the logp of a pm.Distribution.dist()

**URL:** <https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471>\
**Category:** General\
**Created:** [January 31, 2025, 7:34pm UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471 "2025-01-31T19:34:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jared](https://discourse.pymc.io/u/Jared)\
**Post date:** [January 31, 2025, 7:34pm UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471/1 "2025-01-31T19:34:49Z")

</div>

The documentation [here](https://www.pymc.io/projects/docs/en/latest/guides/Probability_Distributions.html) states that the following should work:

```auto
import pymc as pm
y = pm.Binomial.dist(n=10, p=0.5)
y.logp(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TensorVariable' object has no attribute 'logp'. Did you mean: 'log'?

```

however as you can see, this throws an error. I need to compute the PDF of a random variable within my model - I was hoping to use something like

```auto
pdf_at_x = pm.math.exp(random_variable.logp(x))

```

can someone please let me know the correct way to do this? The documentation is very sparse…

---

<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:** [January 31, 2025, 9:30pm UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471/2 "2025-01-31T21:30:27Z")

</div>

Those are outdated (cc @fonnesbeck).

Here is the current way: [pymc.logp — PyMC dev documentation](https://www.pymc.io/projects/docs/en/latest/api/generated/pymc.logp.html)

---

<div class="post-metadata">

**Author:** ![Jared](https://avatars.discourse-cdn.com/v4/letter/j/848f3c/32.png) [@Jared](https://discourse.pymc.io/u/Jared)\
**Post date:** [February 1, 2025, 2:17am UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471/3 "2025-02-01T02:17:11Z")

</div>

Thanks! This does work. Since in the example above, `random_variable` is supposed to represent a PDF, could I skip `pm.logp()` and just call something like

```auto
pdf_at_x = pytensor.function([value], random_variable)

```

to get the same effect? To avoid need to exponentiate the logp and get the p directly?

---

<div class="post-metadata">

**Author:** ![jessegrabowski](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jessegrabowski/32/5010_2.png) [@jessegrabowski](https://discourse.pymc.io/u/jessegrabowski)\
**Post date:** [February 1, 2025, 4:08am UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471/4 "2025-02-01T04:08:24Z")

</div>

Random variables aren’t PDFs, they’re random variables. `pytensor.function([], random_variable)` returns draws from that random variable (well not exactly, there’s some missing boilerplate to handle random seeds. Consider `pm.compile` over `pytensor.function` when working with RVs).

Anyway, `value` isn’t an input at all to `random_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:** [February 1, 2025, 8:13am UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471/5 "2025-02-01T08:13:42Z")

</div>

More details on RVs/pdfs can be found here: [PyMC and PyTensor — PyMC 5.20.0 documentation](https://www.pymc.io/projects/docs/en/stable/learn/core_notebooks/pymc_pytensor.html)

And here: [rosetta\_stone\_pymc\_stan.ipynb · GitHub](https://gist.github.com/ricardoV94/c421ddacb3ba7a19ac46efa253ea466c)

---

<div class="post-metadata">

**Author:** ![fonnesbeck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/fonnesbeck/32/13_2.png) [@fonnesbeck](https://discourse.pymc.io/u/fonnesbeck)\
**Post date:** [February 1, 2025, 7:06pm UTC](https://discourse.pymc.io/t/evaluating-the-logp-of-a-pm-distribution-dist/16471/6 "2025-02-01T19:06:52Z")

</div>

I’ve updated that page.
