# Application of Neural Networks for Water Meter Body Assembly Process Optimization
## 2 Materials and Methods
### Assumptions of a Neural Network  
The goal of ANN was to assess the influence of particular parameters of the assembly process on the magnitude of axle radial runout in the water meter body. The first step was to prepare the training set, which consisted of the input and output data. Previously presented dimensional characteristics of the body and selected parameters of the assembly process served as the input data. After preparing the set of training data, the individual numerical values were normalized to obtain independence between them and at the same time to ensure their equivalence. To normalize initial variables, which values were in different ranges, linear transformation was used. This approach allowed us to represent each variable in a range between 0 and 1. Data were normalized using the rescaling function, dividing the difference between the original and minimal values, by the range of data set, according to the equation:  
\[X^{*}=\frac{X-\text{min}(X)}{\text{max}(X)-\text{min}(X)} \tag{2}\]  
Quantitative variables were converted according to the min-max function to numbers in the range 0-1. Qualitative variables were assigned values of 0, when the feature was not obtained, and values of 1, otherwise. Training the neural network in order to obtain the appropriate efficiency is based on minimizing the prediction error function, defined by the sum of squared residuals (SSR), described as follows:  
\[SSR=\sum_{i=1}^{n}(y_{i}-y_{i}^{*})^{2} \tag{3}\]  
where: \(n\)--number of training examples, \(y_{i}\)--expected network output value, \(y_{i}\)*--measured network output value. Mentioned error function calculates the divergence between the network output values and the a priori output values form teaching set of data. The error surface has paraboloid shape with one distinct minimum. The network error is calculated iteratively after each repetition of training algorithm--epoch. Based on its value, it is possible to assess and modify only those weights that are associated with neurons in the last layer. Weights of signals in remaining layers can be trained by using backpropagation algorithm. In this approach each neuron has an assigned error value, calculated based on the error value of all those neurons, to which it sends its output value. The backpropagation algorithm is applied in the reverse direction from normal data flow, i.e., from output to input. The efficiency of a neural network is defined as the ratio of correctly approximated or classified cases to all cases included in the data set. Network performance can be influenced by following parameters: the number of hidden layers, number of neurons in each layer, existence of an additional neuron--bias, network learning rules, including the learning algorithm and activation function. Mentioned parameters were empirically selected to achieve the best prediction efficiency. Each set of process data, prepared for passing to the network has to be divided into three groups:  
(1) A sequence of training data, selected to allow the mapping of the considered prediction task;  
(2) Test data checking the network operation, including the assessment of changes made during subsequent learning cycles;(3) Verification data evaluating network efficiency based on the set of data, which was not used before. The data were divided into three groups: teaching (70%), testing (15%) and validation (15%). The division of datasets into each of these groups was done using K-Fold cross validation. Size and number of hidden layers are set empirically, training the network multiple times. This approach allows us to find balance between its overgrown structure and performance. The output layer of the ANN is a set of neurons, determining output signals. The number of neurons in the output layer is identical to the number of output data constituting the result of the network. The number of neuron inputs is related to the number of signals that are either the fed to the network or are output signals from preceding layer.