spectralclustering

  • o3_615177
    了解作者
  • matlab
    开发工具
  • 15.1MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-02-23 10:47
    上传日期
spectral clustering 算法工具包
spectralclustering
  • spectralclustering-1.0
  • data
  • corel_20_NN_sym_distance.mat
    503.6KB
  • corel_10_NN_sym_distance.mat
    252.5KB
  • corel_feature.mat
    1.2MB
  • corel_label.mat
    236B
  • corel_15_NN_sym_distance.mat
    376.8KB
  • corel_5_NN_sym_distance.mat
    126.8KB
  • corel_100_NN_sym_distance.mat
    2.5MB
  • corel_150_NN_sym_distance.mat
    3.8MB
  • corel_50_NN_sym_distance.mat
    1.2MB
  • corel_200_NN_sym_distance.mat
    5.1MB
  • script_nystrom.m
    2KB
  • sc.m
    2.8KB
  • gen_nn_distance.m
    4.1KB
  • k_means.m
    4.4KB
  • nmi.m
    1.9KB
  • nystrom.m
    4.9KB
  • script_sc.m
    2.3KB
  • README
    5.3KB
内容介绍
function [predict_labels evd_time kmeans_time total_time] = nystrom(data, num_samples, sigma, num_clusters) %NYSTROM Spectral clusterina using the Nystrom method. % % Input : data : N-by-D data matrix, where N is the number of data, % D is the number of dimensions % num_samples : number of random samples % sigma : sigma value used in computing similarity % num_clusters : number of clusters % % Output : predict_labels : N-by-1 vector containing predicted labels % evd_time : running time for eigendecomposition % kmeans_time : running time for k-means % total_time : total running time % % Authors: Wen-Yen Chen, Yangqiu Song, Hongjie Bai, Chih-Jen Lin, 2008. % % Contact: Wen-Yen Chen (wychen@cs.ucsb.edu) % Computer Science % University of California at Santa Barbara % Santa Barbara, CA 93106 % % Randomly select samples % disp('Randomly selecting samples...'); tic; num_rows = size(data, 1); permed_index = randperm(num_rows); sample_data = data(permed_index(1:num_samples), :); other_data = data(permed_index(num_samples+1:num_rows), :); clear data; toc; % % Calculate the euclidean distance between samples themselves % disp('Calculating distance among samples...'); A = euclidean(sample_data', sample_data'); A = single(A); toc; % % Calculate the euclidean distance between samples and other points % disp('Calculating distance between samples and other points...'); B = euclidean(sample_data', other_data'); B = single(B); clear sample_data other_data; toc; % % Convert distance matrix to similarity matrix: S = exp^(-(dist^2 / 2*sigma^2)) % disp('Converting distance matrix to similarity matrix...'); A = single(exp(-(A.*A) ./ (2*sigma*sigma))); B = single(exp(-(B.*B) ./ (2*sigma*sigma))); toc; % % Normalize A and B using row sums of W, where W = [A B; B' B'*A^-1*B]. % Let d1 = [A B]*1, d2 = [B' B'*A^-1*B]*1, dhat = sqrt(1./[d1; d2]). % disp('Normalizing A and B for Laplacian...'); B_T = B'; d1 = sum(A, 2) + sum(B, 2); d2 = sum(B_T, 2) + B_T*(pinv(A)*sum(B, 2)); dhat = sqrt(1./[d1; d2]); A = A .* (dhat(1:num_samples)*dhat(1:num_samples)'); m = num_rows - num_samples; B1 = dhat(1:num_samples)*dhat(num_samples+(1:m))'; B = B .* B1; clear W d1 d2 B1 dhat; time1 = toc; % % Do orthogalization and eigendecomposition % Reference: PAMI'04 paper 'Spectral grouping using Nystrom method' % disp('Orthogalizing and eigendecomposition...'); Asi = sqrtm(pinv(A)); B_T = B'; BBT = B*B_T; W = single(zeros(size(A,1)+size(B_T,1), size(A,2))); W(1:size(A,1), :) = A; W(size(A,1)+1:size(W,1), :) = B_T; clear B B_T; % Calculate R = A + A^-1/2*B*B'*A^-1/2 R = A + Asi*BBT*Asi; R = (R + R')/2; % Make sure R is symmetric, sometimes R can be non-symmetric because of numerical inaccuracy [U L] = eig(R); [val ind] = sort(diag(L), 'descend'); U = U(:, ind); % in decreasing order L = L(ind, ind); % in decreasing order clear A R BBT; W = W*Asi; V = W*U(:,1:num_clusters)*pinv(sqrt(L(1:num_clusters,1:num_clusters))); clear W Asi L U; time2 = toc; % % Do k-means % disp('Performing kmeans...'); % Normalize each row to be of unit length sq_sum = sqrt(sum(V.*V, 2)) + 1e-20; U = V ./ repmat(sq_sum, 1, num_clusters); clear sq_sum V; predict_labels = k_means(U, [], num_clusters); % Restore predict_labels in original order predict_labels(permed_index) = predict_labels; clear permed_index; total_time = toc; % % Calculate and show time statistics % evd_time = time2 - time1 kmeans_time = total_time - time2 total_time disp('Finished!'); %-------------------------------------------------------------------------- function d = euclidean(a, b) %EUCLIDEAN Compute the Euclidean distance matrix between two matrices. % This function is designed for processing very large data using divide- % and-conquer technique. % % Input : a : D-by-M data matrix, where D is the number of dimensions, % M is the number of data % b : D-by-N data matrix, where D is the number of dimensions, % N is the number of data % Output: d : M-by-N matrix of the Euclidean distance between a and b. % % Calculate a^2, b^2, here we assume b is larger than a % aa = single(full(sum(a.*a, 1))); bb = single(full(sum(b.*b, 1))); % % Do a*b in several steps instead of once because of memory limitation % two_ab = single(zeros(size(aa, 2), size(bb, 2))); % Select at most 10000 instances of b for a*b per iteration num_iter = ceil(size(bb, 2)/10000); for i = 1:num_iter start_index = 1 + (i-1)*10000; end_index = min(i*10000, size(bb, 2)); abtmp = single(full(a'*b(:, start_index:end_index))); two_ab(:, start_index:end_index) = 2*abtmp; end % Now we have entire ab clear a b abtmp; d = bb(ones(size(aa, 2), 1), :); d = d - two_ab; % Now we have d = b^2 - 2ab clear two_ab; ff = aa'; ff = ff(:, ones(size(bb, 2), 1)); d = d + ff; % Now we have d = a^2 + b^2 -2ab clear aa bb ff; d = sqrt(d);
评论
    相关推荐
    • Matlab合集
      冈萨雷斯数字图像处理MATLAB版.中文版+数字图像处理第二版中文版(冈萨雷斯)+MATLAB-R2014a完全自学一本通+MATLAB R2016a完全自学一本通 素材文件+[模式识别与智能计算:MATLAB技术实现(第2版)].杨淑莹.扫描版
    • MATLAB教程
      MATLAB教程MATLAB教程MATLAB教程MATLAB教程MATLAB教程MATLAB教程
    • MATLAB
      MATLAB 该项目是在matlab上完成的,涉及创建和移动宇宙飞船和机器人。 太空飞船和机器人是使用Matlab中的简单几何形状创建的,并通过连续变换矩阵进行移动。 这个项目教我如何使用变换矩阵(旋转,平移等)的概念...
    • MATLAB基础
      一本学习matlab的一本好书
    • MATLAB编译器
      基于MATLAB 2018b版本介绍MATLAB编译器。介绍如何利用编译器将MATLAB代码编译为独立应用程序或组件,并在没有安装MATLAB的计算机上进行部署。
    • matlabruntime
      通过奇点容器运行您的matlab项目 可以在没有MATLAB的容器中运行matlab代码。 为此,我们首先需要通过Matlab编译器在本地构建相应的Matlab代码的独立应用程序,然后使用具有Matlab运行时( 的容器)运行该应用程序 )...
    • matlab实现
      matlab实现 matlab实现matlab实现matlab实现matlab实现
    • matlab 教程
      matlab 信号处理资料,里面包含信号处理pdf文档,一些杂乱的程序和命令等
    • matlab教程
      matlab教程,PPT格式,包含 matlab基本知识、matlab入门、matlab作图、线性规划、无约束优化、非线性规划、统计工具箱、差值、微分方程等多项知识点,并且每个知识点独立成为PPT,内还含有matlab信号处理详解等文档...
    • matlab简介
      1.MATLAB 开发环境 1.1 MATLAB 的视窗环境 进入MATLAB之后,会看到一个视窗MATLAB Command Window称为指令视窗,它是你键入指令的地方同时 MATLAB也将计算结果显示在此。 1.2 简易计算 我们先从MATLAB的...