-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add InverseMultiQuadricKernel
#396
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,3 +139,71 @@ function Base.show(io::IO, κ::GammaRationalKernel) | |
")", | ||
) | ||
end | ||
|
||
@doc raw""" | ||
InverseMultiQuadricKernel(; α::Real=1.0, c::Real=1.0, metric=Euclidean()) | ||
|
||
Inverse multiquadric kernel with respect to the `metric` with parameters `α` and `c`. | ||
|
||
# Definition | ||
|
||
For inputs ``x, x'`` and metric ``d(\cdot, \cdot)``, the inverse multiquadric kernel with | ||
parameters ``\alpha, c > 0`` is defined as | ||
```math | ||
k(x, x'; \alpha, c) = \big(c + d(x, x')^2\big)^{-\alpha}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at this, it looks extremely similar to the polynomial kernel (except for -alpha < 0). Could this eventually be unified? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it is more similar to the rational quadratic kernel, therefore I put it in this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the tests show it is the same as scaling an RQ kernel with rescaled inputs. The construction is a bit annoying though, so the question is more: should it be a separate kernel or a function that constructs the corresponding RQ kernel? |
||
``` | ||
By default, ``d`` is the Euclidean metric ``d(x, x') = \|x - x'\|_2``. | ||
|
||
For ``\alpha = c = 1``, the [`GammaRationalKernel`](@ref) with parameters ``\alpha = 1`` | ||
and ``\gamma = 2`` is recovered. | ||
|
||
For ``\alpha = 1/2`` and ``c = 1``, the [`RationalQuadraticKernel`](@ref) with parameter | ||
``\alpha = 1/2`` is recovered. | ||
|
||
# References | ||
|
||
Micchelli, C.A. (1986). Interpolation of scattered data: Distance matrices and conditionally | ||
positive definite functions. Constructive Approximation 2, 11-22. | ||
""" | ||
struct InverseMultiQuadricKernel{Tα<:Real,Tc<:Real,M} <: SimpleKernel | ||
α::Vector{Tα} | ||
theogf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
c::Vector{Tc} | ||
metric::M | ||
|
||
function InverseMultiQuadricKernel(α::Real, c::Real, metric) | ||
@check_args(InverseMultiQuadricKernel, α, α > zero(α), "α > 0") | ||
@check_args(InverseMultiQuadricKernel, c, c > zero(c), "c > 0") | ||
return new{typeof(α),typeof(c),typeof(metric)}([α], [c], metric) | ||
end | ||
end | ||
|
||
function InverseMultiQuadricKernel(; | ||
alpha::Real=1.0, α::Real=alpha, c::Real=1.0, metric=Euclidean() | ||
) | ||
return InverseMultiQuadricKernel(α, c, metric) | ||
end | ||
|
||
@functor InverseMultiQuadricKernel | ||
|
||
function kappa(k::InverseMultiQuadricKernel, d::Real) | ||
return (first(k.c) + d^2)^(-first(k.α)) | ||
end | ||
function kappa(k::InverseMultiQuadricKernel{<:Real,<:Real,<:Euclidean}, d2::Real) | ||
return (first(k.c) + d2)^(-first(k.α)) | ||
end | ||
|
||
metric(k::InverseMultiQuadricKernel) = k.metric | ||
metric(::InverseMultiQuadricKernel{<:Real,<:Real,<:Euclidean}) = SqEuclidean() | ||
|
||
function Base.show(io::IO, k::InverseMultiQuadricKernel) | ||
return print( | ||
io, | ||
"Inverse Multiquadric Kernel (α = ", | ||
first(k.α), | ||
", c = ", | ||
first(k.c), | ||
", metric = ", | ||
k.metric, | ||
")", | ||
) | ||
end |
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.
I don't think this sentence is needed, it does not bring anything
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.
Yes, I guess one has to know at least what the inverse multiquadric kernel is. However, the same problem exists in all other docstrings. I added this sentence only to be consistent with them.