## 5 Explanation of the Functioning of the Artificial Neural Network: Classification Part
### Neural Network for Recognizing Movement Commands  
The neural network used to recognize the patterns of spectral waveforms was a diagram with 516 inputs (see Section 4.1) consisting of 4 hidden layers, composed successively of layers of 20, 15, 15 and 20 hyperbolic tangent neurons, as well as one layer as output (Figure 15). The last layer had four exits, but only three were move commands. The fourth  
Figure 14: An example of a nervous blink tic.  
Figure 13: An example of a nervous tic involving the neck muscle tightening.  
output represented the person's resting state. It was necessary to distinguish it in the signal to avoid distortions in the classification of traffic commands.  
Hidden layers consisting of hyperbolic tangent activation functions (_tansig_) as represented by the following relationship [48]:  
\[f(x)=tanh(x)=\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}}. \tag{5}\]  
The adopted function in the analyzed case gave better results and a wider range of possibilities due to the values being in the range \(<\)\(-\)1,1\(>\). It was therefore different from the sigmoidal form, which only takes non-negative results.  
The neural network was trained with the input data set **IM** (input movement) (Equation (6)) and the output **OM** (output movement) (Equation (7)). The training set was composed of 516 network inputs denoting the **L** matrix, i.e., the matrix composed of one-second spectral waveforms of the F7, Fp1, F8 and Fp2 channels. They were marked as the matrix of patterns \(iM\) with the number of lines \(aM=516\). The set of initial training data was represented as \(oM\) with the number of lines \(bM=4\). This state of affairs was naturally dictated by the requirements of the network used. It was necessary to recognize four different states.  
\[\textbf{IM}=\begin{bmatrix}\textbf{iM}^{(\textbf{1})}\\ \vdots\\ \textbf{iM}^{(\textbf{aM})}\end{bmatrix}=\begin{bmatrix}iM_{1}^{(1)}&iM_{2}^{( 1)}&\ldots&iM_{n}^{(1)}\\ iM_{1}^{(2)}&iM_{2}^{(2)}&\ldots&iM_{n}^{(2)}\\ \vdots&\vdots&\vdots&\vdots\\ iM_{1}^{(515)}&iM_{2}^{(515)}&\ldots&iM_{n}^{(515)}\\ iM_{1}^{(516)}&iM_{2}^{(516)}&\ldots&iM_{n}^{(516)}\end{bmatrix}. \tag{6}\]  
The discussed matrix of output patterns was presented in accordance with the relationship:  
\[\textbf{OM}=\begin{bmatrix}\textbf{oM}^{(\textbf{1})}\\ \vdots\\ \textbf{oM}^{(\textbf{bM})}\end{bmatrix}=\begin{bmatrix}oM_{1}^{(1)}&oM_{2}^{( 1)}&\ldots&oM_{n}^{(1)}\\ \vdots&\vdots&\vdots&\vdots\\ oM_{1}^{(\textbf{4})}&oM_{2}^{(\textbf{4})}&\ldots&oM_{n}^{(4)}\end{bmatrix}. \tag{7}\]  
The input and output training patterns covered the same number of elements, and it was selected by trial and error. Thus, it was established that the set consisting of \(n=1230\) gave satisfactory results for the classification. The learning results are presented in Figure 16.  
Observing the neural network training confusion matrix from Figure 16, it can be seen that the training of the neural network on the patterns was very successful. Taking into account the training, validation and test matrices, it can be concluded that the percentages of the results of these treatments were equal or close to 100%.  
Figure 15: Expert system based on two neural networks.