Skip to content

Commit b1bd1d3

Browse files
committed
Modify Mahalanobis distance-based kernel
1 parent d99c1af commit b1bd1d3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/kernels/maha.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
"""
2-
MahaKernel(; ell::Real=1.0, p::Real=1.0)
2+
MahaKernel(P::AbstractMatrix, kappa::Function)
33
44
Mahalanobis distance-based kernel given by
55
```math
6-
κ(x,y) = k(r^2), r^2 = maha(x,P,y) = (x-y)'*inv(P)*(x-y)
6+
κ(x,y) = kappa(r^2), r^2 = maha(x,P,y) = (x-y)'*inv(P)*(x-y)
77
```
8-
where the matrix P is the metric.
8+
where the matrix P is the metric and kappa is a user defined kernel function.
99
1010
"""
1111
struct MahaKernel{T<:Real} <: BaseKernel
12-
P
13-
function MahaKernel(P::AbstractMatrix{T}) where {T<:Real}
14-
@assert size(P)[1] == size(P)[2], "P should be a square matrix"
15-
new{T}(P)
12+
P::AbstractMatrix{T}
13+
kappa::Function
14+
function MahaKernel(P::AbstractMatrix{T}, kappa::Function) where {T<:Real}
15+
@assert size(P)[1] == size(P)[2] "P should be a square matrix"
16+
new{T}(P, kappa)
1617
end
1718
end
1819

19-
kappa::MahaKernel, d::T) where {T<:Real} = d
20+
kappa::MahaKernel, d::T) where {T<:Real} = κ.kappa(d)
2021

2122
metric::MahaKernel) = Mahalanobis.P)

0 commit comments

Comments
 (0)