# Fault-Tolerant Model Predictive Control Applied to a Sewer Network
## 2 Theoretical Framework
### Principal Components Analysis (PCA)  
This method has two advantages: on the one hand, it allows data from a higher-dimensional space to be represented in a reduced-dimensional space, and on the other hand, it transforms the original correlated variables into new uncorrelated variables, which facilitates the understanding of the data [16; 17; 18; 19]. A matrix \(\mathbf{X}\in\Re^{mxm}\) representing \(n\) data taken from \(m\) process variables is arranged. So that all variables are equally considered, it is necessary to normalize the data of the matrix by columns with a mean of zero and variance of one, \(\mathbf{X_{n}}\). From this matrix, the covariance matrix \(\mathbf{S}\) is calculated and decomposed using singular value decomposition (SVD):  
\[\mathbf{S}=\frac{1}{n-1}\mathbf{X}_{n}{}^{T}\mathbf{X}_{n}=\mathbf{V}\Lambda \mathbf{V}^{T}, \tag{2}\]  
where \(\Lambda\in\Re^{mxm}\) is a diagonal matrix formed by the non-negative real eigenvalues in decreasing order of \(R\) (\(\lambda_{1}\geq\lambda_{2}\geq\cdots\geq\lambda_{m}\geq 0\)) and \(\mathbf{V}\) is formed by the eigenvectors of \(\mathbf{S}\). The principal components can be obtained as:  
\[\mathbf{T}=\mathbf{X}_{n}\mathbf{P}, \tag{3}\]  
where \(\mathbf{P}\) is formed taking the first \(a\) columns of \(\mathbf{V}\) (also called _loadings_), and \(\mathbf{T}\) are the \(a\) principal components of \(\mathbf{X}_{n}\). Each of the components of new space \(\mathbf{T}\) are called _scores_. An important aspect to consider is what criteria to apply when selecting the number of principal components \(a\). One method is based on selecting the number of principal components until a limit of variance (CPV) is reached. CPV values between 80% and 90% are usually selected. This method has been applied in this work. There are different statistics for monitoring a process considering the PCA by generating control charts to monitor the state of the process. The most used for this task are:  
* Hotelling statistician (T\({}^{2}\)): For an observation vector \(x\in\Re^{mx1}\), this index is defined as: \[T^{2}=x^{T}\mathbf{P}\Lambda_{a}^{-1}\mathbf{P}^{T}x,\] (4) where \(\Lambda_{a}\) has been created with the first rows and columns of \(\Lambda\), and \(a\) is the number of principal components selected. If this index exceeds a preset threshold, it follows that the process is not operating normally, that is, a fault has occurred. The threshold can be calculated offline using historical data, as follows:  
\[T_{a}^{2}=\frac{a\big{(}n^{2}-1\big{)}}{n(n-a)}F_{a}(a,n-a), \tag{5}\]  
where \(n\) is the number of samples that have been considered for the calculation of the PCA, and \(F_{a}(a,n-a)\) is the critical value of the function \(F\) (Fisher-Snedecor \(F\) distribution) with \(n\) and \(n-a\) degrees of freedom and \(\alpha\) the significance level, which will specify the degree of false alarm commitment. Its typical values vary between 0.01 and 0.05. * \(Q\) or SPE statistician: This index is known as a squared prediction error (SPE). It is calculated from an observation vector \(x\in\Re^{mx1}\) as: \[Q=r^{T}r,\ r=\Big{(}\mathbf{I}-\mathbf{P}\mathbf{P}^{T}\Big{)}x,\] (6) where \(r\) is the residue vector, and \(\mathbf{I}\) is the identity matrix \(mxm\). As for the \(T^{2}\) index, a threshold can be calculated to determine when the process stops operating normally. This threshold is obtained from historical data taken offline for the PCA:  
\[Q_{\alpha}=\frac{v}{2\mu}\chi_{\alpha}^{2}(1-\alpha,h)^{-1},\ h=2\frac{\mu^{2} }{v}, \tag{7}\]  
with \(\chi_{\alpha}^{2}(1-\alpha,h)^{-1}\) being the inverse of accumulative function \(\chi^{2}\), \(\alpha\) is the tolerance index to false alarms and \(\mu\) and \(v\) are the mean and variance of \(Q\), respectively. If the process is operating normally, the \(Q\) index measures noise fluctuations. When an abnormal event occurs that affects the covariance of \(\mathbf{X}\), it is detected because the \(Q\) statistic would exceed the set threshold.