@@ -10,27 +10,27 @@ For `h=1/2`, this is the Wiener Kernel, for `h>1/2`, the increments are
1010positively correlated and for `h<1/2` the increments are negatively correlated.
1111"""
1212struct FBMKernel{T<: Real } <: BaseKernel
13- h:: T
13+ h:: Vector{T}
1414 function FBMKernel (; h:: T = 0.5 ) where {T<: Real }
1515 @assert h<= 1.0 && h>= 0.0 " FBMKernel: Given Hurst index h is invalid."
16- return new {T} (h )
16+ return new {T} ([h] )
1717 end
1818end
1919
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) ) )" )
2121
2222_fbm (modX, modY, modXY, h) = (modX^ h + modY^ h - modXY^ h)/ 2
2323
2424function kernelmatrix (κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
2525 @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) )
2727 modXX = pairwise (SqEuclidean (), X, dims = obsdim)
2828 return _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
2929end
3030
3131function kernelmatrix! (K:: AbstractMatrix , κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
3232 @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) )
3434 modXX = pairwise (SqEuclidean (), X, dims = obsdim)
3535 K .= _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
3636 return K
@@ -43,9 +43,9 @@ function kernelmatrix(
4343 obsdim:: Int = defaultobs,
4444)
4545 @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)
4949 return _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
5050end
5151
@@ -57,9 +57,9 @@ function kernelmatrix!(
5757 obsdim:: Int = defaultobs,
5858)
5959 @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)
6363 K .= _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
6464 return K
6565end
@@ -72,23 +72,15 @@ function _kernel(
7272 obsdim:: Int = defaultobs
7373 )
7474 @assert length (x) == length (y) " x and y don't have the same dimension!"
75- return κ (x, y)
75+ return kappa (κ, x, y)
7676end
7777
78- # Syntactic Sugar
79- function (κ:: FBMKernel )(x:: AbstractVector{<:Real} , y:: AbstractVector{<:Real} )
78+ function kappa (κ:: FBMKernel , x:: AbstractVector{<:Real} , y:: AbstractVector{<:Real} )
8079 modX = sum (abs2, x)
8180 modY = sum (abs2, y)
8281 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
8484end
8585
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