I'd like to compute kernel matrices efficiently for generic kernel functions in
Matlab. This means I need to compute k(x,y) for every row x of X
and every row y of Y. Here is some matlab code that computes what I'd
like, but it is rather slow,
function K=compute_kernel( k_func, X, Y )
    m = size(X,1);
    n = size(Y,1);
    K = zeros(m,n);
    for i = 1:m
        for j = 1:n
            K(i,j) = k_func(X(i,:)', Y(j,:)');
        end
    end
end
Is there any other approach to this problem, e.g. some bsxfun variant that
calls a function on every row taken from X and Y?
 
     
    