TheJoker

class thejoker.TheJoker(prior, pool=None, random_state=None, tempfile_path=None)[source]

Bases: object

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

Parameters
priorJokerPrior

The specification of the prior probability distribution over all parameters used in The Joker.

poolschwimmbad.BasePool (optional)

A processing pool (default is a schwimmbad.SerialPool instance).

random_statenumpy.random.RandomState (optional)

A numpy.random.RandomState instance for controlling random number generation.

tempfile_pathstr (optional)

A location on disk where The Joker may store some temporary files. Any files written here by The Joker should be cleaned up: If any files in this path persist, something must have gone wrong within The Joker. Default: ~/.thejoker

Attributes Summary

tempfile_path

Methods Summary

iterative_rejection_sample(self, data, …)

This is an experimental sampling method that adaptively generates posterior samples given a large library of prior samples.

marginal_ln_likelihood(self, data, prior_samples)

rejection_sample(self, data, prior_samples)

setup_mcmc(self, data, joker_samples[, …])

Setup the model to run MCMC using pymc3.

trace_to_samples(self, trace, data[, names])

Create a JokerSamples instance from a pymc3 trace object.

Attributes Documentation

tempfile_path

Methods Documentation

iterative_rejection_sample(self, data, prior_samples, n_requested_samples, max_prior_samples=None, n_linear_samples=1, return_logprobs=False, n_batches=None, randomize_prior_order=False, init_batch_size=None, growth_factor=128, in_memory=False)[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
dataRVData

The radial velocity data, or an iterable containing RVData objects for each data source.

prior_samplesstr, JokerSamples

Either a path to a file containing prior samples generated from The Joker, or a JokerSamples instance containing the prior samples.

n_requested_samplesint (optional)

The number of posterior samples desired.

max_prior_samplesint (optional)

The maximum number of prior samples to process.

n_linear_samplesint (optional)

The number of linear parameter samples to generate for each nonlinear parameter sample returned from the rejection sampling step.

return_logprobsbool (optional)

Also return the log-prior and (marginal) log-likelihood values evaluated at each sample.

n_batchesint (optional)

The number of batches to split the prior samples into before distributing for computation. If using the (default) serial computation pool, this doesn’t have any impact. If using multiprocessing or MPI, this determines how many batches to split the samples into before scattering over all workers.

randomize_prior_orderbool (optional)

Randomly shuffle the prior samples before reading and running the rejection sampler. This is only useful if you are using a large library of prior samples, and choosing to run on a subset of those samples.

init_batch_sizeint (optional)

The initial batch size of likelihoods to compute, before growing the batches using the multiplicative growth factor, below.

growth_factorint (optional)

A factor used to adaptively grow the number of prior samples to evaluate on. Larger numbers make the trial batches grow faster.

in_memorybool (optional)

Load all prior samples or keep all prior samples in memory and run all calculations without creating a temporary cache file.

Returns
samplesJokerSamples

The posterior samples produced from The Joker.

marginal_ln_likelihood(self, data, prior_samples, n_batches=None, in_memory=False)[source]
rejection_sample(self, data, prior_samples, n_prior_samples=None, max_posterior_samples=None, n_linear_samples=1, return_logprobs=False, n_batches=None, randomize_prior_order=False, in_memory=False)[source]
setup_mcmc(self, data, joker_samples, model=None, use_cached=False)[source]

Setup the model to run MCMC using pymc3.

Parameters
dataRVData

The radial velocity data, or an iterable containing RVData objects for each data source.

joker_samplesJokerSamples

If a single sample is passed in, this is packed into a pymc3 initialization dictionary and returned after setting up. If multiple samples are passed in, the median (along period) sample is taken and returned after setting up for MCMC.

modelpymc3.Model

This is either required, or this function must be called within a pymc3 model context.

Returns
mcmc_initdict
trace_to_samples(self, trace, data, names=None)[source]

Create a JokerSamples instance from a pymc3 trace object.

Parameters
traceMultiTrace