# Prognostics of Electromechanical Actuator with Partial Time Scaling Invariant Temporal Alignment
## 5 Alignment by Successive Displacements
At each iteration, \(k\), a distance \(d_{k}\) can be associated with a point. The sequence of distances \((d_{k})0\leq k\leq K\) is then created. As a result, it is a geometric sequence with a ratio \(\frac{1}{\alpha}\). Its partial sum thus has a simple expression,  
\[\sum_{k=0}^{K}\frac{d_{0}}{\alpha_{k}} \tag{3}\]  
which converges, for an infinite number of iterations, \(K\rightarrow\infty\), to the magnitude \(\frac{\alpha d_{0}}{\alpha-1}\). The advection model, therefore, reaches a stability point. By extension, the alignment algorithm necessarily converges towards the target, but, as it stands, it is not yet possible to evaluate the quality of such convergence. A cost function \(\mathcal{L}\) will be developed in Section 6. In more detail, the Advection function of Algorithm A3 produces a source cloud \(\bar{X}\mathcal{T}\) from the two clouds to align \(\bar{X}_{j}^{l}\) and \(\bar{Y}_{j}^{h}\). The assignment table nnAssignmentArray represents the function \(\mathcal{T}_{k}\) and sigmoid, an array containing the previous variable \(\alpha\) for each direction. Lines 2 to 4 initialize the structures to calculate the total distance traveled by the source cloud. Lines 6 to 9 define target and target, which represent the coordinates of the points to be reached in the target \(\bar{Y}_{j}^{h}\), while ssrc and ysrc represent the coordinates of the starting points in the source. The distance between these two points is then calculated on line 12. The displacement amounts \(\kappa_{\text{displacement}}\) and \(\gamma_{\text{displacement}}\) are calculated on lines 15  
Figure 9: Displacement example of the \(n\)th source point towards its affected neighbor (the third point) located in the target point cloud for 4 iterations. and 16 as a proportion of the distance between the source and the target. The coordinates of the source point cloud \(\bar{X}_{j}^{l}\) are then updated on lines 18 and 19. Finally, an advection cost is calculated as being the normalized sum of the distances traveled by each source point and the moved source cloud \(\bar{X}_{\mathcal{T}}\). Note here that the advection cost differs from the cost function \(\mathcal{L}\) developed in the following Section 6. Now that all the steps of Figure 7 have been detailed, the global Algorithm A4 is developed to bring together all these functions and obtain the final alignment of a time series \(X\) with a series \(Y\). The Time Series Alignment function produces the shifted source point cloud \(\bar{X}_{\mathcal{T}}\) using two point clouds \(\bar{X}_{j}^{l}\) and \(\bar{Y}_{j}^{h}\), the set of optimal directions found in Equation (1) \(\phi_{j}^{h,*}\), and an array of hyperparameters weightArray. The Time Series Alignment function then performs \(K\) iterations of steps 1, 2, and 3 in Figure 7 as long as the cumulative displacement of points from the source to the target is not zero. The variable cost is declared in line 7 with a non-zero value and updated in line 56 with the absolute value of a cost calculated by the \(\mathfrak{L}\) function. The cost will be zero below a \(10^{-16}\) limit. This avoids the algorithm continuing to iterate when the displacement cost is of the order of machine precision and potentially a numerical error. Now that the automatic stopping criterion has been presented, let us discuss the operation of Algorithm A4. The first lines of Algorithm A4 initialize the variables, and line 6 preserves the initial values of the source point cloud \(\bar{X}_{j}^{l}\). For reference, the latter is defined as \(\bar{X}_{j}^{l}=\left(t_{i},x_{i}\right)_{1\leq i\leq n,j}^{l}\), where the notation \(\bar{X}_{j}^{l}[\cdot,\cdot]\) keeps only the \(\left(x_{i}\right)_{1\leq i\leq n}\), i.e., the initial time series \(X_{j}^{l}\), which is \(\bar{X}_{j}^{l}[\cdot,\cdot]=\left(x_{i}\right)_{1\leq i\leq n}\). The iterative loop then begins by testing, at line 8, if the calculated cost, which is different from the displacement cost of the cloud, is not negative. This is when the source cloud points converge very slowly to the target.