Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with arbitrary multivariate mean #240

Open
parikshit-pareek opened this issue Dec 2, 2022 · 3 comments
Open

Working with arbitrary multivariate mean #240

parikshit-pareek opened this issue Dec 2, 2022 · 3 comments

Comments

@parikshit-pareek
Copy link

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?

@willtebbutt
Copy link
Member

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?

@parikshit-pareek
Copy link
Author

@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

@willtebbutt
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants