Skip to content

Fix formula of Gabor kernel #240

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 1 commit into from
May 6, 2021
Merged

Fix formula of Gabor kernel #240

merged 1 commit into from
May 6, 2021

Conversation

devmotion
Copy link
Member

There's an inconsistency in the mathematical definition and the implementation that I missed. The Gabor kernel is implemented as a product of a Gaussian and a cosine kernel, both possibly with a (possibly element-wise) lengthscale transformation of the inputs. The formula should reflect this now correctly.

That being said, the Gabor kernel implementation is definitely one of the stranger implementations. It still feels weird to wrap the product in its own struct, a function gabor would be sufficient it seems. I am also wondering if one should drop one of the lengthscale transformations and instead define the kernel with ell = 1 (or p = 1). One would have to apply a separate input transformation to set this parameter, as for other kernels currently, and scale the other parameter accordingly.

@devmotion
Copy link
Member Author

Maybe one could define something like

function gabor_kernel(; sqexponential_transform=IdentityTransform(), cosine_transform=IdentityTransform())
    return transform(SqExponentialKernel(), sqexponential_transform) * transform(CosineKernel(), cosine_transform)
end

instead of the current implementation. I don't think it's helpful to remove one of the transformations, as speculated above, since it would make it more complicated (and sometimes impossible) to recover the original inputs for one kernel if one modifies the inputs for the other one with an additional transformation of the original inputs.

@devmotion
Copy link
Member Author

BTW it seems it would be useful to define

transform(k::Kernel, ::IdentityTransform) = k

@devmotion
Copy link
Member Author

@willtebbutt @theogf What's your opinion? Should we deprecate Gabor and add the suggestions (gabor and transform(, ::IdentityTransform)) above?

@theogf
Copy link
Member

theogf commented May 6, 2021

I definitely think we should deprecate Gabor. Sorry for the duplicate in the issue, I completely forgot about this PR...

I would also be positive for transform(, ::IdentityTransform)

@theogf
Copy link
Member

theogf commented May 6, 2021

For gabor instead of the product can't we use the spectral_mixture_kernel instead? Since it's a special case?

@devmotion
Copy link
Member Author

It is a special case but I don't think we want to just call the current implementation of spectral_mixture_kernel. It would lead to an unnecessarily complicated kernel since it creates a KernelSum of multiple weighted KernelProducts instead of just a simple unweighted KernelProduct and requires to specify a vector of these weights. I also don't think there would be gained much implementationwise since the gabor (or maybe gaborkernel?) implementation would be only 3 lines of code anyway.

@devmotion
Copy link
Member Author

Can someone approve this PR and then I'll open a new PR with the deprecations and suggestions above when it is merged? I think this would be a bit cleaner than adding more changes here.

@devmotion devmotion merged commit 3d8b245 into master May 6, 2021
@devmotion devmotion deleted the devmotion-patch-1 branch May 6, 2021 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants