jwspecmcmc.likelihood
Log-likelihood and log-probability for MCMC sampling.
The likelihood uses the same weighted chi-squared as
jwspecfit.fitter.fit_lines(), ensuring identical statistical
treatment of the data.
Functions
|
Gaussian log-likelihood for free parameters. |
|
Log-posterior = log-prior + log-likelihood. |
Classes
|
Cached data needed for likelihood evaluation. |
- class jwspecmcmc.likelihood.LikelihoodSpec(flam, flam_err, valid, edges, n_lines, constraints, w_pix, n_lya=0, lya_model_fn=None)[source]
Bases:
objectCached data needed for likelihood evaluation.
All arrays are in F_lambda units (erg/s/cm^2/Angstrom).
- Parameters:
flam (np.ndarray) – Continuum-subtracted flux density.
flam_err (np.ndarray) – Flux density errors.
valid (np.ndarray) – Boolean mask of valid pixels.
edges (np.ndarray) – Pixel-edge wavelengths in Angstroms (length
n_pix + 1).n_lines (int) – Number of emission lines.
constraints (ConstraintSet) – Parameter constraints.
w_pix (np.ndarray) – Pixel weights from
jwspecfit.models.pixel_weight().n_lya (int) – Number of extra Lyα parameters appended to the free vector (4 when Lyα is being fit, 0 otherwise).
lya_model_fn (callable or None) – Function
(p_lya,) -> np.ndarraythat evaluates the asymmetric Gaussian Lyα model from a 4-element parameter vector[A_peak, mu, sigma, alpha].
- constraints: ConstraintSet
- jwspecmcmc.likelihood.log_likelihood(p_free, spec)[source]
Gaussian log-likelihood for free parameters.
Mirrors the residual function in
jwspecfit.fitter.fit_lines:-0.5 * sum(((flam - model) / flam_err * w_pix)^2).- Parameters:
p_free (np.ndarray) – Free parameter vector. When Lyα is being fit, the last
spec.n_lyaelements are the Lyα parameters.spec (LikelihoodSpec) – Cached data for evaluation.
- Returns:
Log-likelihood value.
- Return type:
- jwspecmcmc.likelihood.log_probability(p_free, spec, prior_set)[source]
Log-posterior = log-prior + log-likelihood.
- Parameters:
p_free (np.ndarray) – Free parameter vector.
spec (LikelihoodSpec) – Cached data for evaluation.
prior_set (PriorSet) – Prior distributions for free parameters.
- Returns:
Log-posterior value (
-infif outside prior support).- Return type: