• PUDN用户
    了解作者
  • matlab
    开发工具
  • 1KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 1246
    下载次数
  • 2007-07-20 16:04
    上传日期
这是目前最经典的matlab实现的kpca代码,代码量已经很精简,但相信还有高手能做出最简化的代码
KPCA(classicc).rar
  • www.pudn.com.txt
    218B
  • KPCA(classicc).txt
    3.4KB
内容介绍
% Kernel PCA toy example for k(x,y)=exp(-||x-y||^2/rbf_var), cf. Fig. 4 in % @article{SchSmoMue98, % author = "B.~{Sch\"olkopf} and A.~Smola and K.-R.~{M\"uller}", % title = "Nonlinear component analysis as a kernel Eigenvalue problem", % journal = {Neural Computation}, % volume = 10, % issue = 5, % pages = "1299 -- 1319", % year = 1998} % This file can be downloaded from http://www.kernel-machines.org. % Last modified: 4 July 2003 % parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rbf_var = 0.1; xnum = 4; ynum = 2; max_ev = xnum*ynum; % (extract features from the first <max_ev> Eigenvectors) x_test_num = 15; y_test_num = 15; cluster_pos = [-0.5 -0.2; 0 0.6; 0.5 0]; cluster_size = 30; % generate a toy data set %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% num_clusters = size(cluster_pos,1); train_num = num_clusters*cluster_size; patterns = zeros(train_num, 2); range = 1; randn('seed', 0); for i=1:num_clusters, patterns((i-1)*cluster_size+1:i*cluster_size,1) = cluster_pos(i,1)+0.1*randn(cluster_size,1); patterns((i-1)*cluster_size+1:i*cluster_size,2) = cluster_pos(i,2)+0.1*randn(cluster_size,1); end test_num = x_test_num*y_test_num; x_range = -range:(2*range/(x_test_num - 1)):range; y_offset = 0.5; y_range = -range+ y_offset:(2*range/(y_test_num - 1)):range+ y_offset; [xs, ys] = meshgrid(x_range, y_range); test_patterns(:, 1) = xs(:); test_patterns(:, 2) = ys(:); cov_size = train_num; % use all patterns to compute the covariance matrix % carry out Kernel PCA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i=1:cov_size, for j=i:cov_size, K(i,j) = exp(-norm(patterns(i,:)-patterns(j,:))^2/rbf_var); K(j,i) = K(i,j); end end unit = ones(cov_size, cov_size)/cov_size; % centering in feature space! K_n = K - unit*K - K*unit + unit*K*unit; [evecs,evals] = eig(K_n); evals = real(diag(evals)); for i=1:cov_size, evecs(:,i) = evecs(:,i)/(sqrt(evals(i))); end % extract features %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % do not need the following here - only need test point features %unit_train = ones(train_num,cov_size)/cov_size; %for i=1:train_num, % for j=1:cov_size, % K_train(i,j) = exp(-norm(patterns(i,:)-patterns(j,:))^2/rbf_var); % end %end %K_train_n = K_train - unit_train*K - K_train*unit + unit_train*K*unit; %features = zeros(train_num, max_ev); %features = K_train_n * evecs(:,1:max_ev); unit_test = ones(test_num,cov_size)/cov_size; K_test = zeros(test_num,cov_size); for i=1:test_num, for j=1:cov_size, K_test(i,j) = exp(-norm(test_patterns(i,:)-patterns(j,:))^2/rbf_var); end end K_test_n = K_test - unit_test*K - K_test*unit + unit_test*K*unit; test_features = zeros(test_num, max_ev); test_features = K_test_n * evecs(:,1:max_ev); % plot it %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% figure(1); clf for n = 1:max_ev, subplot(ynum, xnum, n); axis([-range range -range+y_offset range+y_offset]); imag = reshape(test_features(:,n), y_test_num, x_test_num); axis('xy') colormap(gray); hold on; pcolor(x_range, y_range, imag); shading interp contour(x_range, y_range, imag, 9, 'b'); plot(patterns(:,1), patterns(:,2), 'r.') text(-1,1.65,sprintf('Eigenvalue=%4.3f', evals(n))); hold off; end
评论
  • 攀登1989 2017-06-12 07:34:07
    不错,这是为数不多可以运行的代码
相关推荐
  • LS_SVMlab.rar
    基于最小二乘法的支持向量机可以用于分类,它比传统的支持向量机方法更省时,准确率更高
  • Cmatlablssvm.zip
    C版的最小支持向量机代码,可作为matlab工具箱
  • SVM-Matlab-and-C-tools.rar
    SVM Matlab and C++ 工具箱充分利用彼此的优势。它非常方便的调用函数
  • PCA和KPCAMatlabC++程序
    PCA和KPCAMatlabC++程序,其中核函数使用的是高斯核函数 PCA和KPCAMatlabC++程序,其中核函数使用的是高斯核函数
  • 软件开发计划书 .asp.rar
    一个完整的项目开发文档,可以看看.没有坏处.
  • wavelet.rar
    关于小波去噪的几十篇经典论文,对利用小波去噪的朋友很有帮助的
  • bldc.matlab.rar
    在分析无刷直流电机(BLDC)数学模型的基础上,提出了一种无刷直流电机控制系统仿 真建模的新方法。在Matlab/Simulink环境下,把独立的功能模块和S函数相结合,构建了无刷直流 电机系统的仿真模型。系统采用双闭环控制:速度环采用离散PID控制,根据滞环电流跟踪型PWM 逆变器原理实现电流控制。仿真和试验结果与理论分析一致,验证了该方法的合理性和有效性。 此方法也适用于验证其他控制算法的合理性,为实际电机控制系统的设计和调试提供了新的思路。
  • JSP课件.rar
    JSP课件 主要是个人在学习JSP时,总结一些重要的源码,大家有可以做为参考资料阅读,谢谢!
  • i386.rar
    i386 windowxp系统
  • DICOM标准.rar
    想深入研究dicom的一定要看这个标准,已经翻译成中文,不是我翻译的,有的翻译的不是很好,但是作为英文对照看,可以学习的很快的。