Stheno.jl
Stheno.jl copied to clipboard
Working with arbitrary multivariate mean
I am attempting to define a arbitrary multivariate mean GP as:
function g(X)
x = X[:,1]; z = X[:,2];
x +z
end
f = stretch(GP(X->g(X),SEKernel()),1 / l);
a = randn(2,N_train)
X = ColVecs(a) # Converting the matrix into a multi-column object
However, I am not able to optimise the hyper parameters and getting the following error:
BoundsError: attempt to access 2-element view(::Matrix{Float64}, :, 1) with eltype Float64 at index [1:2, 2]
Where can I find any example of doing this?
Thanks for opening this @parikshit-pareek . Could you please provide a full copy of your stack trace so that I can get a better idea of where the problem might be coming from?
@willtebbutt Take a look at this code : Here
Also, I discovered that if the mean function is expressed in terms of matrix operations, it works fine.
function m(X)
X'*X
end
Ahhh It's an AD issue.
The way to solve it is to implement _map_meanfunction(::CustomMean{typeof(g)}, ::ColVecs) using something like the matrix operations that you've described above. e.g.
function AbstractGPs._map_meanfunction(::CustomMean{typeof(g)}, x::ColVecs)
X = x.X
return <some operations on X that returns a vector of length `length(x)`>
end
This is the most important operation on a mean function anyway, so it's a good idea to implement this if you at all care about performance.