簡體   English   中英

Matlab中高斯RBF的實現

[英]Implementation of Gaussian RBF in Matlab

我從機器學習開始,需要幫助在 Matlab 中實現高斯 RBF。

在此處輸入圖片說明

我知道它在做什么,但不確定如何在 matlab 中實現它

function K = rbf(coord,sig)

%function K = rbf(coord,sig)
%
% Computes an rbf kernel matrix from the input coordinates
%
%INPUTS
% coord =  a matrix containing all samples as rows
% sig = sigma, the kernel width; squared distances are divided by
%       squared sig in the exponent
%
%OUTPUTS
% K = the rbf kernel matrix ( = exp(-1/(2*sigma^2)*(coord*coord')^2) )
%

n=size(coord,1);
K=coord*coord'/sig^2;
d=diag(K);
K=K-ones(n,1)*d'/2;
K=K-d*ones(1,n)/2;
K=exp(K);

%% Previous version:
%%
% n = size(coord,1);
% for i=1:n
%     K(i,i)=1;
%     for j=1:i-1
%         K(i,j)=exp(-norm(coord(i,:)-coord(j,:))^2/sig^2);% Should be
%         % 2*sig^2!
%         K(j,i)=K(i,j);
%     end
% end

來源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM