mds.m

来自「best routing protocol」· M 代码 · 共 27 行

M
27
字号
% MDS based on distance matrix ALGORITHM%% function [Y,eigenvals] = dist_pca(D, dim)%% D = distance as N x N matrix ( N = #points)% dim = embedding dimensionality% y = embedding as  N x dim matrixfunction [y,eigenvals] = mds(D,dim)    S = D.^2; %the squared distance    N = length(S);    g = gramMatrix(S);    [mu, lam] = eig(g);    eigenvals = dot(lam,eye(N));    rep_lam = repmat(eigenvals(N-dim+1:N),N,1);    new_mu = mu(:,N-dim+1:N); % last d col of  mu    y = sqrt(rep_lam).*new_mu;    function g = gramMatrix(s)%s is the squared distance matrix    N = length(s);    over_i = sum(s);    total = sum(over_i);    Gjj = (over_i - total/N/2) / N;    rep_Gjj = repmat(Gjj,N,1);    rep_Gii = rep_Gjj';    g = (rep_Gjj+rep_Gii-s)./2;

⌨️ 快捷键说明

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