-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: willtebbutt <wct23@cam.ac.uk> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ST John <st--@users.noreply.github.com>
- Loading branch information
1 parent
58cb069
commit 2181649
Showing
7 changed files
with
76 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -36,3 +36,9 @@ SelectTransform | |
ChainTransform | ||
PeriodicTransform | ||
``` | ||
|
||
## Convenience functions | ||
|
||
```@docs | ||
with_lengthscale | ||
``` |
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,43 @@ | ||
""" | ||
with_lengthscale(kernel::Kernel, lengthscale::Real) | ||
Construct a transformed kernel with `lengthscale`. | ||
# Examples | ||
```jldoctest | ||
julia> kernel = with_lengthscale(SqExponentialKernel(), 2.5); | ||
julia> x = rand(2); | ||
julia> y = rand(2); | ||
julia> kernel(x, y) ≈ (SqExponentialKernel() ∘ ScaleTransform(0.4))(x, y) | ||
true | ||
``` | ||
""" | ||
function with_lengthscale(kernel::Kernel, lengthscale::Real) | ||
return kernel ∘ ScaleTransform(inv(lengthscale)) | ||
end | ||
|
||
""" | ||
with_lengthscale(kernel::Kernel, lengthscales::AbstractVector{<:Real}) | ||
Construct a transformed "ARD" kernel with different `lengthscales` for each dimension. | ||
# Examples | ||
```jldoctest | ||
julia> kernel = with_lengthscale(SqExponentialKernel(), [0.5, 2.5]); | ||
julia> x = rand(2); | ||
julia> y = rand(2); | ||
julia> kernel(x, y) ≈ (SqExponentialKernel() ∘ ARDTransform([2, 0.4]))(x, y) | ||
true | ||
``` | ||
""" | ||
function with_lengthscale(kernel::Kernel, lengthscales::AbstractVector{<:Real}) | ||
return kernel ∘ ARDTransform(map(inv, lengthscales)) | ||
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@testset "with_lengthscale" begin | ||
@testset "ScaleTransform" begin | ||
l = exp(rand()) | ||
kernel = @inferred(with_lengthscale(SqExponentialKernel(), l)) | ||
|
||
@test kernel isa TransformedKernel{<:SqExponentialKernel,<:ScaleTransform} | ||
@test kernel.transform.s[1] ≈ inv(l) | ||
end | ||
|
||
@testset "ARDTransform" begin | ||
l = map(exp, rand(5)) | ||
kernel = @inferred(with_lengthscale(SqExponentialKernel(), l)) | ||
|
||
@test kernel isa TransformedKernel{<:SqExponentialKernel,<:ARDTransform} | ||
@test kernel.transform.v ≈ map(inv, l) | ||
end | ||
end |
2181649
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
2181649
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/40659
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: