-
Notifications
You must be signed in to change notification settings - Fork 36
Add Gabor Kernel #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Gabor Kernel #52
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
836ccb6
Add GaborKernel
sharanry 5cb4295
Update src/kernels/gabor.jl
sharanry b78395d
Merge branch 'master' into gabor
sharanry 3be0cbe
Add Gabor kernel using KernelProduct
sharanry 0c731c7
Modify gabor kernel to be more efficient
sharanry 128623e
Add tests for gabor kernel
sharanry bd356a9
Override Base.getproperty for Gabor kernel
sharanry deef7e2
Merge branch 'master' into gabor
sharanry 40b25db
Make tests pass
sharanry b8d3c19
remove unecessary where{T<:Real}
sharanry 8b821db
Add more tests
sharanry 04a1338
Apply suggestions from code review by @devmotion
sharanry 77c1be0
Address code review
sharanry 2fe2000
Add custom show function
sharanry b7a1f62
Fix merge conflicts
sharanry 067b65b
Remove test_kernels.jl
sharanry 2517957
Add gabor to runtests.jl
sharanry efcf72c
Fix gabor tests
sharanry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Base.getproperty | ||
|
||
""" | ||
GaborKernel(; ell::Real=1.0, p::Real=1.0) | ||
|
||
Gabor kernel with length scale ell and period p. Given by | ||
```math | ||
κ(x,y) = h(x-z), h(t) = exp(-sum(t.^2./(ell.^2)))*cos(pi*sum(t./p)) | ||
``` | ||
|
||
""" | ||
struct GaborKernel{T<:Real, K<:Kernel} <: BaseKernel | ||
κ::K | ||
sharanry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function GaborKernel(;ell=nothing, p=nothing) | ||
k = _gabor(ell=ell, p=p) | ||
if ell == nothing ell=1.0 end | ||
if p == nothing p=1.0 end | ||
new{Union{typeof(ell),typeof(p)}, typeof(k)}(k) | ||
sharanry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
|
||
function _gabor(; ell = nothing, p = nothing) | ||
if ell === nothing | ||
if p === nothing | ||
return SqExponentialKernel() * CosineKernel() | ||
else | ||
return SqExponentialKernel() * transform(CosineKernel(), 1 ./ p) | ||
end | ||
elseif p === nothing | ||
return transform(SqExponentialKernel(), 1 ./ ell) * CosineKernel() | ||
else | ||
return transform(SqExponentialKernel(), 1 ./ ell) * transform(CosineKernel(), 1 ./ p) | ||
end | ||
end | ||
|
||
function Base.getproperty(k::GaborKernel, v::Symbol) | ||
if v == :κ | ||
return getfield(k, v) | ||
elseif v == :ell && typeof(k.κ.kernels[1]) <: SqExponentialKernel | ||
return 1.0 | ||
elseif v == :ell && typeof(k.κ.kernels[1]) <: TransformedKernel | ||
return 1 ./ k.κ.kernels[1].transform.s[1] | ||
elseif v == :p && typeof(k.κ.kernels[2]) <: CosineKernel | ||
return 1.0 | ||
elseif v == :p && typeof(k.κ.kernels[2]) <: TransformedKernel | ||
return 1 ./ k.κ.kernels[2].transform.s[1] | ||
sharanry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
else | ||
error("Invalid Property") | ||
end | ||
end | ||
|
||
kappa(κ::GaborKernel, x, y) where {T<:Real} = kappa(κ.κ, x ,y) | ||
sharanry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function kernelmatrix( | ||
κ::GaborKernel, | ||
X::AbstractMatrix; | ||
obsdim::Int=defaultobs) | ||
kernelmatrix(κ.κ, X; obsdim=obsdim) | ||
end | ||
|
||
function kernelmatrix( | ||
κ::GaborKernel, | ||
X::AbstractMatrix, | ||
Y::AbstractMatrix; | ||
obsdim::Int=defaultobs) | ||
kernelmatrix(κ.κ, X, Y; obsdim=obsdim) | ||
end | ||
|
||
function kerneldiagmatrix( | ||
κ::GaborKernel, | ||
X::AbstractMatrix; | ||
obsdim::Int=defaultobs) #TODO Add test | ||
kerneldiagmatrix(κ.κ, X; obsdim=obsdim) | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.