# The Joker [YO-ker] /’joʊkər/¶

## Introduction¶

The Joker 1 is a custom Monte Carlo sampler for the two-body problem that generates posterior samplings in Keplerian orbital parameters given radial velocity observations of stars. It is designed to deliver converged posterior samplings even when the radial velocity measurements are sparse or very noisy. It is therefore useful for constraining the orbital properties of binary star or star-planet systems. Though it fundamentally assumes that any system has two massive bodies (and only the primary is observed), The Joker can also be used for hierarchical systems in which the velocity perturbations from a third or other bodies are much longer than the dominant companion. See the paper 2 for more details about the method and applications.

## Getting started¶

Generating samples with The Joker requires three things:

1. The data, RVData: radial velocity measurements, uncertainties, and observation times

2. The priors, JokerPrior: the prior distributions over the parameters in The Joker

3. The sampler, TheJoker: the work horse that runs the rejection sampler

Here, we’ll work through a simple example to generate poserior samples for orbital parameters given some sparse, simulated radial velocity data (shown below). We’ll first use these plain arrays to construct a RVData object:

>>> import astropy.units as u
>>> import thejoker as tj
>>> t = [0., 49.452, 95.393, 127.587, 190.408]
>>> rv = [38.77, 39.70, 37.45, 38.31, 38.31] * u.km/u.s
>>> err = [0.184, 0.261, 0.112, 0.155, 0.223] * u.km/u.s
>>> data = tj.RVData(t=t, rv=rv, rv_err=err)
>>> ax = data.plot()
>>> ax.set_xlim(-10, 200)


We next need to specify the prior distributions for the parameters of The Joker. The default prior, explained in the docstring of default(), assumes some reasonable defaults where possible, but requires specifying the minimum and maximum period to sample over, along with parameters that specify the prior over the linear parameters in The Joker (the velocity semi-amplitude, K, and the systemic velocity, v0):

>>> import numpy as np
>>> prior = tj.JokerPrior.default(P_min=2*u.day, P_max=256*u.day,
...                               sigma_K0=30*u.km/u.s,
...                               sigma_v=100*u.km/u.s)


With the data and prior created, we can now instantiate the sampler object and run the rejection sampler:

>>> joker = tj.TheJoker(prior)
>>> prior_samples = prior.sample(size=100_000)
>>> samples = joker.rejection_sample(data, prior_samples)


Of the 100_000 prior samples we generated, only a handful pass the rejection sampling step of The Joker. Let’s visualize the surviving samples in the subspace of the period $$P$$ and velocity semi-amplitude $$K$$. We’ll also plot the true values as a green marker. As a separate plot, we’ll also visualize orbits computed from these posterior samples (check the source code below to see how these were made):

(png)

(png)

## API¶

### thejoker Package¶

#### Functions¶

 plot_rv_curves(samples[, t_grid, rv_unit, …]) Plot radial velocity curves for the input set of orbital parameter samples over the input grid of times.

#### Classes¶

 TheJoker(prior[, pool, random_state, …]) A custom Monte-Carlo sampler for two-body systems. RVData(t, rv, rv_err[, t0, clean]) Time-domain radial velocity measurements for a single target. JokerSamples([samples, t0, n_offsets, …]) A dictionary-like object for storing prior or posterior samples from The Joker, with some extra functionality. JokerPrior([pars, poly_trend, v0_offsets, model]) This class controls the prior probability distributions for the parameters used in The Joker.

Footnotes

1

Short for Johannes Kepler.

2

https://arxiv.org/abs/1610.07602