资源简介
一个比较好用的特征提取的kpca程序,调试成功,可以用!kpca是一种非线性的特征提取方法!
代码片段和文件信息
%% the programm of kpca the kernel is polynomial
function [new_datatrans_vec] = KPCA(dataclass_numtrain_numnew_dimd) %d:the degree of the polynomial kernal
[dimdata_num] = size(data);
data_num_perclass = data_num/class_num;
for class_mark = 1:class_num
train_data(:(class_mark-1)*train_num+(1:train_num)) = data(:(class_mark-1)*data_num_perclass+(1:train_num)); %receive the train data
end
train_data_num = train_num*class_num;
%---------------calculate the K matrix-----------------
for train_data_mark = 1:train_data_num
for train_data_mark2 = 1:train_data_num
K(train_data_marktrain_data_mark2) = (train_data(:train_data_mark)‘*train_data(:train_data_mark2))^d;
end
end
unit_1 = ones(train_data_numtrain_data_num)/train_data_num;
K_norm = K - unit_1*K - K*unit_1 + unit_1*K*unit_1; % centralize the K matrix
%-----------use KPCA --------------
[vecval] = eig(K_norm);
val = diag(val);
[sort_valindex] = sort(val‘descend‘);
sort_vec = vec(:index);
% need_vec = sort_vec(:1:new_dim);
for vec_mark = 1:new_dim
trans_vec(:vec_mark) = sort_vec(:vec_mark)/sqrt(sort_val(vec_mark)); % normalize the transform vector
end
%------K2 matrix is used for project the data------------
for data_mark = 1:data_num
for train_data_mark = 1:train_data_num
K2(data_marktrain_data_mark) = (data(:data_mark)‘*train_data(:train_data_mark))^d; %calculate the K2 matrix
end
end
unit_2 = ones(data_numtrain_data_num)/train_data_num;
K2_norm = K2 - unit_2*K - K2*unit_1+ unit_2*K*unit_1; %centralize the K2 matrix
new_data = K2_norm*trans_vec;% project data
new_data = new_data‘;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1682 2008-12-16 16:47 KPCA.m
----------- --------- ---------- ----- ----
1682 1
- 上一篇:多线程生产者消费者模式
- 下一篇:机房管理系统的源代码和功能图
评论
共有 条评论