www.pudn.com > kicILC-control.rar > kicr.m, change:2013-04-18,size:2402b


function [ y_test_predict,A] = kicr( x_train,y_train,x_test,rbf_var) 
%x_train 为输入训练数据,y_train为目标训练函数,x_test测试输入数据,y_test_predict对应的预测值 
%k(x,y)=exp(-||x-y||^2/rbf_var) 
 
 
 
eig_level=1;%主元简化时的特征值限度 贡献度1% 
 
N_train=size(x_train,2); 
N_test=size(x_test,2); 
 
%原始数据原始空间均值标准化处理 
[x_train,mean_x_train,std_x_train]=zscore(x_train,0,2); 
x_test=(x_test-repmat(mean_x_train,1,N_test))./repmat(std_x_train,1,N_test);%根=据训练数据中心化 
[y_train,mean_y_train,std_y_train]=zscore(y_train,0,2); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%构建核函数 
K_train=zeros(N_train); 
for i=1:N_train 
  for j=i:N_train 
    K_train(i,j) = exp(-norm(x_train(:,i)-x_train(:,j))^2/rbf_var); 
    K_train(j,i) = K_train(i,j); 
  end 
end 
K1=K_train; 
% centering in feature space! 
unit = ones(N_train,N_train)/N_train; 
K_train = K_train - unit*K_train - K_train*unit + unit*K_train*unit; 
[E,D,explained] = pcacov(K_train);%返回k-n的特征值和特征向量及对应特征值相对总特征值和的百分比 
%cd=cond(K_train); 
d=sum(explained>eig_level);%特征值贡献大于0.1%个数 
 
E=E(:,1:d); 
D=diag(D(1:d)); 
 
% 白化 
z_train=sqrt(N_train)*D\E.'*K_train; 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%调用fpICA算法,获得z_train的ICA 
whiting=rand(size(D)); 
dewhiting=inv(whiting); 
[~, W_train] = fpica(z_train, whiting, dewhiting); 
IC_train=W_train*z_train; 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%预测 核函数构建 
K_test = zeros(N_train,N_test);%计算K_validate值 
for j=1:N_test 
  for i=1:N_train 
    K_test(i,j) = exp(-norm(x_train(:,i)-x_test(:,j))^2/rbf_var); 
  end 
end  
 
unit_test = ones(N_train,N_test)/N_train; 
K_test = K_test - unit*K_test - K_train*unit_test  + unit*K_train*unit_test;%K_validate中心化 
 
% 白化 
z_test=sqrt(N_train)*D\E.'*K_test; 
 
 
%SPE=diag(z_test.'*(eye(size(W_train,1))-W_train.'*inv(D)*W_train)*z_test); 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%ressgion 
 
B=(IC_train*IC_train.')\IC_train*y_train.'; 
y_test_predict=B.'*W_train*z_test; 
 
A=y_test_predict/K_test;% 迭代控制时使用。回归不用 
%A=A.*repmat(std_y_train,1,N_test)+repmat(mean_y_train,1,N_test); 
y_test_predict=y_test_predict.*repmat(std_y_train,1,N_test)+repmat(mean_y_train,1,N_test); 
 
%%A=y_test_predict/K1; 
end