Hi, I was trying to build a gaussian process model with Turing.jl
I’ve read Gaussianprocesses.jl and Stheno.jl. They must be good.
But for the purpose of learning, I’d like to go through step by step in frame of Turing.jl.
I found this one in search.
Also I’ve looked up this great reference.
So Followings are what I wrote and got an error.
begin
using Turing, Distributions
using Random, LinearAlgebra
using Plots, StatsPlots
using AbstractGPs, KernelFunctions
using CSV, HTTP, DataFrames
end
url = "https://raw.githubusercontent.com/delphinH/imagetoy/main/dataset/Fish.csv"
fish = CSV.read(HTTP.get(url).body, DataFrame)
begin
xs = fish[:, :Length1]
ys = fish[:, :Weight]
end
#Exponentiated quadratic kernel
function EQkernel(x1, x2, l, σ)
t₁ = sum(x1.^2, dims=2)
t₂ = sum(x2.^2, dims=2)
t₃ = 2*x1*x2'
t = (t₁ .+ t₂') - t₃
return σ^2 * exp.(-0.5/l^2 * t)
end
EQkernel(xs, xs, 1, 1) #this work!
@model gptest(x, y) = begin
#Prior
σ ~ LogNormal(0.0, 0.1)
l ~ LogNormal(0.0, 1.0)
σy ~ LogNormal(0.0, 1.0)
#covariance function
kernel = EQkernel(x, x, σ, l)
K = kernelmatrix(kernel, x[:, :], obsdims=1)
#add noise
y ~ MvNormal(K + LinearAlgebra.I * σy^2)
end
model = gptest(xs, ys)
chain = sample(model, NUTS(), 2000) # Got an MethodError
MethodError: no method matching kernelmatrix(::Matrix{Float64}, ::Matrix{Float64}; obsdims=1)
How can I fix this error?
Are there better ways?
I don’t know what kernelmatrix function is.
Thanks for reading and your attention!