@@ -33,45 +33,35 @@ const sqroundoff = 1e-15
33
33
34
34
_fbm (modX, modY, modXY, h) = (modX^ h + modY^ h - modXY^ h)/ 2
35
35
36
- function kernelmatrix (κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
37
- @assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
38
- modX = sum (abs2, X; dims = feature_dim (obsdim))
39
- modXX = pairwise (SqEuclidean (sqroundoff), X, dims = obsdim)
40
- return _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
36
+ _mod (x:: AbstractVector{<:Real} ) = abs2 .(x)
37
+ _mod (x:: ColVecs ) = vec (sum (abs2, x. X; dims= 1 ))
38
+ _mod (x:: RowVecs ) = vec (sum (abs2, x. X; dims= 2 ))
39
+
40
+ function kernelmatrix (κ:: FBMKernel , x:: AbstractVector )
41
+ modx = _mod (x)
42
+ modxx = pairwise (SqEuclidean (sqroundoff), x)
43
+ return _fbm .(modx, modx' , modxx, κ. h)
41
44
end
42
45
43
- function kernelmatrix! (K:: AbstractMatrix , κ:: FBMKernel , X:: AbstractMatrix ; obsdim:: Int = defaultobs)
44
- @assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
45
- modX = sum (abs2, X; dims = feature_dim (obsdim))
46
- modXX = pairwise (SqEuclidean (sqroundoff), X, dims = obsdim)
47
- K .= _fbm .(vec (modX), reshape (modX, 1 , :), modXX, κ. h)
46
+ function kernelmatrix! (K:: AbstractMatrix , κ:: FBMKernel , x:: AbstractVector )
47
+ modx = _mod (x)
48
+ modxx = pairwise (SqEuclidean (sqroundoff), x)
49
+ K .= _fbm .(modx, modx' , modxx, κ. h)
48
50
return K
49
51
end
50
52
51
- function kernelmatrix (
52
- κ:: FBMKernel ,
53
- X:: AbstractMatrix ,
54
- Y:: AbstractMatrix ;
55
- obsdim:: Int = defaultobs,
56
- )
57
- @assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
58
- modX = sum (abs2, X, dims = feature_dim (obsdim))
59
- modY = sum (abs2, Y, dims = feature_dim (obsdim))
60
- modXY = pairwise (SqEuclidean (sqroundoff), X, Y,dims = obsdim)
61
- return _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
53
+ function kernelmatrix (κ:: FBMKernel , x:: AbstractVector , y:: AbstractVector )
54
+ modxy = pairwise (SqEuclidean (sqroundoff), x, y)
55
+ return _fbm .(_mod (x), _mod (y)' , modxy, κ. h)
62
56
end
63
57
64
58
function kernelmatrix! (
65
59
K:: AbstractMatrix ,
66
60
κ:: FBMKernel ,
67
- X:: AbstractMatrix ,
68
- Y:: AbstractMatrix ;
69
- obsdim:: Int = defaultobs,
61
+ X:: AbstractVector ,
62
+ Y:: AbstractVector ,
70
63
)
71
- @assert obsdim ∈ [1 ,2 ] " obsdim should be 1 or 2 (see docs of kernelmatrix))"
72
- modX = sum (abs2, X, dims = feature_dim (obsdim))
73
- modY = sum (abs2, Y, dims = feature_dim (obsdim))
74
- modXY = pairwise (SqEuclidean (sqroundoff), X, Y,dims = obsdim)
75
- K .= _fbm .(vec (modX), reshape (modY, 1 , :), modXY, κ. h)
64
+ modxy = pairwise (SqEuclidean (sqroundoff), X, Y,dims = obsdim)
65
+ K .= _fbm .(_mod (x), _mod (y)' , modxy, κ. h)
76
66
return K
77
67
end
0 commit comments