-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add matern kernel and lean more on Distributions.jl (#16)
* Start on new abstraction * Start rewrite test files for easier spot testing, add matern file * Add matern kernel, rewrite things in terms of distributions * Start implementing MvTDist * Forgot main file * Move dimension handing to base functions * More steps towards MvTDist * Use undocumented MvTDist * Improve tests * Fix tests for matern kernel * Remove SpecialFunctions again * Adjust squared exponential to new format * Some cleanup * Add compat entries * Fix base tests * Fix test script * Small fix * More test fixes * Remove obsolte fallback
- Loading branch information
Showing
13 changed files
with
269 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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 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 @@ | ||
|
This file contains 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 @@ | ||
|
This file contains 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 @@ | ||
|
This file contains 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 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 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 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,24 @@ | ||
|
||
################################################### | ||
## Matern Kernels | ||
|
||
MaternKernels = Union{MaternKernel,Matern32Kernel,Matern52Kernel} | ||
|
||
_matern_order(k::MaternKernel) = only(k.ν) | ||
_matern_order(::Matern32Kernel) = 3 / 2 | ||
_matern_order(::Matern52Kernel) = 5 / 2 | ||
|
||
# rewrite everything as returning a distribution (kind of as originally planned) | ||
# should be able to abstract/ generalize a lot of the special casing | ||
function _spectral_distribution(kernel::MaternKernels, l::Real) | ||
ν = _matern_order(kernel) | ||
return inv(2 * π * l) * TDist(2 * ν) | ||
end | ||
|
||
function _spectral_distribution(kernel::MaternKernels, l::AbstractVector) | ||
ν = _matern_order(kernel) | ||
n = length(l) | ||
l = inv.(2 * π * l) .^ 2 | ||
D = Distributions.MvTDist(2 * ν, zeros(n), diagm(l)) | ||
return D | ||
end |
This file contains 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 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 |
---|---|---|
@@ -1,36 +1,48 @@ | ||
if (!@isdefined RUN_TESTS) || !RUN_TESTS | ||
using CairoMakie | ||
show_plot = true | ||
include("test_utils.jl") | ||
else | ||
show_plot = false | ||
end | ||
|
||
@testset "SquaredExponential Kernel" begin | ||
ker = SqExponentialKernel() | ||
@testset "1D" begin | ||
@testset "Pure" begin | ||
w_interval = [-2.0, 2.0] | ||
# ker = SqExponentialKernel() | ||
w_interval = 2.0 | ||
t_interval = [0.0, 4.0] | ||
|
||
f = test_spectral_density(ker, w_interval, t_interval) | ||
test_spectral_density(ker, w_interval, t_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
ker = with_lengthscale(SqExponentialKernel(), 0.7) | ||
w_interval = [-2.0, 2.0] | ||
# ker = SqExponentialKernel() | ||
kert = with_lengthscale(ker, 0.7) | ||
w_interval = 2.0 | ||
t_interval = [0.0, 4.0] | ||
|
||
f = test_spectral_density(ker, w_interval, t_interval) | ||
f = test_spectral_density(kert, w_interval, t_interval; show_plot) | ||
end | ||
end | ||
|
||
@testset "2D" begin | ||
@testset "Pure" begin | ||
# ker = SqExponentialKernel() | ||
w_interval = [-2.0, 2.0] | ||
x_interval = [-2.0, 2.0] | ||
|
||
f = test_2Dspectral_density(ker, w_interval, x_interval) | ||
f = test_2Dspectral_density(ker, w_interval, x_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
ker = with_lengthscale(SqExponentialKernel(), 0.7) | ||
# ker = SqExponentialKernel() | ||
kert = with_lengthscale(ker, 0.7) | ||
w_interval = [-2.0, 2.0] | ||
x_interval = [-2.0, 2.0] | ||
|
||
f = test_2Dspectral_density(ker, w_interval, x_interval) | ||
f = test_2Dspectral_density(kert, w_interval, x_interval; show_plot) | ||
end | ||
end | ||
end |
This file contains 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,128 @@ | ||
if (!@isdefined RUN_TESTS) || !RUN_TESTS | ||
using CairoMakie | ||
show_plot = true | ||
include("test_utils.jl") | ||
else | ||
show_plot = false | ||
end | ||
|
||
@testset "Matern32" begin | ||
ker = Matern32Kernel() | ||
@testset "1D" begin | ||
@testset "Pure" begin | ||
w_interval = 1.5 | ||
t_interval = [0.0, 4.0] | ||
|
||
test_spectral_density(ker, w_interval, t_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
# ker = Matern32Kernel() | ||
kert = with_lengthscale(ker, 0.7) | ||
w_interval = 2.0 | ||
t_interval = [0.0, 3.5] | ||
|
||
test_spectral_density(kert, w_interval, t_interval; show_plot) | ||
end | ||
end | ||
|
||
@testset "2D" begin | ||
@testset "Pure" begin | ||
ker = Matern32Kernel() | ||
w_interval = [-1.5, 1.5] | ||
x_interval = [-3.0, 3.0] | ||
|
||
test_2Dspectral_density(ker, w_interval, x_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
# ker = Matern32Kernel() | ||
kert = with_lengthscale(ker, 0.6) | ||
w_interval = [-2.0, 2.0] | ||
x_interval = [-3.5, 3.5] | ||
|
||
f = test_2Dspectral_density(kert, w_interval, x_interval; show_plot) | ||
end | ||
end | ||
end | ||
|
||
@testset "Matern52" begin | ||
ker = Matern52Kernel() | ||
@testset "1D" begin | ||
@testset "Pure" begin | ||
# ker = Matern52Kernel() | ||
w_interval = 1.0 | ||
t_interval = [0.0, 4.0] | ||
|
||
test_spectral_density(ker, w_interval, t_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
# ker = Matern52Kernel() | ||
kert = with_lengthscale(ker, 0.7) | ||
w_interval = 1.5 | ||
t_interval = [0.0, 3.5] | ||
|
||
test_spectral_density(kert, w_interval, t_interval; show_plot) | ||
end | ||
end | ||
|
||
@testset "2D" begin | ||
@testset "Pure" begin | ||
# ker = Matern52Kernel() | ||
w_interval = [-1.1, 1.1] | ||
x_interval = [-3.0, 3.0] | ||
|
||
test_2Dspectral_density(ker, w_interval, x_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
# ker = Matern52Kernel() | ||
kert = with_lengthscale(ker, 0.6) | ||
w_interval = [-2.0, 2.0] | ||
x_interval = [-3.5, 3.5] | ||
|
||
f = test_2Dspectral_density(kert, w_interval, x_interval; show_plot) | ||
end | ||
end | ||
end | ||
|
||
@testset "Matern72" begin | ||
ker = MaternKernel(; ν=7 / 2) | ||
@testset "1D" begin | ||
@testset "Pure" begin | ||
# ker = MaternKernel(; ν=7 / 2) | ||
w_interval = 1.0 | ||
t_interval = [0.0, 6.0] | ||
|
||
test_spectral_density(ker, w_interval, t_interval; show_plot) | ||
end | ||
|
||
@testset "Scaled" begin | ||
# ker = MaternKernel(; ν=7 / 2) | ||
kert = with_lengthscale(ker, 0.7) | ||
w_interval = 1.2 | ||
t_interval = [0.0, 3.5] | ||
|
||
test_spectral_density(kert, w_interval, t_interval; show_plot) | ||
end | ||
end | ||
|
||
@testset "2D" begin | ||
@testset "Pure" begin | ||
# ker = MaternKernel(; ν=7 / 2) | ||
w_interval = [-1.1, 1.1] | ||
x_interval = [-3.0, 3.0] | ||
|
||
test_2Dspectral_density(ker, w_interval, x_interval; show_plot) | ||
end | ||
end | ||
@testset "Scaled" begin | ||
# ker = MaternKernel(; ν=7 / 2) | ||
kert = with_lengthscale(ker, 0.6) | ||
w_interval = [-2.0, 2.0] | ||
x_interval = [-3.5, 3.5] | ||
|
||
f = test_2Dspectral_density(kert, w_interval, x_interval; show_plot) | ||
end | ||
end |
Oops, something went wrong.
e3dc9a5
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.
@JuliaRegistrator register
e3dc9a5
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.
Registration pull request created: JuliaRegistries/General/109118
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: