## 5 Development of Machine-Learning-Based Personal Training System
### Dynamic Time Warping Algorithm for Similarity Evaluations  
In particular, extracting some features in continuously measured signals seems to include many essential aspects of pattern detection in time series. Feature extraction is usually based on matching templates against a waveform of the continuous signal, converted into a discrete-time series. Thus, successful recognition strategies are based on matching signals, despite wide variation in timing and amplitude, approximately. Because the speed of exercise activity for experts is different from that for the user, it is necessary to evaluate the similarity between two different time-span data. Any two-time series can be compared using Euclidean distance or similar distances on a one-to-one basis on the time axis. The amplitude of first time-series data at time \(T\) is compared with the amplitude of second time-series data at time \(T\). The comparison at the same time axis leads to an inferior comparison and similarity score even if the shape of the two-time series are very similar but out of phase in time. Dynamic time warping (DTW) compares amplitude of first signal at time \(T\) with amplitude of second signal at time \(T+1\) and \(T-1\) or \(T+2\) and \(T-2\). This makes sure it does not give low similarity score for signals with similar shape and different phase [36; 37]. The DTW technique is based on an approach of dynamic programming, while aligning the time series to find minimized distance measurement. Because some regulations of the time axis can fit the horizontal axis, the proper template looks useful. Investigating a time series, \(S\), is related to finding the pattern in a template, \(T\),  
\[S =s_{1},s_{2},\cdots,s_{i},\cdots,s_{n} \tag{3}\] \[T =t_{1},t_{2},\cdots,t_{j},\cdots,t_{m}. \tag{4}\]  
The sequences \(S\) and \(T\) have a \(n-by-m\) matrix. Each element of \((i,j)\) at the matrix represents the similarity between the two elements of \(s_{i}\) and \(t_{j}\). \(W\) aligns the elements of \(S\) and \(T\), and the warping path has the minimum value,  
\[W=w_{1},w_{2},\cdots,w_{k}, \tag{5}\]  
where \(W\) represents a sequential point, and \(w_{k}\) represents \((i,j)_{k}\). Solving a dynamic programming problem is to have a measured distance between two elements. Although we have many candidates, it looks proper for the absolute value or square of the similarity as the distance function of \(\delta\). \[\delta(i,j) =\big{|}s_{i}-t_{j}\big{|} \tag{6}\] \[\delta(i,j) =(s_{i}-t_{j})^{2}. \tag{7}\]  
The function of \(\delta\) means a measured distance between two-time series data. Since the cumulative measurement for each path indicates the potential warping paths, the DTW problem can define as minimization of warping paths. \[DTW(S,T)=\min_{W}\Big{[}\Sigma_{k=1}^{p}\delta(w_{k})\Big{]}. \tag{8}\]  
Dynamic programming explains legal state transitions with stage, state, and decision. Although the decision is difficult to recognize, these variables show possible paths between the two elements in the matrix. Some limitations are as follows. However, these are good for deciding permissible paths for efficiency. 1. Monotonicity: The points must be monotonically ordered with respect to time, \(i_{k-1}\leq i_{k}\) and \(j_{k-1}\leq j_{k}\). 2. Continuity: The steps in the grid are confined to neighboring points, \(i_{k}-i_{k-1}\leq 1\) and \(j_{k}-j_{k-1}\leq 1\)Warping window:  
Allowable points can be constrained to fall within a given warping window, \(|i_{k}-j_{k}|\leq w\), where \(w\) is a positive integer window width. Allowable warping paths can be constrained by restricting the slope, avoiding extensive movements in a single direction. Boundary conditions:  
The starting point selects one of the subsequent paths, and the endpoint adds some offset to constrained points, such as \(i_{1}=1\), \(j_{1}=1\) and \(i_{k}=n\), \(j_{k}=m\).