jwspecmcmc.priors

Prior distributions for MCMC sampling.

Provides prior classes that can be composed into a PriorSet for use with the MCMC samplers. Default priors are uniform within the parameter bounds from jwspecfit.fitter._grating_bounds().

Functions

priors_from_bounds(lb_free, ub_free[, overrides])

Build a PriorSet from parameter bounds.

Classes

GaussianPrior(mean, std[, lo, hi])

Truncated Gaussian prior.

LogUniformPrior(lo, hi)

Log-uniform (Jeffreys) prior on [lo, hi] with lo > 0.

Prior()

Abstract base class for a 1-D prior distribution.

PriorSet([priors])

Collection of priors indexed by free-parameter position.

UniformPrior(lo, hi)

Uniform (flat) prior on [lo, hi].

class jwspecmcmc.priors.GaussianPrior(mean, std, lo=-inf, hi=inf)[source]

Bases: Prior

Truncated Gaussian prior.

Parameters:
  • mean (float) – Mean of the Gaussian.

  • std (float) – Standard deviation.

  • lo (float) – Hard lower bound (-inf for unbounded).

  • hi (float) – Hard upper bound (+inf for unbounded).

hi: float = inf
lo: float = -inf
log_prob(x)[source]

Return the log-probability at x.

Parameters:

x (float) – Parameter value.

Returns:

Log-probability (-inf if outside support).

Return type:

float

mean: float
sample(rng, size=1)[source]

Draw random samples from the prior.

Parameters:
Returns:

Samples of shape (size,).

Return type:

np.ndarray

std: float
class jwspecmcmc.priors.LogUniformPrior(lo, hi)[source]

Bases: Prior

Log-uniform (Jeffreys) prior on [lo, hi] with lo > 0.

Parameters:
  • lo (float) – Lower bound (must be positive).

  • hi (float) – Upper bound.

hi: float
lo: float
log_prob(x)[source]

Return the log-probability at x.

Parameters:

x (float) – Parameter value.

Returns:

Log-probability (-inf if outside support).

Return type:

float

sample(rng, size=1)[source]

Draw random samples from the prior.

Parameters:
Returns:

Samples of shape (size,).

Return type:

np.ndarray

class jwspecmcmc.priors.Prior[source]

Bases: ABC

Abstract base class for a 1-D prior distribution.

abstractmethod log_prob(x)[source]

Return the log-probability at x.

Parameters:

x (float) – Parameter value.

Returns:

Log-probability (-inf if outside support).

Return type:

float

abstractmethod sample(rng, size=1)[source]

Draw random samples from the prior.

Parameters:
Returns:

Samples of shape (size,).

Return type:

np.ndarray

class jwspecmcmc.priors.PriorSet(priors=<factory>)[source]

Bases: object

Collection of priors indexed by free-parameter position.

Parameters:

priors (list of Prior) – One prior per free parameter.

log_prior(p_free)[source]

Evaluate the total log-prior for a free-parameter vector.

Parameters:

p_free (np.ndarray) – Free parameter values (length n_dim).

Returns:

Sum of individual log-priors (-inf if any parameter is outside its support).

Return type:

float

property n_dim: int

Number of free parameters.

priors: list[Prior]
sample(rng)[source]

Draw one sample from the joint prior.

Parameters:

rng (numpy.random.Generator) – Random number generator.

Returns:

Sample of shape (n_dim,).

Return type:

np.ndarray

class jwspecmcmc.priors.UniformPrior(lo, hi)[source]

Bases: Prior

Uniform (flat) prior on [lo, hi].

Parameters:
  • lo (float) – Lower bound.

  • hi (float) – Upper bound.

hi: float
lo: float
log_prob(x)[source]

Return the log-probability at x.

Parameters:

x (float) – Parameter value.

Returns:

Log-probability (-inf if outside support).

Return type:

float

sample(rng, size=1)[source]

Draw random samples from the prior.

Parameters:
Returns:

Samples of shape (size,).

Return type:

np.ndarray

jwspecmcmc.priors.priors_from_bounds(lb_free, ub_free, overrides=None)[source]

Build a PriorSet from parameter bounds.

Parameters:
  • lb_free (np.ndarray) – Lower bounds for free parameters.

  • ub_free (np.ndarray) – Upper bounds for free parameters.

  • overrides (dict mapping int to Prior, optional) – Per-index prior overrides.

Return type:

PriorSet