# TheJoker¶

class thejoker.sampler.TheJoker(params, pool=None, random_state=None, n_batches=None)[source]

Bases: object

A custom Monte-Carlo sampler for two-body systems.

Parameters: params : JokerParams Object specifying hyper-parameters for The Joker. pool : schwimmbad.BasePool (optional) A processing pool (default is a schwimmbad.SerialPool instance). random_state : numpy.random.RandomState (optional) A RandomState instance to serve as a parent for the random number generators. See the random numbers page for more information. n_batches : int (optional) When using multiprocessing to split the likelihood evaluations, this sets the number of batches to split the work into. Defaults to pool.size, meaning equal work to each worker. For very large prior sample caches, you may need to set this to a larger number (e.g., 100*pool.size) to avoid memory issues.

Methods Summary

 iterative_rejection_sample(data, …[, …]) TODO: docstring For now: prior_cache_file is required mcmc_sample(data, samples0[, n_steps, …]) Run standard MCMC (using emcee) to generate posterior samples in orbital parameters. rejection_sample(data[, n_prior_samples, …]) Run The Joker’s rejection sampling on prior samples to get posterior samples for the input data. sample_prior([size, return_logprobs]) Generate samples from the prior.

Methods Documentation

iterative_rejection_sample(data, n_requested_samples, prior_cache_file=None, n_prior_samples=None, return_logprobs=False, magic_fudge=128)[source]

TODO: docstring For now: prior_cache_file is required

Parameters: data : RVData n_requested_samples : int prior_cache_file : str n_prior_samples : int (optional) return_logprobs : bool (optional) magic_fudge : int (optional)
mcmc_sample(data, samples0, n_steps=1024, n_walkers=256, n_burn=8192, return_sampler=False, ball_scale=1e-05)[source]

Run standard MCMC (using emcee) to generate posterior samples in orbital parameters.

Parameters: data : RVData The data to fit orbits to. samples0 : JokerSamples This can either be (a) a single sample to use as initial conditions for the MCMC walkers, or (b) a set of samples, in which case the mean of the samples will be used as initial conditions. n_steps : int The number of MCMC steps to run for. n_walkers : int (optional) The number of walkers to use in the emcee ensemble. n_burn : int (optional) If specified, the number of steps to burn in for. return_sampler : bool (optional) Also return the sampler object. model : TheJokerMCMCModel samples : JokerSamples The posterior samples. sampler : emcee.EnsembleSampler If return_sampler == True.
rejection_sample(data, n_prior_samples=None, prior_cache_file=None, return_logprobs=False, start_idx=0)[source]

Run The Joker’s rejection sampling on prior samples to get posterior samples for the input data.

You must either specify the number of prior samples to generate and use for rejection sampling, n_prior_samples, or the path to a file containing prior samples, prior_cache_file.

Parameters: data : RVData The radial velocity. n_prior_samples : int (optional) If prior_cache_file is not specified, this sets the number of prior samples to generate and use to do the rejection sampling. If prior_cache_file is specified, this sets the number of prior samples to load from the cache file. prior_cache_file : str (optional) A path to an HDF5 cache file containing prior samples. TODO: more information return_logprobs : bool (optional) Also return the log-probabilities. start_idx : int (optional) Index to start reading from in the prior cache file.
sample_prior(size=1, return_logprobs=False)[source]

Generate samples from the prior. Logarithmic in period, uniform in phase and argument of pericenter, Beta distribution in eccentricity.

Parameters: size : int Number of samples to generate. return_logprobs : bool (optional) If True, will also return the log-value of the prior at each sample. samples : JokerSamples Keys: ['P', 'M0', 'e', 'omega'], each as astropy.units.Quantity objects (i.e. with units).