-
Notifications
You must be signed in to change notification settings - Fork 36
Adding Gibbskernel #374
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
Merged
devmotion
merged 28 commits into
JuliaGaussianProcesses:master
from
Cyberface:gibbskernel
Oct 1, 2021
Merged
Adding Gibbskernel #374
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d50f2b4
add gibbskernel.jl
Cyberface 2ca62f4
include gibbskernel.jl
Cyberface 2b83286
some modifications for gibbskernel and added a small test
Cyberface e4d1414
fix missing definition of ell function in test
Cyberface f9f066a
fix gibbskernel test
Cyberface d6b53b9
add gibbskernel to test/runtests.jl
Cyberface 698c453
Update test/kernels/gibbskernel.jl
Cyberface 3a98028
Update src/kernels/gibbskernel.jl
Cyberface 0f757a3
Update src/kernels/gibbskernel.jl
Cyberface 2e1df2d
implement changes based on PR discussion and update test
Cyberface b5c6faa
add brackets back in
Cyberface 19e6665
fix unit test for gibbs kernel
Cyberface 21de7d4
update gibbskernel test: implement theogf's idea about using a non-tr…
Cyberface 4ddafbe
ensure ell returns positive value in test
Cyberface 9fd1d14
gibbs kernel: fixed implementation and unittest
Cyberface 5531851
gibbs kernel: fix docstring
Cyberface 78faeac
Update src/kernels/gibbskernel.jl
Cyberface ae8b3d4
Update src/kernels/gibbskernel.jl
Cyberface 6b91a23
add gibbskernel to docs
Cyberface a914957
Update src/kernels/gibbskernel.jl
Cyberface 6eb4099
Update test/kernels/gibbskernel.jl
Cyberface 79aa4f5
gibbskernel test: formatting
Cyberface 0942447
Merge branch 'master' into gibbskernel
devmotion de3e535
Fix format (hopefully)
devmotion 0caf2fd
Add newline character
devmotion cfbca3d
Apply suggestions from code review
devmotion 1fb7903
Export invsqrt2
theogf f577700
Version bump
theogf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ CosineKernel | |
|
||
```@docs | ||
ExponentialKernel | ||
GibbsKernel | ||
LaplacianKernel | ||
SqExponentialKernel | ||
SEKernel | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
GibbsKernel(; lengthscale) | ||
|
||
# Definition | ||
|
||
The Gibbs kernel is non-stationary generalisation of the squared exponential | ||
kernel. The lengthscale parameter ``l`` becomes a function of | ||
position ``l(x)``. | ||
|
||
For a constant function``l(x) = c``, one recovers the standard squared exponential kernel | ||
with lengthscale `c`. | ||
|
||
```math | ||
k(x, y; l) = \\sqrt{ \\left(\\frac{2 l(x) l(y)}{l(x)^2 + l(y)^2} \\right) } | ||
\\quad \\rm{exp} \\left( - \\frac{(x - y)^2}{l(x)^2 + l(y)^2} \\right) | ||
``` | ||
|
||
# References | ||
|
||
Mark N. Gibbs. "Bayesian Gaussian Processes for Regression and Classication." PhD thesis, 1997 | ||
|
||
Christopher J. Paciorek and Mark J. Schervish. "Nonstationary Covariance Functions | ||
for Gaussian Process Regression". NeurIPS, 2003 | ||
|
||
Sami Remes, Markus Heinonen, Samuel Kaski. "Non-Stationary Spectral Kernels". arXiV:1705.08736, 2017 | ||
|
||
Cyberface marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Sami Remes, Markus Heinonen, Samuel Kaski. "Neural Non-Stationary Spectral Kernel". arXiv:1811.10978, 2018 | ||
""" | ||
struct GibbsKernel{T} <: Kernel | ||
lengthscale::T | ||
end | ||
|
||
GibbsKernel(; lengthscale) = GibbsKernel(lengthscale) | ||
|
||
function (k::GibbsKernel)(x, y) | ||
lengthscale = k.lengthscale | ||
lx = lengthscale(x) | ||
ly = lengthscale(y) | ||
l = invsqrt2 * hypot(lx, ly) | ||
kernel = (sqrt(lx * ly) / l) * with_lengthscale(SqExponentialKernel(), l) | ||
return kernel(x, y) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@testset "gibbskernel" begin | ||
x = randn() | ||
y = randn() | ||
|
||
# this is the gibbs lengthscale function. | ||
ell(x) = exp(sum(sin, x)) | ||
# create a gibbs kernel with our specific lengthscale function | ||
k_gibbs = GibbsKernel(ell) | ||
|
||
@test k_gibbs(x, y) ≈ | ||
sqrt((2 * ell(x) * ell(y)) / (ell(x)^2 + ell(y)^2)) * | ||
exp(-(x - y)^2 / (ell(x)^2 + ell(y)^2)) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.