11"""
2- SqExponentialKernel()
2+ SqExponentialKernel(; metric=Euclidean() )
33
4- Squared exponential kernel.
4+ Squared exponential kernel with respect to the `metric` .
55
66# Definition
77
8- For inputs ``x, x' \\ in \\ mathbb{R}^d``, the squared exponential kernel is defined as
8+ For inputs ``x, x'`` and metric ``d(\\ cdot, \\ cdot)``, the squared exponential kernel is
9+ defined as
910```math
10- k(x, x') = \\ exp\\ bigg(- \\ frac{\\ |x - x' \\ |_2 ^2}{2}\\ bigg).
11+ k(x, x') = \\ exp\\ bigg(- \\ frac{d(x, x') ^2}{2}\\ bigg).
1112```
13+ By default, ``d`` is the Euclidean metric ``d(x, x') = \\ |x - x'\\ |_2``.
1214
1315See also: [`GammaExponentialKernel`](@ref)
1416"""
15- struct SqExponentialKernel <: SimpleKernel end
17+ struct SqExponentialKernel{M} <: SimpleKernel
18+ metric:: M
1619
17- kappa (:: SqExponentialKernel , d²:: Real ) = exp (- d² / 2 )
20+ function SqExponentialKernel (; metric= Euclidean ())
21+ return new {typeof(metric)} (metric)
22+ end
23+ end
24+
25+ kappa (:: SqExponentialKernel , d:: Real ) = exp (- d^ 2 / 2 )
26+ kappa (:: SqExponentialKernel{<:Euclidean} , d²:: Real ) = exp (- d² / 2 )
1827
19- metric (:: SqExponentialKernel ) = SqEuclidean ()
28+ metric (k:: SqExponentialKernel ) = k. metric
29+ metric (:: SqExponentialKernel{<:Euclidean} ) = SqEuclidean ()
2030
2131iskroncompatible (:: SqExponentialKernel ) = true
2232
23- Base. show (io:: IO , :: SqExponentialKernel ) = print (io, " Squared Exponential Kernel" )
33+ function Base. show (io:: IO , k:: SqExponentialKernel )
34+ return print (io, " Squared Exponential Kernel (metric = " , k. metric, " )" )
35+ end
2436
2537# # Aliases ##
2638
@@ -46,28 +58,37 @@ Alias of [`SqExponentialKernel`](@ref).
4658const SEKernel = SqExponentialKernel
4759
4860"""
49- ExponentialKernel()
61+ ExponentialKernel(; metric=Euclidean() )
5062
51- Exponential kernel.
63+ Exponential kernel with respect to the `metric` .
5264
5365# Definition
5466
55- For inputs ``x, x' \\ in \\ mathbb{R}^d ``, the exponential kernel is defined as
67+ For inputs ``x, x'`` and metric ``d( \\ cdot, \\ cdot) ``, the exponential kernel is defined as
5668```math
57- k(x, x') = \\ exp\\ big(- \\ |x - x' \\ |_2 \\ big).
69+ k(x, x') = \\ exp\\ big(- d(x, x') \\ big).
5870```
71+ By default, ``d`` is the Euclidean metric ``d(x, x') = \\ |x - x'\\ |_2``.
5972
6073See also: [`GammaExponentialKernel`](@ref)
6174"""
62- struct ExponentialKernel <: SimpleKernel end
75+ struct ExponentialKernel{M} <: SimpleKernel
76+ metric:: M
77+
78+ function ExponentialKernel (; metric= Euclidean ())
79+ return new {typeof(metric)} (metric)
80+ end
81+ end
6382
6483kappa (:: ExponentialKernel , d:: Real ) = exp (- d)
6584
66- metric (:: ExponentialKernel ) = Euclidean ()
85+ metric (k :: ExponentialKernel ) = k . metric
6786
6887iskroncompatible (:: ExponentialKernel ) = true
6988
70- Base. show (io:: IO , :: ExponentialKernel ) = print (io, " Exponential Kernel" )
89+ function Base. show (io:: IO , k:: ExponentialKernel )
90+ return print (io, " Exponential Kernel (metric = " , k. metric, " )" )
91+ end
7192
7293# # Aliases ##
7394
@@ -86,53 +107,44 @@ Alias of [`ExponentialKernel`](@ref).
86107const Matern12Kernel = ExponentialKernel
87108
88109"""
89- GammaExponentialKernel(; γ::Real=2.0 )
110+ GammaExponentialKernel(; γ::Real=1.0, metric=Euclidean() )
90111
91- γ-exponential kernel with parameter `γ`.
112+ γ-exponential kernel with respect to the `metric` and with parameter `γ`.
92113
93114# Definition
94115
95- For inputs ``x, x' \\ in \\ mathbb{R}^d``, the γ-exponential kernel[^RW] with parameter
96- ``\\ gamma \\ in (0, 2]`` is defined as
116+ For inputs ``x, x'`` and metric ``d(\\ cdot, \\ cdot)``, the γ-exponential kernel[^RW] with
117+ parameter ``\\ gamma \\ in (0, 2]``
118+ is defined as
97119```math
98- k(x, x'; \\ gamma) = \\ exp\\ big(- \\ |x - x' \\ |_2 ^{\\ gamma}\\ big).
120+ k(x, x'; \\ gamma) = \\ exp\\ big(- d(x, x') ^{\\ gamma}\\ big).
99121```
100-
101- !!! warning
102- The default value of parameter `γ` will be changed to `1.0` in the next breaking release
103- of KernelFunctions.
122+ By default, ``d`` is the Euclidean metric ``d(x, x') = \\ |x - x'\\ |_2``.
104123
105124See also: [`ExponentialKernel`](@ref), [`SqExponentialKernel`](@ref)
106125
107126[^RW]: C. E. Rasmussen & C. K. I. Williams (2006). Gaussian Processes for Machine Learning.
108127"""
109- struct GammaExponentialKernel{Tγ<: Real } <: SimpleKernel
128+ struct GammaExponentialKernel{Tγ<: Real ,M } <: SimpleKernel
110129 γ:: Vector{Tγ}
111- # function GammaExponentialKernel(; gamma::Real=1.0, γ::Real=gamma)
112- function GammaExponentialKernel (; gamma= nothing , γ= gamma)
113- γ2 = if γ === nothing
114- Base. depwarn (
115- " the default value of parameter `γ` of the `GammaExponentialKernel` will " *
116- " be changed to `1.0` in the next breaking release of KernelFunctions" ,
117- :GammaExponentialKernel ,
118- )
119- 2.0
120- else
121- γ
122- end
123- @check_args (GammaExponentialKernel, γ2, zero (γ2) < γ2 ≤ 2 , " γ ∈ (0, 2]" )
124- return new {typeof(γ2)} ([γ2])
130+ metric:: M
131+
132+ function GammaExponentialKernel (; gamma:: Real = 1.0 , γ:: Real = gamma, metric= Euclidean ())
133+ @check_args (GammaExponentialKernel, γ, zero (γ) < γ ≤ 2 , " γ ∈ (0, 2]" )
134+ return new {typeof(γ),typeof(metric)} ([γ], metric)
125135 end
126136end
127137
128138@functor GammaExponentialKernel
129139
130140kappa (κ:: GammaExponentialKernel , d:: Real ) = exp (- d^ first (κ. γ))
131141
132- metric (:: GammaExponentialKernel ) = Euclidean ()
142+ metric (k :: GammaExponentialKernel ) = k . metric
133143
134144iskroncompatible (:: GammaExponentialKernel ) = true
135145
136146function Base. show (io:: IO , κ:: GammaExponentialKernel )
137- return print (io, " Gamma Exponential Kernel (γ = " , first (κ. γ), " )" )
147+ return print (
148+ io, " Gamma Exponential Kernel (γ = " , first (κ. γ), " , metric = " , κ. metric, " )"
149+ )
138150end
0 commit comments