# Small-Scale Zero-Shot Collision Localization for Robots Using RL-CNN
## 4 Proposed Two-Stage Collision Localization Method
### Proposed RL-CNN Method
For an input vibration signal \(S\) of size (\(L\), \(N\), \(C_{in}\)), where \(L\), \(N\), and \(C_{in}\) represent the length of the input, the width of the input, and the channel of the input, respectively, assuming that the kernel size of the convolutional layer is (\(K\), \(K\)), the channel in the convolutional layer is \(C_{cl}\), the stride is \(s\), and then the feature extracted by the convolutional layer can be described as:  
\[CO_{i,j,h}=R\left(\sum_{k=0}^{K-1}\sum_{k=0}^{K-1}\sum_{c=0}^{C_{in}-1}S_{(i<s+ k),(j<s+k),c}W_{k,k,c,h}+b_{h}\right), \tag{1}\]  
where \(W\) and \(b\) are the weight matrix and bias vector of the convolutional layer, respectively. In the convolution operation, the index \(i\) and \(j\) correspond to the spatial location of the output feature map. The index \(c\) and \(h\) represent the number of the input channel and the output channel, respectively. \(R\) represents the activation function. Assuming the padding is \(p\), the output of the convolutional layer, denoted by \(CO\), is a tensor of size (\(\frac{L-K+2p}{s}+1\), \(\frac{N-K+2p}{s}+1\), \(\frac{N-K+2p}{s}+1\), \(C_{cl}\)), representing the activation maps of the convolutional layer. Among this process, the batch normalization is applied to the feature maps before the feature maps are activated to lead to improved accuracy and faster convergence during training. In addition to the convolutional layer, we also incorporate a max pooling layer into our model. The max pooling operation is applied to each activation map independently, and when assuming the stride in the max pooling is also set as \(s\), the output of the max pooling layer is a tensor of size (\(\frac{L-K+2p}{s^{2}}+\frac{1-d}{s}+1\), \(\frac{N-K+2p}{s^{2}}+\frac{1-d}{s}+1\), \(C_{cl}\)), where the pooling window size is (\(d\),\(d\)). After the last max pooling layer, the output feature maps are flattened and passed through two or three fully connected layers. Finally, the output of the last fully connected layer is activated by the softmax activation function in order to serve as a criterion for collision localization. When considering the time complexity of the proposed RL-CNN, it is necessary to analyze the time complexity of each component. Here, we need to consider the time complexity of the convolutional layers, batch normalization layers, max pooling layers, and fully connected layers. Compared to these four components, the impact of the activation functions on the overall time complexity can be neglected. When using the relevant parameters provided above and ignoring the influence of bias, the time complexity of the first convolutional layer can be expressed as:  
\[T_{c1}=O\bigg{(}K^{2}C_{in}C_{cl}\bigg{(}\frac{L-K}{s}+1\bigg{)}\bigg{(}\frac {N-K}{s}+1\bigg{)}\bigg{)}, \tag{2}\]  
When the network is relatively shallow and the number of filters in each convolutional layer is the same, the time complexity of the first convolutional layer can represent that of a generic convolutional layer in RL-CNN. The complexity of this component can be described as:  
\[T_{c}=T_{c1}=O\bigg{(}K^{2}C_{in}C_{cl}\bigg{(}\frac{L-K}{s}+1\bigg{)}\bigg{(} \frac{N-K}{s}+1\bigg{)}\bigg{)}, \tag{3}\]  
Based on similar reasons, the computational complexity of the batch normalization and max pooling layers can be expressed as follows, respectively:  
\[T_{b}=O\bigg{(}\bigg{(}\frac{L-K+2p}{s}+1\bigg{)}\bigg{(}\frac{N-K+2p}{s}+1 \bigg{)}C_{cl}\bigg{)}, \tag{4}\]  
\[T_{m}=O\bigg{(}\bigg{(}\frac{L-K+2p}{s^{2}}+\frac{1-d}{s}+1\bigg{)}\bigg{(} \frac{N-K+2p}{s^{2}}+\frac{1-d}{s}+1\bigg{)}C_{cl}\bigg{)}, \tag{5}\]  
Although the number of fully connected layers in the root and leaf stages is different, for the purpose of the time complexity analysis, we only need to consider the upper bound, which can be achieved by assuming that there are three fully connected layers. Let the number of nodes in these layers be \(N_{1}\), \(N_{2}\), and \(N_{3}\) and let \(O_{m}\) be the dimension of the flattened output from the last max pooling layer.