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},
observations=[],
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],
observations=[],
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.1966 0.0960 0.0027 1296.0198 750.6289 0.9 ⋯
plx 50.0003 0.0208 0.0007 1025.8708 557.5463 1.0 ⋯
b_a 10.0139 1.0169 0.0301 1114.6219 487.5108 0.9 ⋯
b_e 0.4896 0.2820 0.0072 1335.9526 360.6835 1.0 ⋯
b_i 1.5694 0.6724 0.0204 1096.8306 626.2593 1.0 ⋯
b_ωx -0.0503 0.7175 0.0383 386.6100 880.2411 0.9 ⋯
b_ωy 0.0059 0.7047 0.0351 418.4184 674.2741 0.9 ⋯
b_Ωx 0.0721 0.7159 0.0366 416.5615 734.7819 0.9 ⋯
b_Ωy -0.0229 0.7087 0.0391 364.6281 624.2854 1.0 ⋯
b_θx -0.0371 0.7178 0.0392 357.5967 773.6396 1.0 ⋯
b_θy -0.0130 0.7179 0.0374 423.5745 880.2411 1.0 ⋯
b_ω -0.0119 1.8656 0.0834 600.3754 720.5786 0.9 ⋯
b_Ω -0.0253 1.7409 0.0890 424.4974 715.0619 1.0 ⋯
b_θ 0.0192 1.8503 0.0836 594.9518 822.5266 1.0 ⋯
b_M 1.1966 0.0960 0.0027 1296.0198 750.6289 0.9 ⋯
b_tp 44666.3822 4192.2829 146.5527 855.6908 713.6437 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.0118 1.1310 1.1930 1.2680 1.3755
plx 49.9614 49.9858 50.0000 50.0144 50.0416
b_a 8.0385 9.3084 10.0710 10.7195 12.0121
b_e 0.0189 0.2440 0.4860 0.7264 0.9559
b_i 0.3061 1.0799 1.5932 2.0496 2.7913
b_ωx -1.0795 -0.7360 -0.1147 0.6612 1.0660
b_ωy -1.0586 -0.7002 0.0200 0.7055 1.0465
b_Ωx -1.0281 -0.6608 0.1106 0.7713 1.0766
b_Ωy -1.0960 -0.7071 -0.0351 0.6543 1.0655
b_θx -1.0771 -0.7320 -0.0269 0.6621 1.0616
b_θy -1.0811 -0.7229 -0.0363 0.7059 1.0522
b_ω -3.0079 -1.7221 0.0664 1.6739 2.9765
b_Ω -2.9558 -1.4775 -0.0527 1.4030 2.9818
b_θ -3.0216 -1.5733 -0.0520 1.6486 2.9876
b_M 1.0118 1.1310 1.1930 1.2680 1.3755
b_tp 37611.5466 40883.7790 44954.5359 48986.4519 49979.6308
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.013866043588864
std(dat) = 1.0169483306361544Observable 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_obs = PlanetRelAstromObs(astrom_dat, name="rel astrom. 1")
planet_b = Planet(
name="b",
basis=Visual{KepOrbit},
observations=[ObsPriorAstromONeil2019(astrom_obs)],
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],
observations=[],
variables=@variables begin
plx ~ Normal(21.219, 0.060)
M ~ truncated(Normal(1.1, 0.2),lower=0.1)
end
)