test.asv
资源名称:KPCA.rar [点击查看]
上传用户:nxf103
上传日期:2017-12-04
资源大小:2690k
文件大小:2k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Matlab
- load x00;
- load t05;
- %x00=[x00(1,:); x00(80,:);x00(120,:)];
- [tr,meanp,stdp] = prestd(x00');
- te = trastd(t05',meanp,stdp);
- tr=tr';
- te=te';
- trd=data(tr);
- ted=data(te);
- %[r,a]=train(kpca,tr);
- [r,a]=train(kpca({kernel('rbf',50)}),trd);
- d=test(a,ted);
- val=a.e_val;
- vec=a.e_vec;
- dvec=d.X;
- s=inv(diag(val(1:2)));
- for i=1:960
- tsquare(i)=dvec(i,1:2)*s*dvec(i,1:2)';
- SPE(i)=dvec(i,:)*dvec(i,:)'-dvec(i,1:2)*dvec(i,1:2)';
- end
- figure(1);
- subplot(2,1,1);
- plot(tsquare);
- xlabel('Sample Number');
- ylabel('T2');
- subplot(2,1,2);
- plot(tsquare);
- plot(SPE);
- xlabel('Sample Number');
- ylabel('SPE');
- %cn=kpcak(te,tr,vec(:,1:2),s);
- %figure(2)
- %plot(cn);
- %for i=1:960
- % spe(i)=dvec(21)^2;
- % for j=22:499
- % spe(i)=spe(i)+dvec(i,j)^2;
- % end
- %end
- %cn=kpcak(te,tr,vec(:,1:2),s);
- %stcn=standard_cn(cn);
- %K=kernel_matrix(tr,'RBF_kernel',2);
- %unit = ones(500,500)/500;
- %K_n = K - unit*K - K*unit + unit*K*unit;
- %[evecs,evals] = eig(K_n);
- %evals = real(diag(evals))/500;
- %排序
- %[evals,ordered]=sort(-evals);
- %evals=-evals;
- %evecs=evecs(:,ordered);
- %只保留相关的元素
- %peff = find(evals>1000*eps);
- %neff = length(peff);
- %for i=1:neff,
- % evecs(:,i) = evecs(:,i)./sqrt(evecs(:,i)'*evals(i)*evecs(:,i));
- %end
- %test_features_1 = K_n * evecs(:,1:neff);
- %s=inv(diag(evals(1:neff)));
- %for i=1:500
- % tsquare_1(i)=test_features_1(i,:)*s*test_features_1(i,:)';
- %end
- %unit_test = ones(960,500)/500;
- %K_test=kernel_matrix(tr,'RBF_kernel',2,te);
- %K_test=K_test';
- %K_test_n = K_test - unit_test*K - K_test*unit + unit_test*K*unit;
- %test_features = zeros(960,500);
- %test_features = K_test_n * evecs(:,1:neff);
- %s=inv(diag(evals(1:neff)));
- %for i=1:960
- % tsquare(i)=test_features(i,:)*s*test_features(i,:)';
- %end