• 大小: 3KB
    文件类型: .m
    金币: 2
    下载: 1 次
    发布日期: 2021-08-11
  • 语言: Matlab
  • 标签: KPCA  matlab实现  

资源简介

核主成成分分析的实现过程,比较简单明了,希望对大家有作用吧

资源截图

代码片段和文件信息

% Kernel PCA toy example for k(xy)=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  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_pos1);
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_size1) = cluster_pos(i1)+0.1*randn(cluster_size1);
  patterns((i-1)*cluster_size+1:i*cluster_size2) = cluster_pos(i2)+0.1*randn(cluster_size1);
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

评论

共有 条评论