%Let Q be the (n × m) matrix of quality variables where n is the number |
%of observations and m the number of quality variables in the training phase. |
%Define the target class. |
T=target_class(+Q); |
%Use the KMDD algorithm to fit a sphere around the defined target class above, |
%where c1 is a fraction error on the target class and c2 is a parameter |
%defining the number of clusters. |
w = kmeans_dd(T,c1,c2); |
%Show the results of KMDD classifier. |
W=+w; |
%Phase I of the KM-chart: |
%Compute the Euclidean distance of each training observation and the UCL. |
n = size(T,1); |
D_training = sqrt(min(sqeucldistm(+T,W.w),,2)) repmat(W.threshold,n,1); |
%Phase II of the KM-chart: |
%Let now R be the (k x p) matrix of quality variables where k is the number |
%of observations and p the number of quality variables in the testing phase. |
%In Phase II we repeat the same computation as in Phase I but here we use |
%test data and compare it with the UCL to detect out-of-control states. |
%Compute the Euclidean distance of each test observation. |
m= size(R,1); |
D_test = sqrt(min(sqeucldistm(+R,W.w),,2)) repmat(W.threshold,m,1); |
y1=D_training(:,1); y2=D_training(:,2);x1=(1:n)’; |
y3=D_training(:,1); D_test(:,1); |
y4 =D_training(:,2); D_test(:,2);x2=(1:n+m)’; |
%Display the KM-chart for Phase I and II. |
figure; |
SUBPLOT(2,1,1), plot(x1,y1, ‘-o’, x1,y2, ‘-’); title(‘Phase I of the KM-chart’) |
SUBPLOT(2,1,2), plot(x2,y3, ‘-o’, x2,y4, ‘-’); title(‘Phase II of the KM-chart’) |