Jed Rembold
April 16, 2024
Defining the prior pdf is usually straightforward
If using an unbounded, flat, prior, then it should just return 1 always (0 in ln-space)
If bounded, check the parameters and return 1 (0 in ln-space) if
within the bounds or \(-\infty\)
otherwise (-np.inf
in Python,
-Inf
in R)
Pseudo-example:
|||function ln_prior(|||params|||)|||
if |||illegal condition|||
return -|||infinity|||
return 0
The ln-likelihood then could look like:
|||function ln_likelihood(|||params, data|||)|||
m,b = params
x,y,errY = data # extract data
y_model = m * x + b # compute model result
return - 0.5 * |||sum(|||
(y - y_model) ** 2 / errY ** 2
|||)|||
Bring both pieces together (since we don’t care about \(P(D)\)):
|||function ln_pdf(|||params, data|||)|||
p = |||call ln_prior|||
if p == -|||infinity||| # no sense continuing
return -|||infinity|||
return p + ln_likelihood(params, data)
Suppose we want to evaluate the uncertainties in our parameters for a fit to the data to the right.
Our model will look something like: \[y = ax^2 + bx\]
MCMC does not tell you about the quality of a fit. It tells you about the variability in the fit parameters.
axis=0