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.89 seconds
Compute duration = 0.89 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.2016 0.0953 0.0028 1193.3415 850.2053 0.9 ⋯
plx 50.0000 0.0190 0.0006 1109.4943 682.9616 0.9 ⋯
b_a 10.0308 1.0203 0.0325 982.1958 579.3455 0.9 ⋯
b_e 0.4931 0.2738 0.0072 1349.0629 770.8007 1.0 ⋯
b_i 1.5537 0.6845 0.0194 1228.6861 462.2799 1.0 ⋯
b_ωy -0.0643 0.7126 0.0360 423.6061 810.5295 1.0 ⋯
b_ωx 0.0127 0.7179 0.0389 395.2441 907.0437 0.9 ⋯
b_Ωy -0.0114 0.7231 0.0396 370.4693 742.3334 1.0 ⋯
b_Ωx -0.0192 0.7053 0.0369 413.2617 757.6431 1.0 ⋯
b_θy -0.0398 0.7264 0.0361 460.9917 787.9826 0.9 ⋯
b_θx 0.0513 0.7048 0.0351 421.3165 752.0955 1.0 ⋯
b_ω 0.0061 1.8901 0.0919 525.3204 948.0926 1.0 ⋯
b_Ω 0.0070 1.8343 0.0904 452.7901 786.7921 1.0 ⋯
b_θ 0.0905 1.8639 0.0819 613.2987 689.9743 1.0 ⋯
b_tp 44962.5462 4184.9921 157.5528 786.5327 749.0070 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.0140 1.1351 1.1996 1.2657 1.3880
plx 49.9640 49.9871 49.9996 50.0133 50.0363
b_a 8.0621 9.3239 10.0331 10.7270 11.9378
b_e 0.0406 0.2536 0.4934 0.7272 0.9487
b_i 0.3359 1.0416 1.5349 2.0485 2.8194
b_ωy -1.0977 -0.7308 -0.0744 0.6152 1.0745
b_ωx -1.0567 -0.6917 -0.0033 0.7477 1.0760
b_Ωy -1.0494 -0.7324 -0.0585 0.7189 1.0866
b_Ωx -1.0752 -0.7121 -0.0182 0.6577 1.0530
b_θy -1.0807 -0.7480 -0.0935 0.6937 1.0685
b_θx -1.0503 -0.6379 0.0614 0.7371 1.0762
b_ω -3.0421 -1.6332 -0.0032 1.6758 3.0108
b_Ω -2.9551 -1.6065 -0.0200 1.6513 2.9791
b_θ -3.0203 -1.5430 0.1583 1.7686 3.0250
b_tp 37827.8837 41229.1748 44966.7271 49452.3475 50397.3177
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.030821112683714
std(dat) = 1.020338841682584
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