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:
NormalUniformLogNormalLogUniformTrucatedNormalVonMises
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 = Planet(
name="b",
basis=Visual{KepOrbit},
likelihoods=[],
variables=@variables begin
a ~ kde # Sample from the KDE here
e ~ Uniform(0.0, 0.99)
i ~ Sine()
M = system.M
ω ~ UniformCircular()
Ω ~ UniformCircular()
θ ~ UniformCircular()
tp = θ_at_epoch_to_tperi(θ, 50000; M, e, a, i, ω, Ω)
end
)
sys = System(
name="Tutoria",
companions=[planet_b],
likelihoods=[],
variables=@variables begin
M ~ truncated(Normal(1.2, 0.1), lower=0.1)
plx ~ truncated(Normal(50.0, 0.02), lower=0.1)
end
)
model = Octofitter.LogDensityModel(sys)
chain = octofit(model)Chains MCMC chain (1000×29×1 Array{Float64, 3}):
Iterations = 1:1:1000
Number of chains = 1
Samples per chain = 1000
Wall duration = 0.74 seconds
Compute duration = 0.74 seconds
parameters = M, plx, b_a, b_e, b_i, b_ωx, b_ωy, b_Ωx, b_Ωy, b_θx, b_θy, b_ω, b_Ω, b_θ, b_M, 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.1964 0.0992 0.0035 780.0701 445.3695 0.9 ⋯
plx 50.0009 0.0202 0.0006 1134.3612 667.6113 0.9 ⋯
b_a 10.0042 1.0215 0.0325 984.2824 526.8577 1.0 ⋯
b_e 0.4868 0.2780 0.0091 808.8773 483.5906 0.9 ⋯
b_i 1.5811 0.7328 0.0240 878.2833 563.6076 0.9 ⋯
b_ωx -0.0827 0.6987 0.0354 362.5779 730.2270 1.0 ⋯
b_ωy -0.0181 0.7205 0.0404 359.4392 749.2339 1.0 ⋯
b_Ωx 0.0337 0.7010 0.0331 497.8907 762.1141 0.9 ⋯
b_Ωy 0.0325 0.7197 0.0434 280.2408 638.6893 0.9 ⋯
b_θx 0.0335 0.7162 0.0341 484.0497 907.8532 1.0 ⋯
b_θy 0.0217 0.7167 0.0377 378.0742 793.9253 0.9 ⋯
b_ω -0.0537 1.8990 0.0881 551.7850 773.9769 1.0 ⋯
b_Ω 0.0381 1.7641 0.0936 398.9816 607.7017 1.0 ⋯
b_θ 0.1058 1.7772 0.0809 551.2386 903.5186 1.0 ⋯
b_M 1.1964 0.0992 0.0035 780.0701 445.3695 0.9 ⋯
b_tp 44611.0815 4165.0284 154.5461 710.7708 723.6651 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.0045 1.1244 1.1956 1.2700 1.3782
plx 49.9604 49.9885 50.0007 50.0134 50.0416
b_a 7.9762 9.3051 10.0341 10.7216 11.8698
b_e 0.0150 0.2458 0.4948 0.7085 0.9717
b_i 0.2484 1.0001 1.6028 2.1526 2.8315
b_ωx -1.0715 -0.7369 -0.1336 0.5816 1.0529
b_ωy -1.0542 -0.7143 -0.0908 0.7127 1.0596
b_Ωx -1.0498 -0.6513 0.0883 0.7099 1.0344
b_Ωy -1.0542 -0.6880 0.1240 0.7319 1.0622
b_θx -1.0596 -0.6708 0.0158 0.7273 1.0708
b_θy -1.0674 -0.6896 0.0661 0.7160 1.0649
b_ω -3.0096 -1.7842 -0.1809 1.6790 3.0233
b_Ω -2.9702 -1.4645 0.1812 1.4946 2.8831
b_θ -2.9654 -1.3651 0.1697 1.6892 2.9740
b_M 1.0045 1.1244 1.1956 1.2700 1.3782
b_tp 37486.3023 40821.7544 44662.9012 48965.8437 49977.1226
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.004177181437628
std(dat) = 1.0215283329451312Observable 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_dat = Table(
epoch=[mjd("2020-12-20")],
ra=[400.0],
σ_ra=[5.0],
dec=[400.0],
σ_dec=[5.0]
)
astrom_like = PlanetRelAstromLikelihood(astrom_dat, name="rel astrom. 1")
planet_b = Planet(
name="b",
basis=Visual{KepOrbit},
likelihoods=[ObsPriorAstromONeil2019(astrom_like)],
variables=@variables begin
# For using with ObsPriors:
P ~ Uniform(0.001, 1000)
M = system.M
a = cbrt(M * P^2)
e ~ Uniform(0.0, 1.0)
i ~ Sine()
ω ~ UniformCircular()
Ω ~ UniformCircular()
mass ~ LogUniform(0.01, 100)
τ ~ UniformCircular(1.0)
tp = τ*P*365.25 + 58849 # reference epoch for τ. Choose an MJD date near your data.
end
)
sys = System(
name="System1",
companions=[planet_b],
likelihoods=[],
variables=@variables begin
plx ~ Normal(21.219, 0.060)
M ~ truncated(Normal(1.1, 0.2),lower=0.1)
end
)