# Neural Network System for Predicting Anomalous Data in Applied Sensor Systems
## 2 Materials and Methods
### Development of the Preprocessor Model  
The preprocessor (Figure 2) prepares the training dataset for the neural network in the predictor subsystem and consists of the following components: an analyzer, restorer, outlier detector, and normalizer. The analyzer extracts sensor data from storage and converts it into a format suitable for further processing. The restorer then replaces missing values with synthetic ones. The outlier detector identifies anomalous points and replaces them with NULL. The processed data passes through the restorer again for outlier replacement. The normalizer forms normalized subsequences, which become the training dataset for the neural network.  
The restorer uses the SARIMAX model to predict missing values and replace them with synthetic ones [33; 34]. The SARIMAX model is defined by the equation:  
\[y_{t}=c+\varphi_{1}\cdot y_{t-1}+\varphi_{2}\cdot y_{t-2}+\ldots+\varphi_{p} \cdot y_{t-p}+\varepsilon_{t}+\theta_{1}\cdot\varepsilon_{t-1}+\ldots+\theta_ {q}\cdot\varepsilon_{t-q}+\beta\cdot X_{t}, \tag{1}\]  
where \(c\) is a constant, \(\varphi_{1}\), \(\ldots\), \(\varphi_{p}\) are the autoregressive coefficients, \(\theta_{1}\), \(\ldots\), \(\theta_{q}\) are the moving average coefficients, \(\varepsilon_{t}\) is the white noise, and \(X_{t}\) are the exogenous regressors. If \(t_{i}\) = NULL, then  
\[t_{i}=\hat{y}_{i}, \tag{2}\]  
where \(\hat{y}_{i}\) is the predicted value obtained using the SARIMAX model. To check stationarity, the Dickey-Fuller and KPSS tests are used [35; 36]. If the series is not stationary, transformations such as logarithms are applied to prepare the data for analysis.  
The analyzer retrieves the time series \(T\) from the data store, where \(T=(t_{1},t_{2},\ldots,t_{m})\), and each value \(t_{i}\) belongs to the real numbers \(\mathbb{R}\) set or is empty (equal to NULL), that is  
\[T=\{t_{i}|t_{i}\in\mathbb{R}\;\;\text{or}\;\;t_{i}=NULL,\;\;i=1,2,\ldots,m\}. \tag{3}\]  
The normalizer then creates a training dataset consisting of \"readings sequence\" and \"predicted value\" pairs. The first element of a pair is the fixed-length sensor readings  
Figure 2: Block diagram of the preprocessor model.  
normalized subsequence, and the second element is a single normalized sensor reading following this subsequence. The normalizer transforms the time series into a set of normalized subsequences using min-max normalization. The sequence \(T_{i,n}\) of the time series \(T\) with length \(n\) is defined as  
\[T_{i,n}=(t_{i},\ldots,t_{i+n-1}),\,1\leq i\leq m-n+1. \tag{4}\]  
Using min-max normalization, for a subsequence \(T_{i,n}\), its normalized version \(\widetilde{T}_{i,n}\) is calculated as  
\[\widetilde{T}_{i,n}=\big{(}\widetilde{t}_{i},\ldots,\widetilde{t}_{i+n-1} \big{)}, \tag{5}\]  
where  
\[\widetilde{t}_{i}=\frac{t_{i}-t_{\text{min}}}{t_{\text{max}}-t_{\text{min}}},j \in\{i,i+1,\ldots,i+n-1\}, \tag{6}\]  
where \(t_{\text{min}}\) and \(t_{\text{max}}\) are the minimum and maximum values in \(T_{i,n}\).  
For a normalized subsequence \(\widetilde{T}_{i,n}\), the element \(\widetilde{t}_{n+1}\) is considered as its predicted value. The training sample is formed from pairs (subsequence, predicted value):  
\[S_{T}^{n}=\Big{\{}\Big{(}\widetilde{T}_{i,n},\widetilde{t}_{n+1}\Big{)}|1 \leq i\leq m-n\Big{\}}. \tag{7}\]  
The subsequence length \(n\) (\(n<<m\)) is the Cleanup Module parameter and is calculated as  
\[n=f_{sensor}\cdot horizon, \tag{8}\]  
where \(f_{sensor}\) is the sensor frequency and \(horizon\) is the historical horizon (the time interval length in the past) used by the predictor and selected by the human operator.