Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add KernelTensorSum #507

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

Open
martincornejo wants to merge 11 commits into JuliaGaussianProcesses:master
base: master
Choose a base branch
Loading
from martincornejo:kernel-tensor-sum
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve coverage and error message of `validate_domain(::KernelTensor...
...Sum, ...)`
  • Loading branch information
martincornejo committed May 10, 2023
commit a39f81fdb902ca33a85b0158e9e1954f4b8d4e87
19 changes: 12 additions & 7 deletions src/kernels/kerneltensorsum.jl
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ end
Base.length(kernel::KernelTensorSum) = length(kernel.kernels)

function (kernel::KernelTensorSum)(x, y)
if !(length(x) == length(y) == length(kernel))
throw(DimensionMismatch("number of kernels and number of features
are not consistent"))
if !((nx = length(x)) == (ny = length(y)) == (nkernerls = length(k)))
throw(DimensionMismatch("number of kernels ($nkernels) and number of features
(x=$nx, y=$ny) are not consistent"))
end
return sum(k(xi, yi) for (k, xi, yi) in zip(kernel.kernels, x, y))
end

function validate_domain(k::KernelTensorSum, x::AbstractVector, y::AbstractVector)
return (dx = dim(x)) == (dy = dim(y)) == (nkernels = length(k)) || error(
"number of kernels ($nkernels) and group of features (x=$dx), y=$dy) are not consistent",
)
end

function validate_domain(k::KernelTensorSum, x::AbstractVector)
return dim(x) == length(k) ||
error("number of kernels and groups of features are not consistent")
return validate_domain(k, x, x)
end

function kernelmatrix(k::KernelTensorSum, x::AbstractVector)
Expand All @@ -67,7 +72,7 @@ function kernelmatrix(k::KernelTensorSum, x::AbstractVector)
end

function kernelmatrix(k::KernelTensorSum, x::AbstractVector, y::AbstractVector)
validate_domain(k, x)
validate_domain(k, x, y)
return mapreduce(kernelmatrix, +, k.kernels, slices(x), slices(y))
end

Expand All @@ -77,7 +82,7 @@ function kernelmatrix_diag(k::KernelTensorSum, x::AbstractVector)
end

function kernelmatrix_diag(k::KernelTensorSum, x::AbstractVector, y::AbstractVector)
validate_domain(k, x)
validate_domain(k, x, y)
return mapreduce(kernelmatrix_diag, +, k.kernels, slices(x), slices(y))
end

Expand Down

AltStyle によって変換されたページ (->オリジナル) /