[r,p]=size(PC*PC');I=eye(r,p);[a,b]=size(tr);[a1,b1]=size(test);
e=tr*(I-PC*PC');for i=1:a;T(i)=tr(i,:)*PC*INVD*PC'*tr(i,:)';SPE(i)=e(i,:)*e(i,:)';
end
%SPEE=tr*(I-PC*PC')*tr';
计算控制限T2和控制限SPE
beta=0.99;
T2beta=numpc*(a-1)*(a+1)*finv(beta,numpc,a-numpc)/(a*(a-numpc));
theta=zeros(3,1);for i=1:3for j=numpc+1:b
theta(i)=theta(i)+lamda(j)^(i);
end
end
h0=1-2*theta(1)*theta(3)/3/(theta(2)^2);
SPEbeta=theta(1)*(norminv(beta)*sqrt(2*theta(2)*h0^2)/theta(1)+1+theta(2)*h0*(h0-1)/theta(1)^2)^(1/h0);
m =mean(SPE);%%m是建模数据集中所有测量数据的SPE统计量的均值
v =var(SPE);%%v是对应的方差
%SPEbeta = v/(2*m)*chi2inv(0.99,2*m.^2/v);%SPE的控制限
计算测试数据的T(i)和SPE(i)
e1=test*(I-PC*PC');
cout_T=0;
cout_SPE=0;for i=1:a1;T1(i)=test(i,:)*PC*INVD*PC'*test(i,:)';if i>=160&&T1(i)>T2beta
cout_T=cout_T+1;
end
SPE1(i)=e1(i,:)*e1(i,:)';if i>=160&&SPE1(i)>SPEbeta
cout_SPE=cout_SPE+1;
end
end
cout_T=cout_T/(a1-159);
cout_SPE=cout_SPE/(a1-159);
SPE+T2的综合指标
zonghe=1/T2beta*T+1/SPEbeta*SPE;
zh=ksdensity(zonghe,0.99,'function','icdf');
zonghe1=1/T2beta*T1+1/SPEbeta*SPE1;
cout_zh=0;
cout_zhF=0;for i=1:a1;if i<160&&zonghe1(i)>zh
cout_zh=cout_zh+1;
end
if i>=160&&zonghe1(i)>zh
cout_zhF=cout_zhF+1;
end
end
% count_m_zh=1-length(find(zonghe>zh))/960
cout_hh=cout_zhF/(a1-159)*100;
cout_hh_F=cout_zh/159*100;
求测试数据的贡献率
contribution=zeros(1,b);
contribution1=zeros(1,b1);for i=1:b;contribution(i)=(norm(e(:,i)))^2;% 即:对e1的每一列求平方和,即为贡献值;
end
for i=1:b1;contribution1(i)=(norm(e1(:,i)))^2;% 即:对e1的每一列求平方和,即为贡献值;
end