Skip to content

Commit b8f7e82

Browse files
committed
Put roundoff for SqEuclidean
1 parent 8644d9a commit b8f7e82

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/kernels/fbm.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ end
1919

2020
Base.show(io::IO, κ::FBMKernel) = print(io, "Fractional Brownian Motion Kernel (h = $(first(k.h)))")
2121

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
2325

2426
function kernelmatrix::FBMKernel, X::AbstractMatrix; obsdim::Int = defaultobs)
2527
@assert obsdim [1,2] "obsdim should be 1 or 2 (see docs of kernelmatrix))"
2628
modX = sum(abs2, X; dims = feature_dim(obsdim))
27-
modXX = pairwise(SqEuclidean(), X, dims = obsdim)
29+
modXX = pairwise(SqEuclidean(sqroundoff), X, dims = obsdim)
2830
return _fbm.(vec(modX), reshape(modX, 1, :), modXX, κ.h)
2931
end
3032

3133
function kernelmatrix!(K::AbstractMatrix, κ::FBMKernel, X::AbstractMatrix; obsdim::Int = defaultobs)
3234
@assert obsdim [1,2] "obsdim should be 1 or 2 (see docs of kernelmatrix))"
3335
modX = sum(abs2, X; dims = feature_dim(obsdim))
34-
modXX = pairwise(SqEuclidean(), X, dims = obsdim)
36+
modXX = pairwise(SqEuclidean(sqroundoff), X, dims = obsdim)
3537
K .= _fbm.(vec(modX), reshape(modX, 1, :), modXX, κ.h)
3638
return K
3739
end
@@ -45,7 +47,7 @@ function kernelmatrix(
4547
@assert obsdim [1,2] "obsdim should be 1 or 2 (see docs of kernelmatrix))"
4648
modX = sum(abs2, X, dims = feature_dim(obsdim))
4749
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)
4951
return _fbm.(vec(modX), reshape(modY, 1, :), modXY, κ.h)
5052
end
5153

@@ -59,7 +61,7 @@ function kernelmatrix!(
5961
@assert obsdim [1,2] "obsdim should be 1 or 2 (see docs of kernelmatrix))"
6062
modX = sum(abs2, X, dims = feature_dim(obsdim))
6163
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)
6365
K .= _fbm.(vec(modX), reshape(modY, 1, :), modXY, κ.h)
6466
return K
6567
end
@@ -78,7 +80,7 @@ end
7880
function kappa::FBMKernel, x::AbstractVector{<:Real}, y::AbstractVector{<:Real})
7981
modX = sum(abs2, x)
8082
modY = sum(abs2, y)
81-
modXY = sqeuclidean(x, y)
83+
modXY = evaluate(SqEuclidean(sqroundoff), x, y)
8284
h = first.h)
8385
return (modX^h + modY^h - modXY^h)/2
8486
end

0 commit comments

Comments
 (0)