-
Notifications
You must be signed in to change notification settings - Fork 32
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
[WIP] Rework on kernelmatrix to work with Vectors and more complex kernels #83
[WIP] Rework on kernelmatrix to work with Vectors and more complex kernels #83
Conversation
I feel like this might be a good case for using traits instead of a |
I really don't think traits are needed here. It would force users who wants to add "simple" kernels to always add a |
I guess users might want to user their own type structure for various reasons (e.g., kernels on special spaces that you might want to group but where not every kernel is a simple or base kernel), and it's just not possible for them to exploit the general implementation using
You could get both by just defining issimple(::Kernel) = false
issimple(::SimpleKernel) = true or something similar with specific traits. So everyone that subtypes |
Please do :) If we go ahead with this change, I'm unclear what the differences between At the minute, |
|
Sorry, is it critical that we do the |
Yup, but then why do we have |
Because KernelProduct etc are not BaseKernels |
I can put an expensive |
Okay, sorry, I think I've been getting myself confused by the purpose of this PR, but I still think it would be good to introduce the changes over the course of two PRs.
AFAICT, the first is going to involve some fairly large changes to the codebase, so it would be good to do it as a single PR. Would you be okay with doing that @theogf ? |
The second one implies that we need to be able to treat the matrices as vectors of vectors, hence the need for |
Yup, so if we do 1 then 2 everything should be okay? |
So as you mentioned in #84 and #43, time to tackle obsdim!
|
I'm a little confused. I was expecting the following to happen:
Why aren't we doing that? edit: I know we don't actually have a |
I don't understand the point of using a ColVecs wrapper when it's not necessary (for AbstractMatrix with SimpleKernels).
If I understand you correctly, the problem there is with |
No. The problem is that you ever have to pass an Since I've misunderstood, could you explain to me why you need |
For But as you stated in #43 we can make a uniform interface. I will just finish this PR so we can move on and get rid of |
Co-Authored-By: David Widmann <[email protected]>
src/matrix/kernelmatrix.jl
Outdated
κ::Kernel, | ||
X::AbstractVector{<:Real} | ||
) | ||
kernelmatrix!(K, κ, reshape(X, 1, :), obsdim = 2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we agreed not to do this? I guess more in line with the discussion we had would be to not import Distances.pairwise and define an internal method pairwise
along the lines of
function pairwise(metric::PreMetric, X::AbstractMatrix; obsdim = defaultobs)
return Distances.pairwise(metric, X; dims = obsdim)
end
function pairwise(metric::PreMetric, X::AbstractVector; obsdim = defaultobs)
return Distances.pairwise(metric, reshape(X, 1, :); dims = 2)
end
and similarly for pairwise(metric, X, Y, ...)
(and pairwise! maybe, not sure if that's useful?).
I guess then it would be easier to remove obsdim in one of the subsequent PRs and add support for ColVecs. It seems a bit weird to add this implementation with our plan in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well right now it's not really an issue. If you want I can replace it by :
kernelmatrix!(K, κ, ColVecs(reshape(X, 1, :)))
This will be done anyway in the next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as far as I understand, the idea is to only use vectors so there is no reason to reshape and wrap it anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh now I understand!
But it would raise the problem for SimpleKernel
we would not use pairwise
anymore. But I suppose that for 1D problem it will not make a big difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we would - but the reshaping for Distances would only happen in the implementation of pairwise
sketched above (since only Distances cares about it being a matrix instead of a vector).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐌 (there is no slowpoke emoji)
Oh yeah I could remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of picky style things. I'm happy for this to be merged once they've been addressed and tests have passed though.
@@ -15,6 +15,8 @@ end | |||
|
|||
kappa(k::ScaledKernel, x) = first(k.σ²) * kappa(k.kernel, x) | |||
|
|||
kappa(k::ScaledKernel, x, y) = first(k.σ²) * kappa(k.kernel, x, y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why has this been added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I realised that ScaleKernel
could only be applied to SimpleKernel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, okay. And this is kappa
in the kappa == kernelmatrix
sense, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh no, it's in the sense of k(x,y)
, it multiplies by sigma for every function call. But this can get replaced when implementing #87
I added the notion of
SimpleKernel
for whenDistances.jl
pairwise can just be used.While
BaseKernel
will just rely onkappa(k, x, y)
@willtebbutt Now I can see the point of
ColVecs
, is that okay if I steal your implementation from Stheno and rework it for our purpose?[EDIT] This PR only aims at making the difference between
SimpleKernel
wherekernelmatrix
is based onpairwise
fromDistances.jl
,BaseKernel
wherekernelmatrix
relies onkappa(k, x, y)
andKernel
which also contains composite kernels.ColVecs
andRowVecs
are added separately in #84 and #89