# Recurrent Neural Network-Based Hybrid Localization for Worker Tracking in an Offshore Environment
## 3 Materials and Methods
### Training of RHLS  
To perform positioning through the structure of RHLS, it is necessary to train weights and biases in the network using extensive data. As described in Section 3.2, the area in which positioning service is to be provided is firstly set, and then the intersection and end point of the deck corridor are marked. The wireless signal, accelerometer, geomagnetic, and gyroscope sensing values are collected by the moving distance between the points where the location is known. Steps are detected using the accelerometer value, and the direction is estimated using the geomagnetic and angular velocity values. Then, the location coordinates of the starting point and the ending point are labeled with the value using the time at which the step was detected. For the location value, the value is obtained by scaling the location coordinates to a value between zero and one using the maximum and minimum values among the recorded coordinate values. Finally, the data are divided, according to the time at which the Wi-Fi signal is input, to match the input value introduced above.  
A Wi-Fi scanning period is generally 3 to 4 s, and a person can walk at least three to four steps and at most six to eight steps during that time. Here, training is disrupted. In general, when training the RNN, an input sequence of a certain length is used, but considering the human step, the length of the input sequence is variable from three to eight. Naturally, when considering only the structure of the general RNN, the sequence needs not be constant. However, the longer the sequence is, the smaller the gradient value transmitted to the backpropagation becomes, such that smooth propagation is not achieved. Therefore, in general, the length of the sequence is fixed. However, in the case of this problem in which the sequence length is not constant, it is necessary to use an RNN cell that accepts the sequence length as additional information. The maximum length of the sequence is set to eight, and in the case of a sequence having a length shorter than this, only the information of the corresponding length is used. The RNN cell up to the maximum length was set to derive the zero vector as the output value, thereby solving the problem of the sequence length not being constant. On the one hand, when data exceed the limit set in relation to the mask used in the experiment, the limit must be increased and the input vector trained.  
If the length of the sequence is not constant, the output value has to be processed. This is because a zero vector is output after the length of the input sequence. These zero vectors are output as meaningless values through the long short-term memory (LSTM) module of the middle layer and the sigmoid layer of the output layer. Because this value generates and transmits an incorrect gradient during the backpropagation process, it is necessary to remove this value and use the output value only for the length of the input sequence. As a way to handle this, the output value is multiplied by a mask.  
The mask is a Boolean vector, which has a value of one as long as it has a valid value, and zero after that. For example, if the maximum sequence length is five, and the input sequence length is three, the mask is composed of [1 1 1 0 0], as shown in Figure 4. The final output value is then multiplied, leaving only valid values. Using this method, in batch training, where different input sequences are input and trained at the same time, training can be performed without being influenced by a false gradient.