@@ -10,27 +10,27 @@ For `h=1/2`, this is the Wiener Kernel, for `h>1/2`, the increments are
10
10
positively correlated and for `h<1/2` the increments are negatively correlated.
11
11
"""
12
12
struct FBMKernel{T<: Real } <: BaseKernel
13
- h:: T
13
+ h:: Vector{T}
14
14
function FBMKernel (; h:: T = 0.5 ) where {T<: Real }
15
15
@assert h<= 1.0 && h>= 0.0 " FBMKernel: Given Hurst index h is invalid."
16
- return new {T} (h )
16
+ return new {T} ([h] )
17
17
end
18
18
end
19
19
20
- Base. show (io:: IO , κ:: FBMKernel ) = print (io, " Fractional Brownian Motion Kernel (h = $(k. h) )" )
20
+ Base. show (io:: IO , κ:: FBMKernel ) = print (io, " Fractional Brownian Motion Kernel (h = $(first ( k. h) ) )" )
21
21
22
22
_fbm (modX, modY, modXY, h) = (modX^ h + modY^ h - modXY^ h)/ 2
23
23
24
24
function kernelmatrix (κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
25
25
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
26
- modX = sum (abs2, X; dims = 3 - obsdim)
26
+ modX = sum (abs2, X; dims = feature_dim ( obsdim) )
27
27
modXX = pairwise (SqEuclidean (), X, dims = obsdim)
28
28
return _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
29
29
end
30
30
31
31
function kernelmatrix! (K:: AbstractMatrix , κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
32
32
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
33
- modX = sum (abs2, X; dims = 3 - obsdim)
33
+ modX = sum (abs2, X; dims = feature_dim ( obsdim) )
34
34
modXX = pairwise (SqEuclidean (), X, dims = obsdim)
35
35
K .= _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
36
36
return K
@@ -43,9 +43,9 @@ function kernelmatrix(
43
43
obsdim:: Int = defaultobs,
44
44
)
45
45
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
46
- modX = sum (abs2, X, dims= 3 - obsdim)
47
- modY = sum (abs2, Y, dims= 3 - obsdim)
48
- modXY = pairwise (SqEuclidean (), X, Y,dims= obsdim)
46
+ modX = sum (abs2, X, dims = feature_dim ( obsdim) )
47
+ modY = sum (abs2, Y, dims = feature_dim ( obsdim) )
48
+ modXY = pairwise (SqEuclidean (), X, Y,dims = obsdim)
49
49
return _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
50
50
end
51
51
@@ -57,9 +57,9 @@ function kernelmatrix!(
57
57
obsdim:: Int = defaultobs,
58
58
)
59
59
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
60
- modX = sum (abs2, X, dims= 3 - obsdim)
61
- modY = sum (abs2, Y, dims= 3 - obsdim)
62
- modXY = pairwise (SqEuclidean (), X, Y,dims= obsdim)
60
+ modX = sum (abs2, X, dims = feature_dim ( obsdim) )
61
+ modY = sum (abs2, Y, dims = feature_dim ( obsdim) )
62
+ modXY = pairwise (SqEuclidean (), X, Y,dims = obsdim)
63
63
K .= _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
64
64
return K
65
65
end
@@ -72,23 +72,15 @@ function _kernel(
72
72
obsdim:: Int = defaultobs
73
73
)
74
74
@assert length (x) == length (y) " x and y don't have the same dimension!"
75
- return κ (x, y)
75
+ return kappa (κ, x, y)
76
76
end
77
77
78
- # Syntactic Sugar
79
- function (κ:: FBMKernel )(x:: AbstractVector{<:Real} , y:: AbstractVector{<:Real} )
78
+ function kappa (κ:: FBMKernel , x:: AbstractVector{<:Real} , y:: AbstractVector{<:Real} )
80
79
modX = sum (abs2, x)
81
80
modY = sum (abs2, y)
82
81
modXY = sqeuclidean (x, y)
83
- return (modX^ κ. h + modY^ κ. h - modXY^ κ. h)/ 2
82
+ h = first (κ. h)
83
+ return (modX^ h + modY^ h - modXY^ h)/ 2
84
84
end
85
85
86
- (κ:: FBMKernel )(x:: Real , y:: Real ) = (abs2 (x)^ κ. h + abs2 (y)^ κ. h - abs2 (x- y)^ κ. h)/ 2
87
-
88
- function (κ:: FBMKernel )(X:: AbstractMatrix{<:Real} , Y:: AbstractMatrix{<:Real} ; obsdim:: Integer = defaultobs)
89
- return kernelmatrix (κ, X, Y, obsdim= obsdim)
90
- end
91
-
92
- function (κ:: FBMKernel )(X:: AbstractMatrix{<:Real} ; obsdim:: Integer = defaultobs)
93
- return kernelmatrix (κ, X, obsdim= obsdim)
94
- end
86
+ (κ:: FBMKernel )(x:: Real , y:: Real ) = (abs2 (x)^ first (κ. h) + abs2 (y)^ first (κ. h) - abs2 (x- y)^ first (κ. h))/ 2
0 commit comments