Sampler¶

class
orbitize.sampler.
MCMC
(system, num_temps=20, num_walkers=1000, num_threads=1, like='chi2_lnlike', custom_lnlike=None)[source]¶ MCMC sampler. Supports either parallel tempering or just regular MCMC. Parallel tempering will be run if
num_temps
> 1 ParallelTempered MCMC Sampler uses ptemcee, a fork of the emcee Affineinfariant sampler AffineInvariant Ensemble MCMC Sampler uses emcee.Warning
may not work well for multimodal distributions
 Parameters
system (system.System) – system.System object
num_temps (int) – number of temperatures to run the sampler at. Parallel tempering will be used if num_temps > 1 (default=20)
num_walkers (int) – number of walkers at each temperature (default=1000)
num_threads (int) – number of threads to use for parallelization (default=1)
like (str) – name of likelihood function in
lnlike.py
custom_lnlike (func) – ability to include an addition custom likelihood function in the fit. the function looks like
clnlikes = custon_lnlike(params)
whereparams is a RxM array of fitting parameters, where R is the number of orbital paramters (can be passed in system.compute_model()), and M is the number of orbits we need model predictions for. It returns ``clnlikes
which is an array of length M, or it can be a single float if M = 1.
Written: Jason Wang, Henry Ngo, 2018

chop_chains
(burn, trim=0)[source]¶ Permanently removes steps from beginning (and/or end) of chains from the Results object. Also updates curr_pos if steps are removed from the end of the chain
 Parameters
burn (int) – The number of steps to remove from the beginning of the chains
trim (int) – The number of steps to remove from the end of the chians (optional)
 Returns
None. Updates self.curr_pos and the Results object. .. Warning:: Does not update bookkeeping arrays within MCMC sampler object.
(written): Henry Ngo, 2019

examine_chains
(param_list=None, walker_list=None, n_walkers=None, step_range=None)[source]¶ Plots position of walkers at each step from Results object. Returns list of figures, one per parameter :param param_list: List of strings of parameters to plot (e.g. “sma1”)
If None (default), all parameters are plotted
 Parameters
walker_list – List or array of walker numbers to plot If None (default), all walkers are plotted
n_walkers (int) – Randomly select n_walkers to plot Overrides walker_list if this is set If None (default), walkers selected as per walker_list
step_range (array or tuple) – Start and end values of step numbers to plot If None (default), all the steps are plotted
 Returns
Walker position plot for each parameter selected
 Return type
List of
matplotlib.pyplot.Figure
objects
(written): Henry Ngo, 2019

run_sampler
(total_orbits, burn_steps=0, thin=1, examine_chains=False)[source]¶ Runs PT MCMC sampler. Results are stored in
self.chain
andself.lnlikes
. Results also added toorbitize.results.Results
object (self.results
)Note
Can be run multiple times if you want to pause and inspect things. Each call will continue from the end state of the last execution.
 Parameters
total_orbits (int) – total number of accepted possible orbits that are desired. This equals
num_steps_per_walker
xnum_walkers
burn_steps (int) – optional paramter to tell sampler to discard certain number of steps at the beginning
thin (int) – factor to thin the steps of each walker by to remove correlations in the walker steps
examine_chains (boolean) – Displays plots of walkers at each step by running examine_chains after total_orbits sampled.
 Returns
the sampler used to run the MCMC
 Return type
emcee.sampler
object

class
orbitize.sampler.
OFTI
(system, like='chi2_lnlike', custom_lnlike=None)[source]¶ OFTI Sampler
 Parameters
like (string) – name of likelihood function in
lnlike.py
system (system.System) –
system.System
objectcustom_lnlike (func) – ability to include an addition custom likelihood function in the fit. the function looks like
clnlikes = custon_lnlike(params)
whereparams is a RxM array of fitting parameters, where R is the number of orbital paramters (can be passed in system.compute_model()), and M is the number of orbits we need model predictions for. It returns ``clnlikes
which is an array of length M, or it can be a single float if M = 1.
Written: Isabel Angelo, Sarah Blunt, Logan Pearce, 2018

prepare_samples
(num_samples)[source]¶ Prepare some orbits for rejection sampling. This draws random orbits from priors, and performs scale & rotate.
 Parameters
num_samples (int) – number of orbits to draw and scale & rotate for OFTI to run rejection sampling on
 Returns
array of prepared samples. The first dimension has size of num_samples. This should be passed into
OFTI.reject()
 Return type
np.array

reject
(samples)[source]¶ Runs rejection sampling on some prepared samples.
 Parameters
samples (np.array) – array of prepared samples. The first dimension has size
num_samples
. This should be the output ofprepare_samples()
. Returns
np.array: a subset of
samples
that are accepted based on the data.np.array: the log likelihood values of the accepted orbits.
 Return type
tuple

run_sampler
(total_orbits, num_samples=10000, num_cores=None)[source]¶ Runs OFTI in parallel on multiple cores until we get the number of total accepted orbits we want. :param total_orbits: total number of accepted orbits desired by user :type total_orbits: int :param num_samples: number of orbits to prepare for OFTI to run
rejection sampling on. Defaults to 10000.
 Parameters
num_cores (int) – the number of cores to run OFTI on. Defaults to number of cores availabe.
 Returns
array of accepted orbits. Size: total_orbits.
 Return type
output_orbits (np.array)
Written by: Vighnesh Nagpal(2019)