# Developing Machine Learning-Based Models for Railway Inspection
## 4 Deep Learning-Based Methods
### Representation Method of Raw Data
#### 4.3.2 Data Interpolation  
The acceleration data was collected with a sampling time interval of 2.15 ms. The data was converted into the distance domain by integrating the speed signal collected simultaneously with the two acceleration channels. Thus, the data points are indexed by distance from the starting point. The running speed of the inspection vehicle is changing and the data was collected with a fixed frequency, so the distance interval is not unique. To train a model for time series classification, input samples require fixed-length signals. If the raw data is directly divided with the same number of data points in each sample, the sequence features of samples are not aligned.  
If the distance interval between two adjacent data points is large, some data points may be missed between them. Data interpolation is a method of constructing new data points within the range of a discrete set of known data points. The method creates a function by curve-fitting the data points; then the function is used to generate points anywhere along the curve. In this work, the system was implemented in Python. Therefore the \"interp1d\" class in the Python package \"SciPy-interpolate\" is a convenient method for this task. Suppose there is a sample \(x_{i}\) by sliding window, which is expressed in Equation (5).  
\[x_{i}=\left[\begin{array}{c}x_{i}^{l}\\ x_{i}^{r}\end{array}\right]=\left[\begin{array}{cc}x_{i}^{l1}&x_{i}^{l2}& \ldots&x_{i}^{lm}\\ x_{i}^{r1}&x_{i}^{r2}&\ldots&x_{i}^{rm}\\ \end{array}\right], \tag{5}\]  
where, \(x_{i}\) is a bivariate time series of acceleration data of left and right track respectively. There are \(m\) data points in this sample, which is different from sample to sample. There is another index vector \(d_{i}=\left\{d_{i}^{1},\ d_{i}^{2},\ \ldots\ d_{i}^{m}\right\}\) with each \(d_{i}^{j}\) indicating the location of the data point \(\left(\begin{array}{c}x_{i}^{lj}\\ x_{i}^{lj}\end{array}\right)\). The distance between two adjacent data points might be different but the distance interval of the sample \(d=d_{i}^{m}-d_{i}^{1}\), fixed by the sliding window size, is the same for every sample. The first step is to create the curve-fitting functions by the \"interp1d\" class from Python package \"SciPy-interpolate\" [32] for left and right separately as expressed in Equation (6) and Equation (7).  
\[f_{l} =interp1d(d_{i},\ x_{i}^{l},\ kind=cubic), \tag{6}\] \[f_{r} =interp1d(d_{i},\ x_{i}^{r},\ kind=cubic), \tag{7}\]  
The second step is to generate a fixed number of data points evenly distributed in this distance interval. Suppose \(M\) is the fixed number, Equation (8) expresses new data vector.  
\[d_{i}^{new}=\left\{d_{i}^{1,new},d_{i}^{2,new},\ \ldots\ d_{i}^{M,new}\right\}, \tag{8}\]  
where, \(d_{i}^{new}\) is a new distance vector contains M points equally spaced between the start point of \(d_{i}^{1}\) and the end point \(d_{i}^{m}\). The new data points can be generated as \(x_{i}^{l,\ new}=f_{l}\left(d_{i}^{new}\right)\) and \(x_{i}^{r,\ new}=f_{r}(d_{i}^{new})\). Through data interpolation, each sample can be expressed as Equation (9).  
\[x_{i}^{new}=\left[\begin{array}{c}x_{i}^{l,new}\\ x_{i}^{r,new}\end{array}\right]=\left[\begin{array}{c}x_{i}^{l1,new}\ x_{i}^{l2,new}\ldots&x_{i}^{ lM,new}\\ x_{i}^{r1,new}\ x_{i}^{r2,new}\ldots&x_{i}^{rM,new}\end{array}\right], \tag{9}\]  
An example to show the data representation method described above is given in Figure 6. Figure 6 shows a data sample that contains 19 data readings (points) given the window size is 4 cm from our application. Figure 5(a) is the original data points for two sides of rail; and Figure 5(b) is the curve after fitting with the \"SciPy-interpolate\" algorithm. With the fitted spline, we resample the curve with 100 data points, which are equally spaced (0.4 mm).  
Figure 6: An example of data sample given a fixed window size (4 cm). (**a**) Original data; (**b**) cubic interpolations.