test_sample_my.asv
上传用户:nxf103
上传日期:2017-12-04
资源大小:2690k
文件大小:1k
开发平台:

Matlab

  1. %generate train date&test data
  2. %this sample is from "Nonlinear process monitoring using kernel principal component analysis"
  3. e11=normrnd(0,0.01,1,100);
  4. e21=normrnd(0,0.01,1,100);
  5. e31=normrnd(0,0.01,1,100);
  6. t1=rand(1,100)*2;
  7. x11=t1+e11;
  8. for i=1:100
  9.     x21(i)=2*t1(i)^2-3*t1(i)+e21(i);
  10. end
  11. for i=1:100
  12.     x31(i)=-t1(i)^3+3*t1(i)^2+e31(i);
  13. end
  14. trian=[x11;x21;x31];
  15. e1=normrnd(0,0.01,1,300);
  16. e2=normrnd(0,0.01,1,300);
  17. e3=normrnd(0,0.01,1,300);
  18. t=rand(1,300)*2;
  19. x1=t+e1;
  20. for i=1:300
  21.     x2(i)=2*t(i)^2-3*t(i)+e2(i);
  22. end
  23. for i=1:300
  24.     x3(i)=-t(i)^3+3*t(i)^2+e3(i);
  25. end
  26. for i=101:250
  27.     x2(i)=x2(i)-0.4;
  28. end
  29. tes=[x1;x2;x3];
  30. %standard the data
  31. [tr,meanp,stdp] = prestd(trian);
  32. te = trastd(tes,meanp,stdp);
  33. tr=tr';
  34. te=te';
  35. trd=data(tr);
  36. ted=data(te)
  37. [r,a]=train(kpca({kernel('rbf',1.581)}),trd);
  38. d=test(a,ted);
  39. val=a.e_val;
  40. vec=a.e_vec;
  41. dvec=d.X;
  42. s=inv(diag(val(1:10)));
  43. for i=1:300
  44.   tsquare(i)=dvec(i,1:10)*s*dvec(i,1:10)';
  45. end
  46. for i=1:300
  47.    spe(i)=dvec(i,10)^2;
  48.    for j=11:70
  49.         spe(i)=spe(i)+dvec(i,j)^2;
  50.     end
  51. end
  52. %cn=kpcak(te,tr,vec(:,1:4),s);