Priors

All parameters to your model must have a prior defined. You may provide any continuous, univariate distribution from the Distributions.jl. A few useful distributions include:

  • Normal
  • Uniform
  • LogNormal
  • LogUniform
  • TrucatedNormal
  • VonMises

This pacakge also defines the Sine() distribution for e.g. inclination priors and UniformCircular() for periodic variables. Internally, UniformCircular() creates two standard normal variables and finds the angle between them using arctan. This allows the sampler to smoothly cycle past the ends of the domain. You can specify a different circular domain than (0,2pi) by passing the size of the domain e.g. τ = UniformCircular(1.0).

The VonMise distribution is notable but not commonly used. It is the analog of a normal distribution defined on a circular domain (-π, +π). If you have a Gaussian prior on an angular parameter, a Von Mises distribution is probably more appropriate.

Behind the scenes, Octofitter remaps your parameters to unconstrained domains using the Bijectors.jl (and corrects the priors accordingly). This is essential for good sampling efficiency with HMC based samplers.

This means that e.g. if you define the eccentricity prior as e=Uniform(0,0.5), the sampler will actually generate values across the whole real line and transform them back into the [0,0.5] range before evaluating the orbit. It is therefore essential that your priors do not include invalid domains.

For example, setting a=Normal(3,2) will result in poor sampling efficiency as sometimes negative values for semi-major axis will be drawn (especially if you're using the parallel tempered sampler).

Instead, for parameters like semi-major axis, eccentricity, parallax, and masses, you should truncate any distributions that have negative tails. This can easily be accomplished with TrauncatedNormal or Trunacted(dist, low, high) for any arbitrary distribution.

Kernel Density Estimate Priors

Octofitter has support for sampling from smoothed kernel density estimate priors. These are non-parametric distributions fit to a 1D dataset consisting of random draws. This is one way to include the output of a different model as the prior to a new model. That said, it's usually best to try and incorporate the model directly into the code. There are a few examples on GitHub of this, including atmosphere model grids, cooling tracks, etc.

Using a KDE

First, we will generate some data. In the real world, you would load this data eg. from a CSV file.

using Octofitter, Distributions

# create a smoothed KDE estimate of the samples from a 10+-1 gaussian
kde = Octofitter.KDEDist(randn(1000).+10)
KDEDist kernel density estimate distribution

Note that in Octofitter the KDE will have its support truncated to the minimum and maximum values that occur in your dataset, ie. it doesn't allow for infinite long tails.

Now add it to your model as a prior:

@planet b Visual{KepOrbit} begin
    a ~ kde # Sample from the KDE here
    e ~ Uniform(0.0, 0.99)
    i ~ Sine()
    ω ~ UniformCircular()
    Ω ~ UniformCircular()
    θ ~ UniformCircular()
    tp = θ_at_epoch_to_tperi(system,b,50000)
end
@system Tutoria begin
    M ~ truncated(Normal(1.2, 0.1), lower=0.1)
    plx ~ truncated(Normal(50.0, 0.02), lower=0.1)
end b
model = Octofitter.LogDensityModel(Tutoria)
chain = octofit(model)
Chains MCMC chain (1000×28×1 Array{Float64, 3}):

Iterations        = 1:1:1000
Number of chains  = 1
Samples per chain = 1000
Wall duration     = 0.91 seconds
Compute duration  = 0.91 seconds
parameters        = M, plx, b_a, b_e, b_i, b_ωy, b_ωx, b_Ωy, b_Ωx, b_θy, b_θx, b_ω, b_Ω, b_θ, b_tp
internals         = n_steps, is_accept, acceptance_rate, hamiltonian_energy, hamiltonian_energy_error, max_hamiltonian_energy_error, tree_depth, numerical_error, step_size, nom_step_size, is_adapt, loglike, logpost, tree_depth, numerical_error

Summary Statistics
  parameters         mean         std       mcse    ess_bulk   ess_tail      r ⋯
      Symbol      Float64     Float64    Float64     Float64    Float64   Floa ⋯

           M       1.1992      0.1006     0.0035    874.4261   566.3778    1.0 ⋯
         plx      49.9993      0.0204     0.0007    936.7313   676.4312    1.0 ⋯
         b_a      10.0800      1.0919     0.0457    619.8236   316.1480    1.0 ⋯
         b_e       0.4890      0.2782     0.0085    990.3864   614.9544    1.0 ⋯
         b_i       1.5835      0.6686     0.0200   1078.2827   769.3002    0.9 ⋯
        b_ωy      -0.0379      0.7052     0.0327    509.2819   741.5125    0.9 ⋯
        b_ωx       0.0779      0.7201     0.0379    404.1475   500.7570    0.9 ⋯
        b_Ωy       0.0147      0.7247     0.0377    375.6385   789.4449    0.9 ⋯
        b_Ωx       0.0625      0.7056     0.0366    377.7605   745.3954    0.9 ⋯
        b_θy       0.0367      0.7175     0.0419    285.0305   792.1349    0.9 ⋯
        b_θx       0.0255      0.7057     0.0372    383.1695   596.9429    1.0 ⋯
         b_ω       0.1797      1.8441     0.0854    574.2227   868.2807    0.9 ⋯
         b_Ω       0.1823      1.7964     0.0825    542.9553   661.3184    0.9 ⋯
         b_θ       0.0971      1.7674     0.0821    533.2708   715.8530    1.0 ⋯
        b_tp   45024.3925   4263.4986   150.8081    818.4966   743.4487    1.0 ⋯
                                                               2 columns omitted

Quantiles
  parameters         2.5%        25.0%        50.0%        75.0%        97.5%
      Symbol      Float64      Float64      Float64      Float64      Float64

           M       0.9836       1.1371       1.1979       1.2630       1.3923
         plx      49.9598      49.9857      49.9992      50.0131      50.0383
         b_a       8.0404       9.3628      10.0605      10.7812      12.2996
         b_e       0.0282       0.2583       0.4981       0.7306       0.9471
         b_i       0.3913       1.0676       1.5752       2.0862       2.8344
        b_ωy      -1.0874      -0.7156      -0.0904       0.6389       1.0593
        b_ωx      -1.0773      -0.6261       0.1534       0.7691       1.0667
        b_Ωy      -1.0676      -0.7054       0.0326       0.7462       1.0808
        b_Ωx      -1.0779      -0.6232       0.1252       0.7498       1.0662
        b_θy      -1.0408      -0.6777       0.0947       0.7381       1.0794
        b_θx      -1.0665      -0.6709       0.0348       0.6894       1.0636
         b_ω      -3.0046      -1.4495       0.3407       1.7844       2.9989
         b_Ω      -2.9710      -1.2844       0.2498       1.7679       2.9992
         b_θ      -2.9518      -1.3261       0.0486       1.6200       2.9055
        b_tp   37258.9828   41277.7187   45210.5155   49420.5183   50399.6036

We now examine the posterior and verify that it matches our KDE prior:

dat = chain[:b_a][:]
@show mean(dat) std(dat)
mean(dat) = 10.080030370224607
std(dat) = 1.0919213483850636

Observable Based Priors

Octofitter implements observable-based priors from O'Neil 2019 for relative astrometry. You can fit a model to astrometry using observable-based priors using the following recipe:

using Octofitter, Distributions

astrom_like = PlanetRelAstromLikelihood(
    (;epoch=mjd("2020-12-20"), ra=400.0, σ_ra=5.0, dec=400.0, σ_dec=5.0)
)

@planet b Visual{KepOrbit} begin
    # For using with ObsPriors:
    P ~ Uniform(0.001, 1000)
    a = cbrt(system.M * b.P^2)

    e ~ Uniform(0.0, 1.0)
    i ~ Sine()
    ω ~ UniformCircular()
    Ω ~ UniformCircular()
    mass ~ LogUniform(0.01, 100)

    τ ~ UniformCircular(1.0)
    tp =  b.τ*b.P*365.25 + 58849 # reference epoch for τ. Choose an MJD date near your data.
end astrom_like ObsPriorAstromONeil2019(astrom_like);

@system System1 begin
    plx ~ Normal(21.219, 0.060)
	M ~ truncated(Normal(1.1, 0.2),lower=0.1)
end b