Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions src/transform/periodic_transform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/transform/with_period.jl
Original file line number Diff line number Diff line change
@@ -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))

Check warning on line 20 in src/transform/with_period.jl

View check run for this annotation

Codecov / codecov/patch

src/transform/with_period.jl#L19-L20

Added lines #L19 - L20 were not covered by tests
end