Skip to content
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

Support for precomputed kernels #61

Closed
MichielStock opened this issue Nov 16, 2019 · 2 comments
Closed

Support for precomputed kernels #61

MichielStock opened this issue Nov 16, 2019 · 2 comments

Comments

@MichielStock
Copy link
Collaborator

Often you don't have (or need) a function to compute a kernel matrix on the fly, but you already have a precomputed Gram matrix. Example code how I solved this (because I needed a diffusion kernel):

struct Diffusion <: Kernel
    K
    function Diffusion(A::AbstractMatrix, β::Real=1.0; norm=false)
        L = laplacian(A)
        if norm
            L = norm_laplacian(L)
        end
        return new(exp* L))
    end
end

#Diffusion(E::Eigen, β::Real=1.0) = Diffusion(diffusion(E, β))

ew(k::Diffusion, x::AbstractVector{<:Int}) = [k.K[i,i] for i in x]
ew(k::Diffusion, x::AbstractVector{<:Int}, x′::AbstractVector{<:Int}) = [k.K[i,j] for (i,j) in zip(x, x′)]

pw(k::Diffusion, x::AbstractVector{<:Int}) = k.K[x,x]
pw(k::Diffusion, x::AbstractVector{<:Int}, x′::AbstractVector{<:Int}) = k.K[x,x′]

Maybe we should have PrecomputedKernel type to mediate this?

@willtebbutt
Copy link
Member

Ahh I see. Yeah, a pre-computed kernel makes sense. Would be very happy to receive a PR involving a pre-computed kernel. I don't have a great intuition for what the best construction interface would be, but it might literally just be to pass in a matrix of numbers.

@MichielStock MichielStock mentioned this issue Nov 20, 2019
@willtebbutt
Copy link
Member

Closed by #62 being merged. Please reopen if more to do.

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

No branches or pull requests

2 participants