sqrdist.m

来自「该算法包包含了hierichal」· M 代码 · 共 41 行

M
41
字号
function D = sqrDist(x,t,w)% SQRDIST : calculate a nt*nx matrix containing weighted squared error between%           every vector in x and every vector in t% D = sqrDist(x,t,w)%	x - d*nx matrix containing the x vectors %	t - d*nt matrix containing the t vectors%	w - if specified, a length d weight vector%	D - the nt*nx result%% useful facts:%  sqrDist(X,M,v.^-0.5) = sqrMahalanobis(X,z,diag(v))%  sqrDist(X,M,s.^-1)   = sqrMahalanobis(X,z,diag(s.^2))%  sqrDist(X,M,w)       = sqrMahalanobis(X,z,diag(w.^2))% Copyright (c) 1995 Frank Dellaert% All rights Reservedglobal sqrDist_warningif isempty(sqrDist_warning)   warning('sqrDist: please compile mex-version by typing "mex sqrDist.c" in "clusters" directory');   sqrDist_warning=1;end[d ,nx] = size(x);[dt,nt] = size(t);if (dt~=d), error('sqrDist: x and t must have same dimension'); endif (nargin<3), w=[]; endD = zeros(nt,nx);for l=1:d   D2 = dist1(x(l,:),t(l,:)).^2; % distance for 1 dimension, unweighted   if isempty(w)      D  = D + D2;               % sum to get unweighted distance   else      D  = D + (w(l)^2)*D2;      % sum to get weighted distance   endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?