-
Notifications
You must be signed in to change notification settings - Fork 36
Add general TensorProduct kernel #81
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
Conversation
It would be good to get a basic implementation off the ground -- so it should be fine to make this a In an initial implementation, we could just assume 1 dimension per group. |
Realising that now we have quite a collection of kernels which will only work with |
I would be up for that generally, but in a separate PR. I think in this case we're best off implementing |
Ok I will take care of this tomorrow then. This could also be a good start for tackling the "my data is not a matrix" problem |
So you suggest implementing
Intuitively, I would say in the setting described above it's more efficient to fill the matrix by evaluating |
Yeah, although I think in my notation I was thinking D groups of inputs with D different kernels.
I can see your point, but it's not generally the case that any one of the D kernel matrices will be most efficiently computed in this manner. For example, if one of the D groups has P-dimensional inputs and the Exponentiated Quadratic kernel, the most efficient thing is generally going to be to make a call out to Distances.jl to compute the matrix, then product it, since the naive implementation of the kernel matrix in that case is really bad. I think the high level point is that any given kernel knows best how to execute |
I completely agree that a general implementation should just call |
That's a fair point, my previous argument does really only apply to P > 1. I think that there are other reason though, including code complexity and ease of doing reverse-mode AD. The former is in the eye of the beholder of course, and the latter is hard to assess without having a decent suite of benchmarks. |
I ended up using I also had to add some methods for constructing kernel matrices (and their diagonal) from vector-valued inputs (it felt silly to reshape just the slices in tensorproduct.jl, IMO this should work for other kernels as well). |
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.
Quite a bit of readability-related comments, also it would be great if we could have some more tests. In particular the edge-case in which there's only a single kernel in the TensorProduct
.
(edit: this looks great other than the above / below 🙂 )
src/kernels/tensorproduct.jl
Outdated
|
||
featuredim = feature_dim(obsdim) | ||
if !check_dims(X, X, featuredim, obsdim) | ||
throw(DimensionMismatch("Dimensions of the target array K $(size(K)) are not consistent with X $(size(X))")) |
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.
Not within 92 char lim. Please wrap string over multiple lines
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.
Yeah, I just copied this from kernelmatrix.jl
(which is not great either) and missed that it doesn't follow the style guide.
Co-Authored-By: willtebbutt <[email protected]>
Happy for you to merge when you're happy @devmotion , nice work. |
Just want to make sure that tests pass. Otherwise I'm happy. |
OK, tests pass (test failures on Julia master are unrelated). |
See #80 (comment).
As discussed in the outdated PR #56 (comment), it is still unclear what type of arguments
kernelmatrix
andkerneldiagmatrix
should take, or how to implement this in a general way to support both data types (i.e., collections of joint observations in all spaces (e.g., of typeVector{Tuple{Vector{Float64},Vector{Int}}}
), or collections of collections of observations in each space (e.g., of typeTuple{Matrix{Float64},Matrix{Int}}
).