@willtebbutt I have this working code
using Stheno
using Stheno.AbstractGPs
using CairoMakie
const l1 = 0.4
const s1 = 0.2
f = let
gpc = Stheno.GPC()
gp = kernel -> Stheno.wrap(GP(kernel), gpc)
f1 = s1 * stretch(gp(Matern52Kernel()), 1 / l1)
f2 = gp(ConstantKernel())
f3 = gp(LinearKernel())
ff = f1 + f2 + f3
Stheno.GPPP((; f1, f2, f3, ff), gpc)
end
average(x) = sum(x) ./ length(x)
center(x) = x .- average(x)
const n = 3
const xx = collect(range(1.0, 5.0; length=n))
const x = GPPPInput(:ff, xx);
const σ²_n = .1;
const fx = f(x, σ²_n);
const y = center(rand(n) + (xx .* 2));
f_posterior = @time posterior(fx, y);
x_plot = range(0.0, 7.0; length=1000);
xp = GPPPInput(:ff, x_plot);
ms = marginals(f_posterior(xp));
mea = mean.(ms)
st3 = 3std.(ms)
fig = Figure()
Axis(fig[1, 1])
scatter!(x.x, y; color=:red);
lines!(x_plot, mean.(ms), color = :blue, linewidth = 2)
band!(x_plot, mea .- st3, mea .+ st3, color = (:blue, 0.2))
for col in eachcol(rand(f_posterior(xp), 10))
lines!(x_plot, col, color = (:blue, 0.3))
end
fig
and I want to change it to use TemporalGPs. I’m not sure where to put the to_sde
calls. For example, this doesn’t work:
using Stheno
using Stheno.AbstractGPs
using TemporalGPs
using CairoMakie
const l1 = 0.4
const s1 = 0.2
f = let
gpc = Stheno.GPC()
gp = kernel -> Stheno.wrap(GP(kernel), gpc)
sde = x -> to_sde(x, SArrayStorage(Float64))
f1 = s1 * stretch(gp(sde(Matern52Kernel())), 1 / l1)
f2 = gp(sde(ConstantKernel()))
f3 = gp(sde(LinearKernel()) )
ff = f1 + f2 + f3
gppp = Stheno.GPPP((; f1, f2, f3, ff), gpc)
end
average(x) = sum(x) ./ length(x)
center(x) = x .- average(x)
const n = 3
const xx = collect(range(1.0, 5.0; length=n))
const x = GPPPInput(:ff, xx);
const σ²_n = .1;
const fx = f(x, σ²_n);
const y = center(rand(n) + (xx .* 2));
f_posterior = @time posterior(fx, y);
x_plot = range(0.0, 7.0; length=1000);
xp = GPPPInput(:ff, x_plot);
ms = marginals(f_posterior(xp));
mea = mean.(ms)
st3 = 3std.(ms)
fig = Figure()
Axis(fig[1, 1])
scatter!(x.x, y; color=:red);
lines!(x_plot, mean.(ms), color = :blue, linewidth = 2)
band!(x_plot, mea .- st3, mea .+ st3, color = (:blue, 0.2))
for col in eachcol(rand(f_posterior(xp), 10))
lines!(x_plot, col, color = (:blue, 0.3))
end
fig