test_sample_my.m
资源名称:KPCA.rar [点击查看]
上传用户:nxf103
上传日期:2017-12-04
资源大小:2690k
文件大小:1k
源码类别:
能源行业(电力石油煤炭)
开发平台:
Matlab
- %generate train date&test data
- %this sample is from "Nonlinear process monitoring using kernel principal component analysis"
- e11=normrnd(0,0.01,1,100);
- e21=normrnd(0,0.01,1,100);
- e31=normrnd(0,0.01,1,100);
- t1=rand(1,100)*2;
- x11=t1+e11;
- for i=1:100
- x21(i)=2*t1(i)^2-3*t1(i)+e21(i);
- end
- for i=1:100
- x31(i)=-t1(i)^3+3*t1(i)^2+e31(i);
- end
- trian=[x11;x21;x31];
- e1=normrnd(0,0.01,1,300);
- e2=normrnd(0,0.01,1,300);
- e3=normrnd(0,0.01,1,300);
- t=rand(1,300)*2;
- x1=t+e1;
- for i=1:300
- x2(i)=2*t(i)^2-3*t(i)+e2(i);
- end
- for i=1:300
- x3(i)=-t(i)^3+3*t(i)^2+e3(i);
- end
- for i=101:250
- x2(i)=x2(i)-0.4;
- end
- tes=[x1;x2;x3];
- %standard the data
- [tr,meanp,stdp] = prestd(trian);
- te = trastd(tes,meanp,stdp);
- tr=tr';
- te=te';
- %trd=data(tr);
- %ted=data(te)
- [r,a]=train(kpca({kernel('rbf',1.581)}),trd);
- d=test(a,ted);
- val=a.e_val;
- vec=a.e_vec;
- dvec=d.X;
- s=inv(diag(val(1:10)));
- for i=1:300
- tsquare(i)=dvec(i,1:10)*s*dvec(i,1:10)';
- end
- for i=1:300
- spe(i)=dvec(i,10)^2;
- for j=11:70
- spe(i)=spe(i)+dvec(i,j)^2;
- end
- end
- %cn=kpcak(te,tr,vec(:,1:4),s);