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)
    plx ~ truncated(Normal(50.0, 0.02), lower=0)
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     = 1.13 seconds
Compute duration  = 1.13 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.2005      0.0975     0.0036    741.4254   712.0350    0.9 ⋯
         plx      50.0005      0.0196     0.0006    964.8033   426.2000    1.0 ⋯
         b_a      10.0067      1.0312     0.0316   1077.4768   583.4725    1.0 ⋯
         b_e       0.5204      0.2867     0.0101    728.7875   360.8107    1.0 ⋯
         b_i       1.6098      0.6779     0.0225    889.6782   587.9417    1.0 ⋯
        b_ωy       0.0666      0.7067     0.0397    334.3524   756.0302    1.0 ⋯
        b_ωx       0.0092      0.7155     0.0407    348.2050   738.9199    1.0 ⋯
        b_Ωy       0.0343      0.7096     0.0393    359.8931   809.4000    1.0 ⋯
        b_Ωx       0.0195      0.7101     0.0436    297.0492   693.5678    1.0 ⋯
        b_θy      -0.0294      0.7129     0.0363    424.8380   609.3305    1.0 ⋯
        b_θx       0.0309      0.7155     0.0380    365.1478   548.9754    0.9 ⋯
         b_ω       0.0562      1.7317     0.0938    380.4489   561.4524    1.0 ⋯
         b_Ω       0.0168      1.7734     0.0848    517.8987   765.2233    1.0 ⋯
         b_θ       0.0925      1.8411     0.0861    553.8887   653.7758    1.0 ⋯
        b_tp   45044.9667   4344.3027   155.1877    783.9082   735.6916    1.0 ⋯
                                                               2 columns omitted

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

           M       1.0174       1.1295       1.2028       1.2656       1.3937
         plx      49.9619      49.9878      50.0003      50.0141      50.0384
         b_a       8.0136       9.3034      10.0371      10.7099      11.9658
         b_e       0.0442       0.2681       0.5358       0.7692       0.9683
         b_i       0.3246       1.0983       1.6358       2.1294       2.8362
        b_ωy      -1.0544      -0.6020       0.0935       0.7621       1.0722
        b_ωx      -1.0578      -0.7052       0.0404       0.6986       1.0510
        b_Ωy      -1.0703      -0.6652       0.0770       0.7296       1.0382
        b_Ωx      -1.0424      -0.6529      -0.0034       0.7242       1.0599
        b_θy      -1.0697      -0.7278      -0.0589       0.6704       1.0739
        b_θx      -1.0465      -0.6784       0.0614       0.7302       1.0637
         b_ω      -2.9263      -1.3696       0.0878       1.5657       2.9444
         b_Ω      -2.9460      -1.4805      -0.0058       1.5259       2.9608
         b_θ      -2.9772      -1.5660       0.1350       1.7206       2.9956
        b_tp   37545.8190   41231.4528   45063.3941   49610.3265   50404.4166

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.00671813457469
std(dat) = 1.0312330429039755

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)
end b