------------------------------------------------------------------------- | RBC_ind_struct = compute_RBC(X, PCA_struct) | ------------------------------------------------------------------------- ----------------- | FUNCTIONALITY | ------------------------------------------------------------------------- | This function aim is to compute the reconstruction-based | | contributions (RBC) to an observation dataset (X). The RBC is | | computed for the squarred prediction error (SPE), the Hottelling's | | T^2 statistic and the combined index Phi. | ------------------------------------------------------------------------- -------------------- | INPUT PARAMETERS | ------------------------------------------------------------------------- | X: Dataset containing the observations to compute the RBC | | for the three different indices. X can be either an auto | | scaled vector or a matrix of real values. | | PCA_struct: Structure that contains the information of a PCA model. | | This structure must have the following fields, at least: | | -> P. The loading matrix used to project new observations | | into the PCA model. | | -> lambda. Row vector containing the eigenvalues | | associated to the retained principal components. | | -> SPE_lim. Limit for the SPE index. | | -> T2_lim. Limit for the Hottelling's T^2 statistic. | ------------------------------------------------------------------------- --------------------- | OUTPUT PARAMETERS | ------------------------------------------------------------------------- | RBC_ind_struct: Structure containing the RBC index for the | | observation's dataset. This structure contains the | | following information for each index (SPE, T^2 and | | Phi, which are the main fields of the structure): | | -> RBC. Matrix containing the reconstruction-based | | contribution for each variable (column) and | | observation (row). | | -> RBC_fd. Logical (with only 0's and 1's) matrix | | that indicates which variables surpass the RBC | | control limit. Rows of this matrix refer to | | observations, while columns are the different | | variables. | | -> RBC_limit. Row vector containing the RBC control | | limit for each variable. | -------------------------------------------------------------------------
0001 % ------------------------------------------------------------------------- 0002 % | RBC_ind_struct = compute_RBC(X, PCA_struct) | 0003 % ------------------------------------------------------------------------- 0004 % ----------------- 0005 % | FUNCTIONALITY | 0006 % ------------------------------------------------------------------------- 0007 % | This function aim is to compute the reconstruction-based | 0008 % | contributions (RBC) to an observation dataset (X). The RBC is | 0009 % | computed for the squarred prediction error (SPE), the Hottelling's | 0010 % | T^2 statistic and the combined index Phi. | 0011 % ------------------------------------------------------------------------- 0012 % -------------------- 0013 % | INPUT PARAMETERS | 0014 % ------------------------------------------------------------------------- 0015 % | X: Dataset containing the observations to compute the RBC | 0016 % | for the three different indices. X can be either an auto | 0017 % | scaled vector or a matrix of real values. | 0018 % | PCA_struct: Structure that contains the information of a PCA model. | 0019 % | This structure must have the following fields, at least: | 0020 % | -> P. The loading matrix used to project new observations | 0021 % | into the PCA model. | 0022 % | -> lambda. Row vector containing the eigenvalues | 0023 % | associated to the retained principal components. | 0024 % | -> SPE_lim. Limit for the SPE index. | 0025 % | -> T2_lim. Limit for the Hottelling's T^2 statistic. | 0026 % ------------------------------------------------------------------------- 0027 % --------------------- 0028 % | OUTPUT PARAMETERS | 0029 % ------------------------------------------------------------------------- 0030 % | RBC_ind_struct: Structure containing the RBC index for the | 0031 % | observation's dataset. This structure contains the | 0032 % | following information for each index (SPE, T^2 and | 0033 % | Phi, which are the main fields of the structure): | 0034 % | -> RBC. Matrix containing the reconstruction-based | 0035 % | contribution for each variable (column) and | 0036 % | observation (row). | 0037 % | -> RBC_fd. Logical (with only 0's and 1's) matrix | 0038 % | that indicates which variables surpass the RBC | 0039 % | control limit. Rows of this matrix refer to | 0040 % | observations, while columns are the different | 0041 % | variables. | 0042 % | -> RBC_limit. Row vector containing the RBC control | 0043 % | limit for each variable. | 0044 % ------------------------------------------------------------------------- 0045 0046 function RBC_ind_struct = compute_RBC(X, PCA_struct) 0047 %% INITIALISATIONS. 0048 % In this step we will initialise the different variables to use throughout 0049 % all the function. 0050 % Firstly, we create the variable that we will use to get the RBC for each 0051 % variable (an identity matrix with as many rows and columns as variables 0052 % the observation matrix has). 0053 Xi = eye(size(X, 2)); 0054 % Next, we compute the different variables required to compute the RBC 0055 % values for each of the three indices (SPE, T^2 and Phi). 0056 % - Related with the SPE index. 0057 % -- Residual covariance matrix. 0058 C_res = Xi - PCA_struct.P * PCA_struct.P'; 0059 % - Related with the T^2 index. 0060 % -- Diagonal matrix containing the eigenvalues associated to the retained 0061 % principal components inverted (each element in the diagonal is equal 1 / 0062 % sqrt(lambda(i)). 0063 Lambda_Inv = diag(1 ./ sqrt(PCA_struct.lambda)); 0064 % -- Since Lambda contains zeros except in the diagonal, we can't invert it 0065 % directly. In this case, we have to invert only the elements of the 0066 % diagonal. This is equivalent to create a diagonal matrix whose values are 0067 % 1 / sqrt(Lambda) 0068 % -- Matrix containing the rescaled loading vectors. 0069 D = PCA_struct.P * Lambda_Inv * PCA_struct.P'; 0070 % - Related with the combined index Phi. 0071 % -- Matrix to compute the combined index Phi for new observations. 0072 Phi = C_res / PCA_struct.SPE_lim + D / PCA_struct.T2_lim; 0073 % Now, we initialise a set of variables associated to the computation of 0074 % each RBC index control limit and values. 0075 % - Related to the SPE. 0076 % -- Amplitude of the chi-square distribution to compute the RBC control 0077 % limit. 0078 amplitude_SPE = zeros(1, size(Xi, 2)); 0079 % -- Matrix to store the RBC of the SPE index. 0080 RBC_SPE = zeros(size(X)); 0081 % - Related to the T^2. 0082 % -- Amplitude of the chi-square distribution to compute the RBC control 0083 % limit. 0084 amplitude_T2 = zeros(1, size(Xi, 2)); 0085 % -- Matrix to store the RBC of the SPE index. 0086 RBC_T2 = zeros(size(X)); 0087 % - Related to the combined index Phi. 0088 % -- Amplitude of the chi-square distribution to compute the RBC control 0089 % limit. 0090 amplitude_Phi = zeros(1, size(Xi, 2)); 0091 % -- Matrix to store the RBC of the SPE index. 0092 RBC_Phi = zeros(size(X)); 0093 0094 %% COMPUTING THE RBC FOR EACH INDEX. 0095 % In this cell, the RBC information for each index is computed and added to 0096 % the RBC structure. 0097 0098 % Firstly, we will compute the reconstruction-based contributions limits 0099 % for each index. 0100 % - For each fault direction... 0101 for i = 1:size(Xi, 2) 0102 % -- Firstly, we compute the amplitude of the RBC for each index. 0103 % --- SPE index. 0104 amplitude_SPE(i) = Xi(:, i)' * C_res * PCA_struct.R * ... 0105 C_res * Xi(:, i) / (Xi(:, i)' * C_res * Xi(:, i)); 0106 % --- T^2 index. 0107 amplitude_T2(i) = Xi(:, i)' * D * PCA_struct.R * D * Xi(:, i) / ... 0108 (Xi(:, i)' * D * Xi(:, i)); 0109 % --- Phi index. 0110 amplitude_Phi(i) = Xi(:, i)' * Phi * PCA_struct.R * Phi * ... 0111 Xi(:, i) / (Xi(:, i)' * Phi * Xi(:, i)); 0112 % -- At the same time, we compute the RBC to the i-th variable. 0113 % --- SPE index. 0114 RBC_SPE(:, i) = (Xi(:, i)' * C_res * X') .^ 2 / C_res(i,i); 0115 % --- T^2 index. 0116 RBC_T2(:, i) = (Xi(:, i)' * D * X') .^ 2 / D(i,i); 0117 % --- Phi index. 0118 RBC_Phi(:, i) = (Xi(:, i)' * Phi * X') .^ 2 / Phi(i,i); 0119 end 0120 % Now that we have the amplitudes of the chi-square distribution, we can 0121 % compute the control limits for the RBC of each index. 0122 % - SPE index. 0123 RBC_SPE_limit = amplitude_SPE * chi2inv(0.95, 1); 0124 % - T^2 index. 0125 RBC_T2_limit = amplitude_T2 * chi2inv(0.95, 1); 0126 % - Phi index. 0127 RBC_Phi_limit = amplitude_Phi * chi2inv(0.95, 1); 0128 0129 % Next, using the control limits we have just found, we determine the 0130 % sensors that surpass the control limit for each observation. 0131 % - SPE index. 0132 RBC_SPE_fd = RBC_SPE > repmat(RBC_SPE_limit, size(RBC_SPE, 1), 1); 0133 % - T^2 index. 0134 RBC_T2_fd = RBC_T2 > repmat(RBC_T2_limit, size(RBC_T2, 1), 1); 0135 % - Combined index Phi. 0136 RBC_Phi_fd = RBC_Phi > repmat(RBC_Phi_limit, size(RBC_Phi, 1), 1); 0137 0138 %% STRUCTURE BUILDING. 0139 % Now that we have all the information, we can create the structure to 0140 % store the information related to the reconstruction-based contributions. 0141 % - Information related to the SPE index: 0142 % -- RBC control limit. 0143 RBC_ind_struct.SPE.RBC_limit = RBC_SPE_limit; 0144 % -- RBC values. 0145 RBC_ind_struct.SPE.RBC = RBC_SPE; 0146 % -- Variables whose RBC values are over the control limits. 0147 RBC_ind_struct.SPE.RBC_fd = RBC_SPE_fd; 0148 % - Information related to the T^2 index: 0149 % -- RBC control limit. 0150 RBC_ind_struct.T2.RBC_limit = RBC_T2_limit; 0151 % -- RBC values. 0152 RBC_ind_struct.T2.RBC = RBC_T2; 0153 % -- Variables whose RBC values are over the control limits. 0154 RBC_ind_struct.T2.RBC_fd = RBC_T2_fd; 0155 % - Information related to the combined index Phi: 0156 % -- RBC control limit. 0157 RBC_ind_struct.Phi.RBC_limit = RBC_Phi_limit; 0158 % -- RBC values. 0159 RBC_ind_struct.Phi.RBC = RBC_Phi; 0160 % -- Variables whose RBC values are over the control limits. 0161 RBC_ind_struct.Phi.RBC_fd = RBC_Phi_fd;