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

The documentation here states that the following should work:

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

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…

Those are outdated (cc @fonnesbeck).

Here is the current way: pymc.logp — PyMC dev documentation

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

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?

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.

More details on RVs/pdfs can be found here: PyMC and PyTensor — PyMC 5.20.0 documentation

And here: rosetta_stone_pymc_stan.ipynb · GitHub

I’ve updated that page.