Skip to content

Commit 0c731c7

Browse files
committed
Modify gabor kernel to be more efficient
1 parent 3be0cbe commit 0c731c7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/kernels/gabor.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,25 @@ struct GaborKernel{T<:Real, K<:Kernel} <: BaseKernel
1111
ell::T
1212
p::T
1313
κ::K
14-
function GaborKernel(;ell::T=1.0, p::T=1.0) where {T<:Real}
15-
k = transform(SqExponentialKernel(), 1/ell)*transform(CosineKernel(), 1/p)
16-
new{T, typeof(k)}(ell, p, k)
14+
function GaborKernel(;ell=nothing, p=nothing)
15+
k = _gabor(ell=ell, p=p)
16+
if ell==nothing ell=1.0 end
17+
if p==nothing p=1.0 end
18+
new{Union{typeof(ell),typeof(p)}, typeof(k)}(ell, p, k)
19+
end
20+
end
21+
22+
function _gabor(; ell = nothing, p = nothing)
23+
if ell === nothing
24+
if p === nothing
25+
return SqExponentialKernel() * CosineKernel()
26+
else
27+
return SqExponentialKernel() * transform(CosineKernel(), 1 ./ p)
28+
end
29+
elseif p === nothing
30+
return transform(SqExponentialKernel(), 1 ./ ell) * CosineKernel()
31+
else
32+
return transform(SqExponentialKernel(), 1 ./ ell) * transform(CosineKernel(), 1 ./ p)
1733
end
1834
end
1935

src/trainable.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ trainable(k::RationalQuadraticKernel) = (k.α,)
1818

1919
trainable(k::MahalanobisKernel) = (k.P,)
2020

21+
trainable(k::GaborKernel) = (k.κ,)
22+
2123
#### Composite kernels
2224

2325
trainable::KernelProduct) = κ.kernels

0 commit comments

Comments
 (0)