# Anomaly Detection for Hydraulic Power Units--A Case Study
## 2 Materials and Methods
### Algorithms Design
#### 2.2.4 Novelty Detection  
After implementing the approach described in Section 2.2.3, another was proposed and developed. The goal was to analyze data in higher dimensional space. Therefore, some black-box or gray-box algorithms could be used as they are capable of drawing conclusions from high dimensional data much more efficiently than by-hand analysis. The assumption was performed that all data we take into account in this approach are non-anomalies. Then, instead of anomaly detection, the task was novelty detection [51]. It was decided to use One Class SVM (OCSVM) [4] because it is easy to deploy with the scikit-learn Python package [52]. The principles of the OCSVM algorithm are as follows [53]. The training process involved taking only data that come from standard HPU working conditions according to the knowledge of domain experts from PONAR Wadowice. Therefore, we let the dataset of normal samples be:  
\[X=[x_{1},x_{2},\dots,x_{n}]^{T}\in R^{NxL} \tag{4}\]  
and the target decision hyperplane be:  
\[f(x)=\omega\phi(x)-\rho=0 \tag{5}\]  
Afterwards, the optimization problem could be constructed and solved:  
\[\min_{\omega\in F_{i}\in R^{N}}\frac{1}{2}||\omega||^{2}+\frac{1}{N_{v}}\sum_{ i=1}^{N}\xi_{i}-\rho \tag{6}\]  
\[s.t.\quad\omega\phi(x_{i})\geq\rho-\xi_{i},\xi_{i}\geq 0 \tag{7}\]  
where:  
* \(N\) is the length of the dataset used for training;
* \(v\) is the regularization parameter;
* \(\xi_{i}\) is the slack variable corresponding to each dataset;
* \(\omega\) and \(\rho\) are the decision planes that can be decided with participation;
* \(\phi\) denotes the way the data are spatially mapped [54]. The OCSVM model is obtained by introducing Lagrange multipliers \(\alpha_{i}\geq 0\) and \(\beta_{i}\geq 0\) and solving the Lagrange equations. \[L(\omega,\xi,\rho,\alpha,\beta)=\frac{1}{2}||\omega||2+\frac{1}{N_{v}}\sum_{i=1} ^{N}\xi_{i}-\rho-\sum_{i=1}^{N}\alpha_{i}[\omega\phi(x_{i})-\rho+\xi_{i}]-\sum_ {i=1}^{N}\beta_{i}\xi_{i} \tag{8}\]  
Partial differentiation of the variables in the above equations gives the pairwise form of the optimization problem [55]:  
\[\min_{\alpha}\alpha^{T}H\alpha \tag{9}\]  
\[s.t.\leq\alpha_{i}\leq\frac{1}{N_{v}},\sum_{i=1}^{N}\alpha_{i}=1 \tag{10}\]  
where \(H\) denotes the kernel matrix, the components of which are \(H_{ij}\), which can be expressed as:  
\[H_{ij}=K(x_{i},x_{j})=\phi(x_{i})\phi(x_{j}) \tag{11}\]  
where \(K(x_{i},x_{j})\) denotes the kernel function, that for the purpose of the article is the Gaussian kernel function. As for the RBF kernel function, only one parameter, denoted as \(\sigma\), is to be adjusted. This parameter directly affects the width of the RBF kernel function, and the calculation formula is presented in Equation (12). \[K(x_{i},x_{j})=\exp^{\frac{-||x_{i}-x_{j}||^{2}}{2\sigma^{2}}} \tag{12}\]  
The quadratic problem that is stated above leads to solving \(\alpha\), whereupon \(\omega\) and \(\rho\) can be computed separately as presented in Equations (13) and (14)  
\[\omega=\sum_{i=1}^{N}\alpha_{i}\phi(x_{i}) \tag{13}\]  
\[f(x)=\omega\phi(x)-\rho=0 \tag{5}\]0  
As a result, a decisional hyperplane in the feature space can be found from the solved \(\omega\) and \(\phi\). The decision function that is defined in Equation (15) is established for classifying the test sample \(z_{k}\) from the training set \(Z=[z_{1},z_{2},\ldots,z_{M}]^{T}\in R^{MxL}\). \[f(x)=\omega\phi(x)-\rho=0 \tag{5}\]1  
The sample is classified as a normal sample when the value of the decision function is positive, so when \(F(z_{k})=+1\). When the value of the decision function is negative, i.e., when \(F(z_{k})=-1\), the sample is classified as an abnormal sample because it falls outside the decision hyperplane. It was decided to take the following variables as input to the algorithm:  
* PressureBehindFilterMean;
* HighPressureMean;
* RotationSpeedMean;
* PressureBeforeFilterMean. The choice was dictated by the same logic as described in Section 2.2.1. These variables have the highest PCC in all available pairs of variables in the solution.