# Using TemporalGPs

**URL:** https://discourse.julialang.org/t/using-temporalgps/63208
**Category:** General Usage
**Tags:** gaussian-process
**Created:** [June 19, 2021, 11:35pm UTC](https://discourse.julialang.org/t/using-temporalgps/63208 "2021-06-19T23:35:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [June 19, 2021, 11:35pm UTC](https://discourse.julialang.org/t/using-temporalgps/63208/1 "2021-06-19T23:35:16Z")

</div>

@willtebbutt I have this working code

```julia
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:

```julia
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

```

---

<div class="post-metadata">

### Author: ![willtebbutt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willtebbutt/32/6790_2.png) [@willtebbutt](https://discourse.julialang.org/u/willtebbutt)
#### Post date: [June 21, 2021, 9:03am UTC](https://discourse.julialang.org/t/using-temporalgps/63208/2 "2021-06-21T09:03:48Z")

</div>

Hi @jzr – unfortunately Stheno.jl and TemporalGPs.jl integration is not available yet. It’s very doable, but I’ve not had the time to make it happen.

Are you in the situation where you’ve got a training loop which gets calls lots of times (in which TemporalGPs.jl is really important), and then just want to perform a single decomposition of the resulting GP at the end?
