简体   繁体   English

Matlab中RBF核矩阵的算法是什么?

[英]what is the algorithm for an RBF kernel matrix in Matlab?

如果为我提供了训练数据集和未标记的数据集,那么Matlab的RBF内核矩阵算法是什么?

This should be what you are looking for. 这应该是您想要的。 It is taken from here 这里

% With Fast Computation of the RBF kernel matrix
% To speed up the computation, we exploit a decomposition of the Euclidean distance (norm)
%
% Inputs:
%       ker:    'lin','poly','rbf','sam'
%       X:      data matrix with training samples in rows and features in columns
%       X2:     data matrix with test samples in rows and features in columns
%       sigma: width of the RBF kernel
%       b:     bias in the linear and polinomial kernel
%       d:     degree in the polynomial kernel
%
% Output:
%       K: kernel matrix
%
% Gustavo Camps-Valls
% 2006(c)
% Jordi (jordi@uv.es), 2007
% 2007-11: if/then -> switch, and fixed RBF kernel

function K = kernelmatrix(ker,X,X2,sigma)

switch ker
    case 'lin'
        if exist('X2','var')
            K = X' * X2;
        else
            K = X' * X;
        end

    case 'poly'
        if exist('X2','var')
            K = (X' * X2 + b).^d;
        else
            K = (X' * X + b).^d;
        end

    case 'rbf'

        n1sq = sum(X.^2,1);
        n1 = size(X,2);

        if isempty(X2);
            D = (ones(n1,1)*n1sq)' + ones(n1,1)*n1sq -2*X'*X;
        else
            n2sq = sum(X2.^2,1);
            n2 = size(X2,2);
            D = (ones(n2,1)*n1sq)' + ones(n1,1)*n2sq -2*X'*X2;
        end;
        K = exp(-D/(2*sigma^2));

    case 'sam'
        if exist('X2','var');
            D = X'*X2;
        else
            D = X'*X;
        end
        K = exp(-acos(D).^2/(2*sigma^2));

    otherwise
        error(['Unsupported kernel ' ker])
end

To produce the grahm/kernel matrix (matrix of inner products) do: 要生成grahm /内核矩阵(内部乘积矩阵),请执行以下操作:

function [ Kern ] = produce_kernel_matrix( X, t, beta )
%
X = X';
t = t';
X_T_2 = sum(X.^2,2) + sum(t.^2,2).' - (2*X)*t.'; % ||x||^2 + ||t||^2 - 2<x,t>
Kern =exp(-beta*X_T_2); %
end

then to do the interpolation do: 然后做插值:

function [ mdl ] = learn_RBF_linear_algebra( X_training_data, Y_training_data, mdl )
%
Kern_matrix = produce_kernel_matrix_bsxfun(X_training_data, mdl.t, mdl.beta); % (N x K)
C = Kern_matrix \ Y_training_data';  % (K x D) = (N x K)' x (N x D)
mdl.c = C; % (K x D)
end

note beta is 1/2sigma 注意beta是1/2sigma

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 matlab中的convhull()函数使用什么算法? - What algorithm does the convhull() function in Matlab use? 等效于Matlab代码的数学公式(特征面算法的协方差矩阵) - Equivalent matlab code to maths formula (covariance matrix for eigenfaces algorithm) 找到矩阵行列式的最佳算法是什么? - What is the best algorithm to find a determinant of a matrix? 在矩阵上找到波中心的最佳算法是什么? - What is the best algorithm to find the center of a wave on a matrix? 什么样的算法用于生成方阵? - What kind of algorithm is used to generate a square matrix? 邻接矩阵的克鲁斯卡尔算法的时间复杂度是多少? - What is the time complexity of kruskal's algorithm for an adjacency matrix? 在MATLAB中使用什么算法(rgb2ind())? - What Algorithm(s) do(es) rgb2ind() in MATLAB use? bwareafilt 在 MATLAB 中的奇怪行为以及它使用什么算法? - Weird behaviour of bwareafilt in MATLAB and what algorithm does it use? 找到矩阵中所有局部最小值(最大值)的有效算法是什么? - What is an efficient algorithm to find all local minimums(maximums) in a matrix? 在 NxN 矩阵中,什么算法可以找到两个节点之间的最短路径? - In a NxN matrix, what algorithm finds the shortest path between two nodes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM