ACID_code.MCMC

class ACID_code.MCMC(x_or_data: Array1D | Array2D | Data, y: Array1D | None = None, yerr: Array1D | None = None, alpha: Array2D | None = None, velocities: Array1D | None = None, c_factor=None, deterministic_profile: bool = False, sampler_type: str = 'emcee', model_inputs: Array1D | None = None, od: bool = True)[source]

Class for handling the MCMC fitting process. Since this is the most computationally intensive part of the code, it is designed to be as efficient as possible. Hence, no beartype checks are performed except in initialization, and we have tried to precomputed as many variables as possible to avoid as much recalculation during sampling as possible.

Initialise MCMC functions with necessary data. Called once per worker if using multiprocessing.

Parameters:
  • x_or_data (Array1D | Array2D | Data) – Wavelength array or Data instance. If a Data instance is provided, takes all the arguments below from there. If a Data instance is provided, all other arguments are ignored.

  • y (Array1D, optional) – Observed flux array, required if x_or_data is a Array1D or Array2D.

  • yerr (Array1D, optional) – Observed flux error array, required if x_or_data is a Array1D or Array2D.

  • alpha (Array2D, optional) – Precomputed alpha matrix, required if x_or_data is a Array1D or Array2D.

  • velocities (Array1D | None, optional) – Velocity grid for LSD profile, only needed when calling log-probability function, by default None.

  • c_factor (tuple, optional) – Precomputed c_factor for LSD profile calculation, by default None.

  • deterministic_profile (bool, optional) – Whether to fit the full profile (True) or use the fast model (False), by default True.

model_function

The model function can be called to directly run the model based on the deterministic_profile flag from initialization

full_model(theta)[source]

Full model for mcmc - takes all inputs (profile points + continuum coefficents) to create a model spectrum.

Parameters:

theta (np.ndarray) – Model parameters: first k_max values are profile points (z), followed by continuum polynomial coefficients and scale factor.

Returns:

Model spectrum and profile points (z).

Return type:

tuple

deterministic_model(theta)[source]

Deterministic model for mcmc - takes only continuum coefficents and scale factor to create a model spectrum, solving for the profile points (z) directly.

Parameters:

theta (array-like) – Model parameters: continuum polynomial coefficients followed by scale factor.

Returns:

Model spectrum and profile points (z).

Return type:

tuple

log_prior(z)[source]

Calculates the log prior probability of the profile points (z) and imposes the prior restrictions on the inputs - rejects if profile point is less than -0.4 or greater than 1.6.

Parameters:

z (array-like) – Profile points.

Returns:

Log prior probability.

Return type:

float

log_probability(theta)[source]

Calculates log probability depending on which model (full or fast).

Parameters:

theta (array-like) – Model parameters.

Returns:

Log probability.

Return type:

float

dynesty_logprob(theta)[source]

Log likelihood function for dynesty nested sampling.

ptform(u)[source]

Prior transform for dynesty.

Maps unit-cube samples u in [0, 1] to continuum polynomial coefficients using uniform priors centred on self.model_inputs.