# Sensor-Based Hand Gesture Detection and Recognition by Key Intervals
## 3 Proposed Algorithm
### Training Operations
Let \(\mathcal{I}_{\text{rx}}\) and \(\mathcal{I}_{\text{rx}}\) be the set of indices belong to PKI and SKI of the gesture, respectively. They are then given by  
\[\mathcal{I}_{\text{rx}} = \{t:u_{\text{rx}}-\frac{I}{2}\leq t\leq u_{\text{rx}}+\frac{I}{2 }\}, \tag{6}\] \[\mathcal{I}_{\text{sxt}} = \{t:u_{\text{sxt}}-\frac{I}{2}\leq t\leq u_{\text{sxt}}+\frac{I}{2 }\}. \tag{7}\]  
Figure 3: An example of labelling process for a training sequence \(S\) containing only a single gesture. The \(P_{f}\) and \(P_{s}\) of the top graph are the locations of the start and final samples of the gesture, respectively. The \(u_{c}\) of the top graph is the centroid of the gesture. The second graph marks the locations of \(u_{\text{rx}}\) and \(u_{\text{sxt}}\) as black arrows. The third, fourth, and the bottom graphs reveal the Gaussian-like ground truth of the gesture for PKI score, SKI score, and classification score, respectively. Assume class \(g\) is the ground truth of the gesture. Furthermore, let \(F_{t,j}\), \(G_{t,j}\) and \(H_{t,j}\) be the ground truth of the PKI score, SKI score, and classification score associated with class \(j\) for the window \(S_{t}\). In this study, a Gaussian-like function was adopted for the assignments of \(F_{t,g}\), \(G_{t,g}\), and \(H_{t,g}\) as follows. \[F_{t,g} = \left\{ \begin{array}{ll}1&,\text{if }t\in\mathcal{I}_{\text{ rx}},\\ e^{-(|t-u_{\text{rx}}|-\frac{j}{2})^{2}/2\sigma^{2}}&,\text{otherwise}.\end{array} \right. \tag{8}\] \[G_{t,g} = \left\{ \begin{array}{ll}1&,\text{if }t\in\mathcal{I}_{\text{ rx}},\\ e^{-(|t-u_{\text{rx}}|-\frac{j}{2})^{2}/2\sigma^{2}}&,\text{otherwise}.\end{array} \right.\] (9) \[H_{t,g} = \left\{ \begin{array}{ll}1&,\text{if }t\in\mathcal{I}_{R},\\ e^{-(|t-u_{\text{rx}}|-\frac{j}{2})^{2}/2\sigma^{2}}&,\text{otherwise}.\end{array} \right. \tag{10}\]  
Examples of \(F_{t,g}\), \(G_{t,g}\), and \(H_{t,g}\) are shown in the third, fourth, and bottom graphs of Figure 3, respectively. After the ground truth of the PKI score, SKI score, and classification score associated with class \(g\) are determined, we then compute the ground truth of the scores of the other classes \(j\), \(j\
eq g\), as  
\[F_{t,j} = \left\{ \begin{array}{ll}0&,j\
eq g,j=1,...,K,\\ 1-F_{t,g}&,j=K+1.\end{array} \right. \tag{11}\] \[G_{t,j} = \left\{ \begin{array}{ll}0&,j\
eq g,j=1,...,K,\\ 1-G_{t,g}&,j=K+1.\end{array} \right.\] (12) \[H_{t,j} = \left\{ \begin{array}{ll}0&,j\
eq g,j=1,...,K,\\ 1-H_{t,g}&,j=K+1.\end{array} \right. \tag{13}\]  
Based on the assignment, it can be easily shown that  
\[\sum_{j=1}^{K+1}F_{t,j}=1,\ \sum_{j=1}^{K+1}G_{t,j}=1,\ \ \sum_{j=1}^{K+1}H_{t,j}=1. \tag{14}\]  
The constraints in Equation (14) for the ground truth of the scores are consistent with those in Equation (1) for the scores produced by the proposed network model. Let \(J\) be the loss function for the training of the proposed network model for a training sequence \(S\). In this study, \(J\) was given by  
\[J=A+B+C, \tag{15}\]  
where \(A\), \(B\), and \(C\) are the loss function for the PKI score, SKI score, and classification scores produced by the proposed neural network model from the training sequence \(S\), respectively. A variant of the focal loss function [24] was adopted for the functions \(A\), \(B\), and \(C\). That is,  
\[A=\sum_{t}A_{t},\ B=\sum_{t}B_{t},\ C=\sum_{t}C_{t}, \tag{16}\]  
where \(A_{t}\), \(B_{t}\), and \(C_{t}\) are the losses measured for the window \(S_{t}\). They are given by  
\[A_{t}=\sum_{j=1}^{K+1}A_{t,j},\ B_{t}=\sum_{j=1}^{K+1}B_{t,j},\ C_{t}=\sum_{j=1 }^{K+1}C_{t,j}, \tag{17}\]  
where \(A_{t,j}\), \(B_{t,j}\), and \(C_{t,j}\) are the losses due to the PKI score \(X_{t,j}\), SKI score \(Y_{t,j}\), and classification score \(Z_{t,j}\), respectively. They are evaluated by  
\[A_{t,j}=\left\{ \begin{array}{ll}-(1-X_{t,j})^{\alpha}\log(X_{t,j})&,\text{ if }t\in\mathcal{I}_{\text{rx}},\\ -(1-F_{t,j})^{\beta}(X_{t,j})^{\alpha}\log(1-X_{t,j})&,\text{otherwise}.\end{array} \right. \tag{18}\]\[B_{t,j} =\left\{