Simulations

In addition to inference, the Gaussian process modelling framework allows simulations and predictions of the underlying process. This is done by conditioning the Gaussian process on some observations and then sampling from the conditioned distribution.

Sampling from the Gaussian process

Assuming a SingleBendingPowerLaw we can draw realisations from the Gaussian process with a mean. First, we define the power spectral density function and plot it.

using Random
using Plots
using Pioran

rng = MersenneTwister(1234)
# Define power spectral density function
𝓟 = SingleBendingPowerLaw(0.3,1e-2,2.9)
f_min, f_max = 1e-3, 1e3
f0,fM = f_min/20.,f_max*20.
f = 10 .^ range(log10(f0), log10(fM), length=1000)
plot(f, 𝓟(f), xlabel="Frequency (day^-1)",ylabel="Power Spectral Density",legend=false,framestyle = :box,xscale=:log10,yscale=:log10,lw=2)
Example block output

Then we approximate it to form a covariance function. We then build the Gaussian process and draw realisations from it using rand.

variance = 15.2
# Approximation of the PSD to form a covariance function
𝓡 = approx(𝓟, f_min, f_max, 20, variance, basis_function="SHO")
μ = 1.3
# Build the GP
f = ScalableGP(μ, 𝓡) # Define the GP

T = 450 # days
t = range(0, stop=T, length=1000)
σ² = ones(length(t))*0.25

fx = f(t, σ²) # Gaussian process
realisations = [rand(rng,fx) for _ in 1:5]
plot(t, realisations, label="Realisations", xlabel="Time [days]", framestyle = :box,ylabel="Value")
Example block output
Note

Sampling from a Gaussian process built with semi-separable covariance functions is very efficient. The time complexity is O(N) where N is the number of data points.

Conditioning the Gaussian process

We can compute the conditioned or posterior distribution of the Gaussian process given some observations. Let's use a subset of the realisations to condition the Gaussian process and then sample from the conditioned distribution.

using StatsBase
idx = sort(sample(1:length(t), 50, replace = false));
t_obs = t[idx]
y_obs = realisations[1][idx]
yerr = 0.25*ones(length(t_obs))
fx = f(t_obs, yerr.^2) # Gaussian process
AbstractGPs.FiniteGP{ScalableGP{AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}, Symbol}, Vector{Float64}, LinearAlgebra.Diagonal{Float64, Vector{Float64}}}(
f: ScalableGP{AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}, Symbol}(AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}(AbstractGPs.ConstMean{Float64}(1.3), Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}(Celerite[Celerite(0.21179581122061306, 0.21179581122061306, 0.0002221441469079183, 0.0002221441469079183), Celerite(0.38542244831627853, 0.38542244831627853, 0.0006300497947253256, 0.0006300497947253256), Celerite(0.9038882037020084, 0.9038882037020084, 0.0017869601758986303, 0.0017869601758986303), Celerite(1.6067166095810141, 1.6067166095810141, 0.0050682131745472155, 0.0050682131745472155), Celerite(4.964666291074675, 4.964666291074675, 0.014374570362059993, 0.014374570362059993), Celerite(22.755812872815056, 22.755812872815056, 0.04076945187142277, 0.04076945187142277), Celerite(5.378025805869529, 5.378025805869529, 0.11563115724719714, 0.11563115724719714), Celerite(0.5417886639897328, 0.5417886639897328, 0.32795546451037977, 0.32795546451037977), Celerite(0.08070461417658467, 0.08070461417658467, 0.9301540282286335, 0.9301540282286335), Celerite(0.010848075938726597, 0.010848075938726597, 2.638121970376775, 2.638121970376775), Celerite(0.0015090806302273192, 0.0015090806302273192, 7.482295748198312, 7.482295748198312), Celerite(0.0002076692891940062, 0.0002076692891940062, 21.221440969050757, 21.221440969050757), Celerite(2.8676529647079397e-5, 2.8676529647079397e-5, 60.18868699641365, 60.18868699641365), Celerite(3.955543296634202e-6, 3.955543296634202e-6, 170.70839099171252, 170.70839099171252), Celerite(5.458037196298439e-7, 5.458037196298439e-7, 484.16664674402534, 484.16664674402534), Celerite(7.53042020169437e-8, 7.53042020169437e-8, 1373.203393562152, 1373.203393562152), Celerite(1.0389899331678754e-8, 1.0389899331678754e-8, 3894.70768540476, 3894.70768540476), Celerite(1.4338973791019396e-9, 1.4338973791019396e-9, 11046.249977144691, 11046.249977144691), Celerite(1.9677308815711412e-10, 1.9677308815711412e-10, 31329.601195702533, 31329.601195702533), Celerite(3.012647957419647e-11, 3.012647957419647e-11, 88857.65876316732, 88857.65876316732)], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732])), Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}(Celerite[Celerite(0.21179581122061306, 0.21179581122061306, 0.0002221441469079183, 0.0002221441469079183), Celerite(0.38542244831627853, 0.38542244831627853, 0.0006300497947253256, 0.0006300497947253256), Celerite(0.9038882037020084, 0.9038882037020084, 0.0017869601758986303, 0.0017869601758986303), Celerite(1.6067166095810141, 1.6067166095810141, 0.0050682131745472155, 0.0050682131745472155), Celerite(4.964666291074675, 4.964666291074675, 0.014374570362059993, 0.014374570362059993), Celerite(22.755812872815056, 22.755812872815056, 0.04076945187142277, 0.04076945187142277), Celerite(5.378025805869529, 5.378025805869529, 0.11563115724719714, 0.11563115724719714), Celerite(0.5417886639897328, 0.5417886639897328, 0.32795546451037977, 0.32795546451037977), Celerite(0.08070461417658467, 0.08070461417658467, 0.9301540282286335, 0.9301540282286335), Celerite(0.010848075938726597, 0.010848075938726597, 2.638121970376775, 2.638121970376775), Celerite(0.0015090806302273192, 0.0015090806302273192, 7.482295748198312, 7.482295748198312), Celerite(0.0002076692891940062, 0.0002076692891940062, 21.221440969050757, 21.221440969050757), Celerite(2.8676529647079397e-5, 2.8676529647079397e-5, 60.18868699641365, 60.18868699641365), Celerite(3.955543296634202e-6, 3.955543296634202e-6, 170.70839099171252, 170.70839099171252), Celerite(5.458037196298439e-7, 5.458037196298439e-7, 484.16664674402534, 484.16664674402534), Celerite(7.53042020169437e-8, 7.53042020169437e-8, 1373.203393562152, 1373.203393562152), Celerite(1.0389899331678754e-8, 1.0389899331678754e-8, 3894.70768540476, 3894.70768540476), Celerite(1.4338973791019396e-9, 1.4338973791019396e-9, 11046.249977144691, 11046.249977144691), Celerite(1.9677308815711412e-10, 1.9677308815711412e-10, 31329.601195702533, 31329.601195702533), Celerite(3.012647957419647e-11, 3.012647957419647e-11, 88857.65876316732, 88857.65876316732)], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732]), :celerite)
x: [4.504504504504505, 27.47747747747748, 29.27927927927928, 40.990990990990994, 55.4054054054054, 77.92792792792793, 115.76576576576576, 135.13513513513513, 140.54054054054055, 145.04504504504504  …  380.6306306306306, 386.93693693693695, 391.44144144144144, 400.9009009009009, 420.72072072072075, 422.07207207207205, 425.22522522522524, 435.13513513513516, 437.8378378378378, 447.7477477477477]
Σy: [0.0625 0.0 … 0.0 0.0; 0.0 0.0625 … 0.0 0.0; … ; 0.0 0.0 … 0.0625 0.0; 0.0 0.0 … 0.0 0.0625]
)

We can compute the posterior distribution of the Gaussian process given the observations.

fp = posterior(fx, y_obs) # Posterior distribution
Pioran.PosteriorGP{AbstractGPs.FiniteGP{ScalableGP{AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}, Symbol}, Vector{Float64}, LinearAlgebra.Diagonal{Float64, Vector{Float64}}}, Vector{Float64}}(AbstractGPs.FiniteGP{ScalableGP{AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}, Symbol}, Vector{Float64}, LinearAlgebra.Diagonal{Float64, Vector{Float64}}}(
f: ScalableGP{AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}, Symbol}(AbstractGPs.GP{AbstractGPs.ConstMean{Float64}, Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}}(AbstractGPs.ConstMean{Float64}(1.3), Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}(Celerite[Celerite(0.21179581122061306, 0.21179581122061306, 0.0002221441469079183, 0.0002221441469079183), Celerite(0.38542244831627853, 0.38542244831627853, 0.0006300497947253256, 0.0006300497947253256), Celerite(0.9038882037020084, 0.9038882037020084, 0.0017869601758986303, 0.0017869601758986303), Celerite(1.6067166095810141, 1.6067166095810141, 0.0050682131745472155, 0.0050682131745472155), Celerite(4.964666291074675, 4.964666291074675, 0.014374570362059993, 0.014374570362059993), Celerite(22.755812872815056, 22.755812872815056, 0.04076945187142277, 0.04076945187142277), Celerite(5.378025805869529, 5.378025805869529, 0.11563115724719714, 0.11563115724719714), Celerite(0.5417886639897328, 0.5417886639897328, 0.32795546451037977, 0.32795546451037977), Celerite(0.08070461417658467, 0.08070461417658467, 0.9301540282286335, 0.9301540282286335), Celerite(0.010848075938726597, 0.010848075938726597, 2.638121970376775, 2.638121970376775), Celerite(0.0015090806302273192, 0.0015090806302273192, 7.482295748198312, 7.482295748198312), Celerite(0.0002076692891940062, 0.0002076692891940062, 21.221440969050757, 21.221440969050757), Celerite(2.8676529647079397e-5, 2.8676529647079397e-5, 60.18868699641365, 60.18868699641365), Celerite(3.955543296634202e-6, 3.955543296634202e-6, 170.70839099171252, 170.70839099171252), Celerite(5.458037196298439e-7, 5.458037196298439e-7, 484.16664674402534, 484.16664674402534), Celerite(7.53042020169437e-8, 7.53042020169437e-8, 1373.203393562152, 1373.203393562152), Celerite(1.0389899331678754e-8, 1.0389899331678754e-8, 3894.70768540476, 3894.70768540476), Celerite(1.4338973791019396e-9, 1.4338973791019396e-9, 11046.249977144691, 11046.249977144691), Celerite(1.9677308815711412e-10, 1.9677308815711412e-10, 31329.601195702533, 31329.601195702533), Celerite(3.012647957419647e-11, 3.012647957419647e-11, 88857.65876316732, 88857.65876316732)], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732])), Pioran.SumOfCelerite{StructArrays.StructArray{<:Pioran.SemiSeparable}}(Celerite[Celerite(0.21179581122061306, 0.21179581122061306, 0.0002221441469079183, 0.0002221441469079183), Celerite(0.38542244831627853, 0.38542244831627853, 0.0006300497947253256, 0.0006300497947253256), Celerite(0.9038882037020084, 0.9038882037020084, 0.0017869601758986303, 0.0017869601758986303), Celerite(1.6067166095810141, 1.6067166095810141, 0.0050682131745472155, 0.0050682131745472155), Celerite(4.964666291074675, 4.964666291074675, 0.014374570362059993, 0.014374570362059993), Celerite(22.755812872815056, 22.755812872815056, 0.04076945187142277, 0.04076945187142277), Celerite(5.378025805869529, 5.378025805869529, 0.11563115724719714, 0.11563115724719714), Celerite(0.5417886639897328, 0.5417886639897328, 0.32795546451037977, 0.32795546451037977), Celerite(0.08070461417658467, 0.08070461417658467, 0.9301540282286335, 0.9301540282286335), Celerite(0.010848075938726597, 0.010848075938726597, 2.638121970376775, 2.638121970376775), Celerite(0.0015090806302273192, 0.0015090806302273192, 7.482295748198312, 7.482295748198312), Celerite(0.0002076692891940062, 0.0002076692891940062, 21.221440969050757, 21.221440969050757), Celerite(2.8676529647079397e-5, 2.8676529647079397e-5, 60.18868699641365, 60.18868699641365), Celerite(3.955543296634202e-6, 3.955543296634202e-6, 170.70839099171252, 170.70839099171252), Celerite(5.458037196298439e-7, 5.458037196298439e-7, 484.16664674402534, 484.16664674402534), Celerite(7.53042020169437e-8, 7.53042020169437e-8, 1373.203393562152, 1373.203393562152), Celerite(1.0389899331678754e-8, 1.0389899331678754e-8, 3894.70768540476, 3894.70768540476), Celerite(1.4338973791019396e-9, 1.4338973791019396e-9, 11046.249977144691, 11046.249977144691), Celerite(1.9677308815711412e-10, 1.9677308815711412e-10, 31329.601195702533, 31329.601195702533), Celerite(3.012647957419647e-11, 3.012647957419647e-11, 88857.65876316732, 88857.65876316732)], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.21179581122061306, 0.38542244831627853, 0.9038882037020084, 1.6067166095810141, 4.964666291074675, 22.755812872815056, 5.378025805869529, 0.5417886639897328, 0.08070461417658467, 0.010848075938726597, 0.0015090806302273192, 0.0002076692891940062, 2.8676529647079397e-5, 3.955543296634202e-6, 5.458037196298439e-7, 7.53042020169437e-8, 1.0389899331678754e-8, 1.4338973791019396e-9, 1.9677308815711412e-10, 3.012647957419647e-11], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732], [0.0002221441469079183, 0.0006300497947253256, 0.0017869601758986303, 0.0050682131745472155, 0.014374570362059993, 0.04076945187142277, 0.11563115724719714, 0.32795546451037977, 0.9301540282286335, 2.638121970376775, 7.482295748198312, 21.221440969050757, 60.18868699641365, 170.70839099171252, 484.16664674402534, 1373.203393562152, 3894.70768540476, 11046.249977144691, 31329.601195702533, 88857.65876316732]), :celerite)
x: [4.504504504504505, 27.47747747747748, 29.27927927927928, 40.990990990990994, 55.4054054054054, 77.92792792792793, 115.76576576576576, 135.13513513513513, 140.54054054054055, 145.04504504504504  …  380.6306306306306, 386.93693693693695, 391.44144144144144, 400.9009009009009, 420.72072072072075, 422.07207207207205, 425.22522522522524, 435.13513513513516, 437.8378378378378, 447.7477477477477]
Σy: [0.0625 0.0 … 0.0 0.0; 0.0 0.0625 … 0.0 0.0; … ; 0.0 0.0 … 0.0625 0.0; 0.0 0.0 … 0.0 0.0625]
)
, [6.367156475271415, -4.90772098031265, -4.84926961125822, -6.698980668077906, -2.0282528862929174, -0.7388443359234012, 3.784907384188556, -2.4163801619353142, 0.9778276520269376, -0.2913590028965023  …  0.43407210208699065, -0.2209925866175233, 1.9995680229890689, 0.07640695112513551, -7.265195653174087, -7.975772472276943, -8.714588428544848, -4.2393774141685165, -6.091141501299605, 2.831043350348003])

The mean and standard deviation of this distribution, can be computed using the mean and std functions. The posterior covariance matrix can be computed using the cov function.

m = mean(fp,t);
s = std(fp,t);
1000-element Vector{Float64}:
 2.0626517007872334
 1.9110763413854732
 1.75276351079283
 1.5872472345598196
 1.4138595245390857
 1.2316590526764528
 1.0395214066980454
 0.8365777882661751
 0.6229416261221012
 0.4037699022251107
 ⋮
 0.7273957109958538
 0.5629224597506416
 0.3811475723442188
 0.24930315917571488
 0.39735949752571564
 0.6061667026522791
 0.8108042256354694
 1.0062576530612704
 1.1921904152760825

We can plot the realisations, the observations and the posterior distribution.

plot(t, realisations[1], label="Realisation", xlabel="Time [days]", framestyle = :box,ylabel="Value")
plot!(t_obs, y_obs,yerr=yerr, label="Observations", seriestype=:scatter)
plot!(t,m, ribbon=s,label="Posterior distribution", lw=2)
plot!(t,m,ribbon=2*s, label=nothing)
Example block output
Note

The computation of the mean of the distribution is very efficient. The time complexity is O(N) where N is the number of data points. However, the computation of the covariance is very inefficient as the posterior covariance is not semi-separable.

Sampling from the conditioned distribution

We can draw realisations from the conditioned distribution using rand.

samples_cond = rand(rng,fp,t,5);
1000×5 Matrix{Float64}:
 8.42748  7.34992  10.6412   10.2005   5.24453
 8.66185  7.05551  10.2608   10.0086   5.33955
 8.70568  6.6528   10.0825    9.77261  5.29936
 8.83709  6.17403  10.1901    9.65821  5.53369
 8.31257  6.10017  10.1221    9.08733  5.38345
 7.76123  5.96929   9.4228    8.81385  5.02117
 7.32911  6.05282   8.90024   8.0894   4.78844
 6.95632  6.0115    8.4788    7.52359  4.99107
 6.45547  6.41548   8.13547   6.93222  5.32481
 6.0703   6.59369   7.18235   6.61222  5.51607
 ⋮                                     
 1.73311  1.81749   1.56871   1.54545  2.22611
 2.37855  1.95991   2.02202   1.92103  2.38687
 2.81616  1.9061    2.36727   2.57885  2.67545
 2.97269  2.5692    2.85837   2.98925  2.51206
 3.41462  2.84287   3.10181   2.8865   1.87264
 3.8412   2.86026   3.26103   3.13078  1.64703
 4.28134  3.39541   3.48248   3.21353  1.48771
 4.86719  3.53674   3.73938   3.42635  1.72988
 5.31795  3.79149   3.1899    3.84353  1.6074

We can plot the realisations, the observations and the posterior distribution.

plot(t_obs, y_obs,yerr=yerr, label="Observations", seriestype=:scatter, xlabel="Time [days]", framestyle = :box,ylabel="Value",color=:black,lw=2)
plot!(t, samples_cond, label=nothing)
Example block output
Note

Sampling from the conditioned Gaussian process is very inefficient as the posterior distribution is not semi-separable.