rxn_ord

ckbit.rxn_ord

ckbit.rxn_ord.MAP(filename, model_name='rxn_ord', priors=None, verbose=True, init_random=False, seed=None, int_init=10, rxn_ord_init=0, sigma_init=1)

MAP estimation for reaction order estimation

Parameters
  • filename (str) – Filename of Excel input file that contains the appropriately formated reaction order data (see examples)

  • model_name (str, optional) – Name of model, used for saving/loading compilied Stan code, Default is ‘rxn_ord’

  • priors (list of str, optional) – User defined prior distributions, Must have appropriate format (see examples), Default is None

  • verbose (bool, optional) – Flag to signal whether Stan intermediate output should be piped to terminal, Default is True

  • trace (bool, optional) – Flag to signal whether traceplots should be generated upon the run’s completion, Default is True

  • init_random (bool, optional) – Flag to signal whether the initialization should be random or if it should use user specified values, Default is False

  • seed (int, optional) – A positive integer used to seed the random number generation, Default is np.random.randint(0, 1E9)

  • int_init (float, optional) – Initialization point for the sampler for intercept, Default is 10

  • rxn_ord_init (float, optional) – Initialization point for the sampler for rxn order, Default is 0

  • sigma_init (float, optional) – Initialization point for the sampler for sigma, Default is 1

Returns

point_estimates – Dictionary containing values corresponding to modes of posterior

Return type

dict

ckbit.rxn_ord.MCMC(filename, model_name='rxn_ord', priors=None, warmup=None, iters=5000, chains=2, n_jobs=1, verbose=True, seed=None, trace=True, init_random=False, control={'adapt_delta': 0.9999, 'max_treedepth': 100}, int_init=10, rxn_ord_init=0, sigma_init=1)

Bayesian inference using MCMC sampling for reaction order estimation

Parameters
  • filename (str) – Filename of Excel input file that contains the appropriately formated reaction order data (see examples)

  • model_name (str, optional) – Name of model, used for saving/loading compilied Stan code, Default is ‘rxn_ord’

  • priors (list of str, optional) – User defined prior distributions, Must have appropriate format (see examples), Default is None

  • warmup (int, optional) – Number of warmup iterations for MCMC sampler, Must be less than the number of total iterations, Default is None, which sets warmup equal to half of iters (the Stan default)

  • iters (int, optional) – Number of total interations for MCMC sampler for each chain, Must be greater than the warmup, total number of samples useable for MCMC inference will equal (chains*(iters-warmup)), Default is 5000

  • chains (int, optional) – Number of chains for MCMC sampler, Default is 2

  • n_jobs (int, optional) – Number of jobs to run in parallel for MCMC sampler, maximum is number of cores the computer has, Default is 1

  • verbose (bool, optional) – Flag to signal whether Stan intermediate output should be piped to terminal, Default is True

  • seed (int, optional) – A positive integer used to seed the random number generation, use one seed even when multiple chains are used since the other chain’s seeds are generated from the first chain’s to avoid dependency among random number streams, set this seed for repeatable inference sampling runs, Default is np.random.randint(0, 1E9)

  • trace (bool, optional) – Flag to signal whether traceplots should be generated upon the run’s completion, Default is True

  • init_random (bool, optional) – Flag to signal whether the initialization should be random or if it should use user specified values, Default is False

  • control (dict, optional) – Dictionary of settings for MCMC sampler, Default is {‘adapt_delta’:0.9999, ‘max_treedepth’:100}, more information at: https://mc-stan.org/docs/2_23/reference-manual/hmc-algorithm-parameters.html

  • int_init (float, optional) – Initialization point for the sampler for intercept, Default is 10

  • rxn_ord_init (float, optional) – Initialization point for the sampler for rxn order, Default is 0

  • sigma_init (float, optional) – Initialization point for the sampler for sigma, Default is 1

Returns

  • fit (Stan object) – Stan object containing results of the MCMC run

  • sample_vals (dict) – Dictionary of values collected by the MCMC sampler

ckbit.rxn_ord.StanModel_cache(model_code, model_name, **kwargs)

Function for saving/loading compiled Stan code to avoid recompilation

Parameters
  • model_code (str) – Stan code written in proper format

  • model_name (str, optional) – Name of model, used for saving/loading compilied Stan code

Returns

sm – Stan object from pystan function StanModel

Return type

Stan model

ckbit.rxn_ord.VI(filename, model_name='rxn_ord', priors=None, iters=2000000, algorithm='fullrank', verbose=True, seed=None, sample_file='./samples.csv', diagnostic_file='./diagnostics.csv', grad_samples=1, elbo_samples=100, tol_rel_obj=0.01, adapt_iter=50, eval_elbo=100, output_samples=10000, eta=0.2, adapt_engaged=False, trace=True, init_random=False, int_init=10, rxn_ord_init=0, sigma_init=1)

Bayesian inference using VI for reaction order estimation

Parameters
  • filename (str) – Filename of Excel input file that contains the appropriately formated reaction order data (see examples)

  • model_name (str, optional) – Name of model, used for saving/loading compilied Stan code, Default is ‘rxn_ord’

  • priors (list of str, optional) – User defined prior distributions, Must have appropriate format (see examples), Default is None

  • iters (int, optional) – Maximum number of iterations of the variational density to achieve minimizing the ELBO before the VI algorithm terminates, Default is 2,000,000

  • algorithm (str, optional) – Algorithm to use for VI, either ‘meanfield’ (for uncorrelated posteriors) or ‘fullrank’ (for correlated posteriors), Default is ‘fullrank’

  • verbose (bool, optional) – Flag to signal whether Stan intermediate output should be piped to terminal, Default is True

  • seed (int, optional) – A positive integer used to seed the random number generation, Default is np.random.randint(0, 1E9)

  • sample_file (str, optional) – Filename where the VI samples are saved to, Default is ‘./samples. csv’

  • diagnostic_file (str, optional) – Filename where the VI diagonstics are saved to, Default is ‘./ diagnostics.csv’

  • grad_samples (int, optional) – Number of gradient evaluations to make to estimate gradient for VI solver, Default is 1

  • elbo_samples (int, optional) – Number of elbo evaluations to make to estimate ELBO for VI solver, Default is 100

  • tol_rel_obj (float, optional) – Relative tolerance convergence criteria for median and mean of the change in the ELBO for VI solver, Default is 0.01

  • adapt_iter (int, optional) – Number of iterations for adaptive tuning of eta, Default is 50

  • eval_elbo (int, optional) – Number of iterations between ELBO evaluations for VI solver, Default is 100

  • output_samples (int, optional) – Number of samples to draw from final approximation of posterior from VI solver, Default is 10,000

  • eta (float, optional) – Positive, stepsize weighing parameter for VI solver, Ignored if adapt_iter is True, Default is 0.2

  • adapt_engaged – Flag to signal whether eta should be automatically tuned, Default is False

  • trace (bool, optional) – Flag to signal whether traceplots should be generated upon the run’s completion, Default is True

  • int_init (float, optional) – Initialization point for the sampler for intercept, Default is 10

  • rxn_ord_init (float, optional) – Initialization point for the sampler for rxn_ord, Default is 0

  • sigma_init (float, optional) – Initialization point for the sampler for sigma, Default is 1

  • init_random (bool, optional) – Flag to signal whether the initialization should be random or if it should use user specified values, Default is False

Returns

  • fit (Stan object) – Stan object containing results of the VI run

  • sample_vals (dict) – Dictionary of values collected by the VI sampler

ckbit.rxn_ord.rxn_ord_exp_data(filename)

Processes Excel file with reaction order data

Parameters

filename (str) – Filename of Excel input file that contains the appropriately formated reaction order data (see examples)

Returns

rxn_ord_data – Dictionary containing reaction order data inputs for Stan code

Return type

dict

ckbit.rxn_ord.write_rxn_ord_stan_code(priors=None)

Writes Stan code used for reaction order estimation

Parameters

priors (list of str, optional) – User defined prior distributions, Must have appropriate format (see examples) in accordance with Stan, Default is None

Returns

code_rxn_ord – Code written in Stan syntax used for reaction order estimation

Return type

str