MCMC Functions

MCMC code for the gaussian model

class src.magpy_rv.mcmc.MCMC(t, rv, rv_err, hparam0, kernel_name, model_par0, model_name, prior_list, numb_chains=100, flags=None, Mstar=0)[source]

Class to perform the MCMC calculation

Parameters
  • t (array, floats) – Time array of the observations

  • rv (array, floats) – Radial velocity array of the observations

  • rv_err (array, floats) – Errors on the radial velocity array

  • hparam0 (dictionary) – Set of hyper-parameters for the kernel, with value, error and vary

  • kernel_name (string) – Name of chosen kernel

  • model_par0 (dictionary) – Set of parameters for the model, with value, error and vary

  • model_name (string) – Name of chosen model

  • prior_list (list) – List inlcuding in order the name of parameter, the name of the prior and the dictionary of the prior parameters (see posterior function in GP_solar.py for better description)

  • numb_chains (integer, optional) – Number of chains requested. The default is 100.

  • flags (array of floats, optional) – array of flags representing which datapoints in the time array are related to which telescope and so will have which offset. Defaults to false

  • Mstar (float) – mass of the host star in solar masses

compare()[source]

Compares current step with previous step, appends current or previous step to storing array based on the difference in logL

compute()[source]

Computes the current logL and mass

gelman_rubin_calc(burn_in)[source]

Computes the Gelman-Rubin convergence statistic. Must be calculated for each parameter independently.

Parameters

burn_in (int) – length in steps of the chosen burn in phase

Returns

all_R – array of Gelman-Rubin values for each parameter

Return type

array, floats

reset()[source]
Returns

  • logL_list (3D array) – List of the logL of all accepted steps, nrow = n_chains, ncol = 1, ndep = iterations

  • hparameters_list (3D array) – List of the hyperparameters of all accepted steps, nrow = n_chains, ncol = n_parameters, ndep = iterations

  • modelel_paramater_list (3D array) – List of the model parameters of all accepted steps, nrow = n_chains, ncol = n_parameters, ndep = iterations

  • accepted (3D array) – List of True and Falses regarding the acceptance of each MCMC step, nrow = n_chains, ncol = 1, ndep = iterations

split_step(n_splits=2, a=2.0, Rstar=None, Mstar=None)[source]
Parameters
  • n_splits (integer, optional) – Number of subsplits of the total number of chains. The default is 2.

  • a (float, optional) – Adjustable scale parameter. The default is 2.

  • Rstar (float, optional) – Radius of the host star in solar radii. The default is None.

  • Mstar (float, optional) – Mass of the star in solar masses. The default is None.

src.magpy_rv.mcmc.run_MCMC(iterations, t, rv, rv_err, hparam0, kernel_name, model_param0=None, model_name=['no_model'], prior_list=[], numb_chains=None, n_splits=None, a=None, Rstar=None, Mstar=None, flags=None, plot_convergence=False, saving_folder=None, gelman_rubin_limit=1.1)[source]

Function to run the MCMC to obtain posterior distributions for hyperparameters and model parameters

Parameters
  • iterations (int) – number of iterations to run the MCMC for

  • t (array of floats) – array of the time data

  • rv (array of floats) – array of the rv data

  • rv_err (array of floats) – array of the rv errors

  • hparam0 (dictionary) – dictionary of all hyperparameters

  • kernel_name (string) – name of the chosen Kernel

  • model_param0 (dictionary, optional) – dictionary of all model parameters, not required for no model. Defaults to None

  • model_name (list of strings, optional) – list of the names of the chosen models, not required for no model. Defaults to [“no_model”]

  • prior_list (list of dictionaries, optional) – list of prior parameters in the form of dictionaries set up by pri_create, not required for no priors. Defaults to []

  • numb_chains (int) – number of MCMC chains to run, no input will run 100 chains. Defaults to None

  • n_splits (int, optional) – number of subsplits of the total number of chains, no input will use 2 splits. Defaults to None

  • a (float, optional) – adjustable scale parameter, no input will use a=2. Defaults to None

  • Rstar (float, optional) – radius of the host star in solar radii. Defaults to None

  • Mstar (float, optional) – rmass of the star in solar masses. Defaults to None

  • flags (array of floats, optional) – array of flags representing which datapoints in the time array are related to which telescope and so will have which offset. Defaults to false

  • saving_folder (string, optional) – folder location to save outputs to. Defaults to None

  • gelman_rubin_limit (float, optional) – Convergence cut for the Gelman_Rubin statistic. Default is 1.1

Raises
  • KeyError – Raised if a model is in use and no model parameters have been provided

  • Assertion – Raised if the number of chains is less than double the number of free parameters

Returns

  • logL_list (array of floats) – array of the log likelihoods of every iteration

  • hparameter_list (array of floats) – array of the hyperparameters of every iteration

  • model_parameter_list (array of floats) – array of the model parameters of every iteration

  • mass (array of floats) – array of calculated masses from the model for each iteraiton, where the columns represent the different planets

  • completed_iterations (integer) – number of completed iterations