1
1
"""
2
- SqExponentialKernel()
2
+ SqExponentialKernel(; metric=Euclidean() )
3
3
4
- Squared exponential kernel.
4
+ Squared exponential kernel with respect to the `metric` .
5
5
6
6
# Definition
7
7
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
9
10
```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).
11
12
```
13
+ By default, ``d`` is the Euclidean metric ``d(x, x') = \\ |x - x'\\ |_2``.
12
14
13
15
See also: [`GammaExponentialKernel`](@ref)
14
16
"""
15
- struct SqExponentialKernel <: SimpleKernel end
17
+ struct SqExponentialKernel{M} <: SimpleKernel
18
+ metric:: M
16
19
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 )
18
27
19
- metric (:: SqExponentialKernel ) = SqEuclidean ()
28
+ metric (k:: SqExponentialKernel ) = k. metric
29
+ metric (:: SqExponentialKernel{<:Euclidean} ) = SqEuclidean ()
20
30
21
31
iskroncompatible (:: SqExponentialKernel ) = true
22
32
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
24
36
25
37
# # Aliases ##
26
38
@@ -46,28 +58,37 @@ Alias of [`SqExponentialKernel`](@ref).
46
58
const SEKernel = SqExponentialKernel
47
59
48
60
"""
49
- ExponentialKernel()
61
+ ExponentialKernel(; metric=Euclidean() )
50
62
51
- Exponential kernel.
63
+ Exponential kernel with respect to the `metric` .
52
64
53
65
# Definition
54
66
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
56
68
```math
57
- k(x, x') = \\ exp\\ big(- \\ |x - x' \\ |_2 \\ big).
69
+ k(x, x') = \\ exp\\ big(- d(x, x') \\ big).
58
70
```
71
+ By default, ``d`` is the Euclidean metric ``d(x, x') = \\ |x - x'\\ |_2``.
59
72
60
73
See also: [`GammaExponentialKernel`](@ref)
61
74
"""
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
63
82
64
83
kappa (:: ExponentialKernel , d:: Real ) = exp (- d)
65
84
66
- metric (:: ExponentialKernel ) = Euclidean ()
85
+ metric (k :: ExponentialKernel ) = k . metric
67
86
68
87
iskroncompatible (:: ExponentialKernel ) = true
69
88
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
71
92
72
93
# # Aliases ##
73
94
@@ -86,53 +107,44 @@ Alias of [`ExponentialKernel`](@ref).
86
107
const Matern12Kernel = ExponentialKernel
87
108
88
109
"""
89
- GammaExponentialKernel(; γ::Real=2.0 )
110
+ GammaExponentialKernel(; γ::Real=1.0, metric=Euclidean() )
90
111
91
- γ-exponential kernel with parameter `γ`.
112
+ γ-exponential kernel with respect to the `metric` and with parameter `γ`.
92
113
93
114
# Definition
94
115
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
97
119
```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).
99
121
```
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``.
104
123
105
124
See also: [`ExponentialKernel`](@ref), [`SqExponentialKernel`](@ref)
106
125
107
126
[^RW]: C. E. Rasmussen & C. K. I. Williams (2006). Gaussian Processes for Machine Learning.
108
127
"""
109
- struct GammaExponentialKernel{Tγ<: Real } <: SimpleKernel
128
+ struct GammaExponentialKernel{Tγ<: Real ,M } <: SimpleKernel
110
129
γ:: 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)
125
135
end
126
136
end
127
137
128
138
@functor GammaExponentialKernel
129
139
130
140
kappa (κ:: GammaExponentialKernel , d:: Real ) = exp (- d^ first (κ. γ))
131
141
132
- metric (:: GammaExponentialKernel ) = Euclidean ()
142
+ metric (k :: GammaExponentialKernel ) = k . metric
133
143
134
144
iskroncompatible (:: GammaExponentialKernel ) = true
135
145
136
146
function 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
+ )
138
150
end
0 commit comments