1 Star 0 Fork 0

Admin/marx_DisPAT

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SpectralClustNg.m 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
marx 提交于 2021-11-26 19:53 . v1
function T = SpectralClustNg(K,N)
% Performs spectral K-means for ell samples specified by the kernel K
%
%INPUTS
% K = the kernel matrix
% N = the number of clusters desired
%
%OUTPUTS
% T = vector (Nr*1) containing, for each point, the index of the cluster he belongs to
% X = Matrix (Nr*N) containing the eigenvectors of L
% totsumD = Total sum of values of distances from each point to every centroid.
% Reference:
% - Dhillon, I., Guan Y and Kulis B., Kernel k-means, Spectral Clustering and Normalized Cuts,
% KKD'04, August 22-25, 2004, Seattle, Washinton, USA
invSqrtD = diag(1./sqrt(sum(K,1)));
L = invSqrtD*K*invSqrtD;
% Find the N largest eigenvectors of L
% [V,D] = eig(L);
% X = V(:,1:N);
% Method Mehrdad for faster eig
[X,D] = symeig(L, N);
% Normalization of X
Z = sqrt(sum(X.^2, 2));
% X = X ./ Z(:, ones(size(X,2), 1));
X = bsxfun(@rdivide,X,Z);
% Try to find N points that are orthogonal to initialize KKM and avoid
% randomness of the results
idxclusters = centroidortho2(X,N);
% Perform traditionnal k-means algorithm using previous initial points
[T a sumD D totsumD] = kmeans2(X,N,'Start',X(idxclusters,:),'Maxiter',500,'EmptyAction','singleton','Display','final');
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Matlab
1
https://gitee.com/marx_1_1307066363/marx_-dis-pat.git
git@gitee.com:marx_1_1307066363/marx_-dis-pat.git
marx_1_1307066363
marx_-dis-pat
marx_DisPAT
master

搜索帮助