Prasad Ostwal
Prasad Ostwal

Reputation: 377

How to distinguish between priors and likelihood in PyMC3

In PyMC3 examples, priors and likelihood are defined inside with statement, but they are not explicitly defined if they are priors or likelihood. How do I define them?

In following example code, alpha and beta are priors and y_obs is likelihood(As PyMC3 examples states).

My question is: How PyMC3 internal code finds out if distribution is of prior or likelihood? There should be some explicit parameter to tell PyMC3 internals about type of distribution (prior/likelihood).

I know y_obs is likelihood, but I could define more y_obs1 y_obs2. How PyMC3 is going to identify which one is likelihood and which one is prior.

from pymc3 import Model, Normal, HalfNormal

regression_model = Model()  
with regression_model:  

    alpha = Normal('alpha', mu=0, sd=10)
    beta = Normal('beta', mu=0, sd=10, shape=2)

    sigma = HalfNormal('sigma', sd=1)

    mu = alpha + beta[0] * X[:,0] + beta[1] * X[:,1]

    y_obs = Normal('y_obs', mu=mu, sd=sigma, observed=y)

Upvotes: 1

Views: 99

Answers (1)

merv
merv

Reputation: 76720

Passing an observed argument makes it a likelihood term (in your example, P[y|mu, sigma]). The other RandomVariable variables (alpha, beta, and sigma), lacking an observed argument, are sampled as priors.

Upvotes: 2

Related Questions