TheJoker

class thejoker.sampler.TheJoker(params, pool=None, random_state=None, n_batches=None, tempfile_path=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.

tempfile_path : str (optional)

Path to create temporary files needed for executing the sampler. Defaults to whatever tempfile thinks is a good temporary directory.

Methods Summary

iterative_rejection_sample(data, …[, …]) This is an experimental sampling method that adaptively generates posterior samples given a large library of prior samples.
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]

This is an experimental sampling method that adaptively generates posterior samples given a large library of prior samples. The advantage of this function over the standard rejection_sample method is that it will try to adaptively figure out how many prior samples it needs to evaluate the likelihood at in order to return the desired number of posterior samples.

Parameters:
data : RVData

The radial velocity data.

n_requested_samples : int (optional)

The number of posterior samples desired.

prior_cache_file : str

A path to an HDF5 cache file containing prior samples.

n_prior_samples : int (optional)

The maximum number of prior samples to use.

return_logprobs : bool (optional)

Also return the log-probabilities.

magic_fudge : int (optional)

A magic fudge factor to use when adaptively determining the number of prior samples to evaluate at. Larger numbers make the trial batches larger more rapidly.

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.

Returns:
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 data.

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.

Returns:
samples : JokerSamples

Keys: ['P', 'M0', 'e', 'omega'], each as astropy.units.Quantity objects (i.e. with units).