From dda411812fd8048437e263750c377be53cd49e51 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 5 Nov 2021 23:58:03 +0000 Subject: [PATCH 1/2] Add example to PeriodicTransform on how it can be used to recreate a 1D PeriodicKernel. --- src/transform/periodic_transform.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/transform/periodic_transform.jl b/src/transform/periodic_transform.jl index 3430a63a1..cf9dff8e7 100644 --- a/src/transform/periodic_transform.jl +++ b/src/transform/periodic_transform.jl @@ -14,6 +14,21 @@ julia> f = rand(); t = PeriodicTransform(f); x = rand(); julia> t(x) == [sinpi(2 * f * x), cospi(2 * f * x)] true ``` + +For 1 dimensional inputs it is possible to create a kernel equivalent +to the `PeriodicKernel` using `PeriodicTransform` and a +`SqExponentialKernel`. + +```jldoctest +julia> wiggle_scale = 0.5; period = π/2; x = rand(); y = rand(); + +julia> k1 = with_lengthscale(PeriodicKernel(; r=[wiggle_scale / 2]), period); + +julia> k2 = with_lengthscale(SqExponentialKernel(), wiggle_scale) ∘ PeriodicTransform(1/period) + +julia> k1(x,y) ≈ k2(x,y) +true +``` """ struct PeriodicTransform{Tf<:AbstractVector{<:Real}} <: Transform f::Tf From 928b9ec08d1276832ce99d0f7e09899095a9d766 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 5 Nov 2021 23:59:17 +0000 Subject: [PATCH 2/2] Add with_period convenience function. --- src/transform/with_period.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/transform/with_period.jl diff --git a/src/transform/with_period.jl b/src/transform/with_period.jl new file mode 100644 index 000000000..446a00736 --- /dev/null +++ b/src/transform/with_period.jl @@ -0,0 +1,21 @@ +""" + with_period(kernel::Kernel, period::Real) + +Construct a transformed kernel with `period`. + +# Examples + +```jldoctest +julia> kernel = with_period(SqExponentialKernel(), π/2); + +julia> x = rand(); + +julia> y = rand(); + +julia> kernel(x, y) ≈ (SqExponentialKernel() ∘ PeriodicTransform(2/π))(x, y) +true +``` +""" +function with_period(kernel::Kernel, period::Real) + return kernel ∘ PeriodicTransform(inv(period)) +end