function K = rbf4nn_vecss( X, Y, sigsq ) %function K = rbf4_vecss( X, Y, sigsq ) % % Computes an rbf kernel matrix of X with Y, using a diagonal % covariance matrix specified in sigsq. Sigsq is specified as % a column vector. % %INPUTS % X = a matrix containing all samples as columns. % Y = another matrix containing samples as columns. % sigsq = column vector specifying the diagonal of the shape matrix. % %NOTE: the result does not include the normalization factor! % %OUTPUTS % K_ij = exp(-1/(2*sigsq)*(X_i' * inv(diag(sigsq)) * Y_j)) % % Adapted by D. Wingate from code written by Tijl De Bie. sigsq = 1 ./ sigsq; Xs = X.*X .* repmat( sigsq, 1, size(X,2) ); Xs = sum( Xs, 1 ); Ys = Y.*Y .* repmat( sigsq, 1, size(Y,2) ); Ys = sum( Ys, 1 ); Xt = Xs' * ones(1,length(Ys)); Yt = ones(length(Xs),1) * Ys; p = X'*(repmat(sigsq,1,size(Y,2)).*Y); K = exp( p + -0.5*( Xt + Yt ) );