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

Testing (and fixing) handling of AbstractVector{AbstractVector{T}} inputs #370

Merged
merged 17 commits into from
Oct 6, 2021

Conversation

Crown421
Copy link
Member

@Crown421 Crown421 commented Sep 24, 2021

Summary
While implementing stuff for #363 I noticed issues with the handling of AbstractVector{AbstractVector{T}} as inputs for kernelmatrix. Specifically, I noticed a missing method for the fbmkernel, and started by adding tests for AbstractVector{AbstractVector{T}} to the test interface. This has spawned additional issues.

Proposed changes

  • Adding tests for AbstractVector{AbstractVector{T}} inputs
  • Possibly fixing uncovered issues with, among others, the delta metric, _mod in fbm kernel.

What alternatives have you considered?
I understand that AbstractVector{AbstractVector{T}} inputs are not recommended, and that RowVecs and ColVecs should be used instead. However, in the current state those inputs work for some kernels, but not for others. I see two alternatives

  1. Disallow AbstractVector{AbstractVector{T}} inputs, i.e. via kernelmatrix(k, AbstractVector{AbstractVector{T}}, AbstractVector{AbstractVector{T}}) = error("....., see documentation for details")
  2. Go through with this PR, and add a maxlog=1 warning that vectors of vectors are not recommended.

Breaking changes
Current state none, alternative 1 will probably be breaking.

@willtebbutt
Copy link
Member

Vey much in favour of ensuring that this works -- if a kernel says its inputs are vector-valued then kernelmatrix ought to work with any AbstractVector{<:AbstractVector} of inputs.

At what point should we review this PR properly? It looks like it's got some stuff for vector-of-vectors collections of inputs, but also some fixes for kronecker-structured covariance matrices. Is the intention that they be reviewed together, or done separately?

@theogf
Copy link
Member

theogf commented Sep 28, 2021

I understand that AbstractVector{AbstractVector{T}} inputs are not recommended

I don't think this is true at all, these inputs should work just as well!

@Crown421
Copy link
Member Author

At what point should we review this PR properly? It looks like it's got some stuff for vector-of-vectors collections of inputs, but also some fixes for kronecker-structured covariance matrices. Is the intention that they be reviewed together, or done separately?

Apologies for this, all but the last commit are actually part of #369 , but I did not pay attention when branching and don't know enough about git to fix it. #369 should be ready to be reviewed.

For this commit, given that the expression towards fixing the issues, I will add them here "soon". I have solutions for the issues I found so far, but it is of course possible that more comes up.

@willtebbutt
Copy link
Member

No problem at all. Lets get 369 sort, then turn our attention back to this PR.

@Crown421
Copy link
Member Author

I understand that AbstractVector{AbstractVector{T}} inputs are not recommended

I don't think this is true at all, these inputs should work just as well!

The section that I am referring to is "We recommend that collections of vector-valued inputs are stored in an AbstractMatrix{<:Real} when possible," in the API section

@willtebbutt
Copy link
Member

@Crown421 is this the PR that you'd like eyes on next?

@Crown421
Copy link
Member Author

Crown421 commented Oct 6, 2021

@Crown421 is this the PR that you'd like eyes on next?

I think the answer is yes. I fixed the two issues that revealed themselves and extended tests pass again.

Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of minor queries -- I think this is broadly fine.

src/distances/delta.jl Outdated Show resolved Hide resolved
src/test_utils.jl Outdated Show resolved Hide resolved
Copy link
Member

@willtebbutt willtebbutt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Just needs a patch bump, then I'm happy for this to be merged.

@@ -133,6 +133,18 @@ function test_interface(
)
end

function test_interface(
rng::AbstractRNG, k::Kernel, ::Type{<:Vector{Vector{T}}}; dim_in=2, kwargs...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rng::AbstractRNG, k::Kernel, ::Type{<:Vector{Vector{T}}}; dim_in=2, kwargs...
rng::AbstractRNG, k::Kernel, ::Type{<:AbstractVector{<:AbstractVector{T}}}; dim_in=2, kwargs...

Sorry what's the reasoning for not using this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test itself utilises a Vector{Vector{T}}, so to my mind this type constraint better reflects what's going on 🤷

@Crown421 Crown421 merged commit 9f708d0 into JuliaGaussianProcesses:master Oct 6, 2021
@Crown421 Crown421 deleted the _mod-fix branch October 6, 2021 17:09
Comment on lines +4 to +6
@inline Distances.eval_op(::Delta, a::Real, b::Real) = a == b
@inline Distances.eval_reduce(::Delta, a, b) = a && b
@inline Distances.eval_start(::Delta, a, b) = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will result in much more complicated code, I don't think we should use the default dispatches in Distances and implement these internal functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just have to check x == y for the inputs x and y.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there even a reason to implement Distances._evaluate here? Isn't (::Delta)(x, y) sufficient?

@devmotion
Copy link
Member

Sorry, I missed this PR. I have some doubts about the changes to Delta, can we fix this in some other way by e.g. defining (::Delta)(x::AbstractVector{<:AbstractVector}, y::AbstractVector{<:AbstractVector}) instead (I assume the problem are vector of vectors as inputs, given the title of the PR)?

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

Successfully merging this pull request may close these issues.

4 participants