19
19
20
20
Base. show (io:: IO , κ:: FBMKernel ) = print (io, " Fractional Brownian Motion Kernel (h = $(first (k. h)) )" )
21
21
22
- _fbm (modX, modY, modXY, h) = (modX^ h + modY^ h - abs (modXY)^ h)/ 2
22
+ const sqroundoff = 1e-15
23
+
24
+ _fbm (modX, modY, modXY, h) = (modX^ h + modY^ h - modXY^ h)/ 2
23
25
24
26
function kernelmatrix (κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
25
27
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
26
28
modX = sum (abs2, X; dims = feature_dim (obsdim))
27
- modXX = pairwise (SqEuclidean (), X, dims = obsdim)
29
+ modXX = pairwise (SqEuclidean (sqroundoff ), X, dims = obsdim)
28
30
return _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
29
31
end
30
32
31
33
function kernelmatrix! (K:: AbstractMatrix , κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
32
34
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
33
35
modX = sum (abs2, X; dims = feature_dim (obsdim))
34
- modXX = pairwise (SqEuclidean (), X, dims = obsdim)
36
+ modXX = pairwise (SqEuclidean (sqroundoff ), X, dims = obsdim)
35
37
K .= _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
36
38
return K
37
39
end
@@ -45,7 +47,7 @@ function kernelmatrix(
45
47
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
46
48
modX = sum (abs2, X, dims = feature_dim (obsdim))
47
49
modY = sum (abs2, Y, dims = feature_dim (obsdim))
48
- modXY = pairwise (SqEuclidean (), X, Y,dims = obsdim)
50
+ modXY = pairwise (SqEuclidean (sqroundoff ), X, Y,dims = obsdim)
49
51
return _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
50
52
end
51
53
@@ -59,7 +61,7 @@ function kernelmatrix!(
59
61
@assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
60
62
modX = sum (abs2, X, dims = feature_dim (obsdim))
61
63
modY = sum (abs2, Y, dims = feature_dim (obsdim))
62
- modXY = pairwise (SqEuclidean (), X, Y,dims = obsdim)
64
+ modXY = pairwise (SqEuclidean (sqroundoff ), X, Y,dims = obsdim)
63
65
K .= _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
64
66
return K
65
67
end
78
80
function kappa (κ:: FBMKernel , x:: AbstractVector{<:Real} , y:: AbstractVector{<:Real} )
79
81
modX = sum (abs2, x)
80
82
modY = sum (abs2, y)
81
- modXY = sqeuclidean ( x, y)
83
+ modXY = evaluate ( SqEuclidean (sqroundoff), x, y)
82
84
h = first (κ. h)
83
85
return (modX^ h + modY^ h - modXY^ h)/ 2
84
86
end
0 commit comments