# A Trajectory Optimisation-Based Incremental Learning Strategy for Learning from Demonstration
## 3 Research Methodology
### Extended Demonstration via G-PRM
#### 3.2.2 Bias Optimisation  
G-PRM can generate an initial \(Tra_{gen}\) based on \(G\!SP\). To derive bias \(\mathbf{bv}\) for updating \(G\!SP\) and \(Tra_{gen}\), two key processes are required: 1 it is essential to design a Frechet distance-based [32] similarity criterion to measure the similarity between \(Tra_{gen}\) and \(Tra_{imi}\) (\(Fresim(Tra_{gen},Tra_{imi})\)). \(Fresim(Tra_{gen},Tra_{imi})\) is derived from Frechet distance. 2 Scaling \(Tra_{gen}\) and \(Tra_{imi}\) to the same scale facilitates the calculation of coordinate differences. 1 To calculate the Frechet distance between \(Tra_{imi}\) and \(Tra_{gen}\), three steps are involved:  
Step 1--Initialisation definitions: This paper defines \(F\!r\hat{e}(a,b)\) as the Frechet distance between the first \(a\) points of \(Tra_{imi}\) and the first \(b\) points of \(Tra_{gen}\). Both \(Tra_{imi}\) and \(Tra_{gen}\) contain an equal number of points, with \(a\) and \(b\in(1,\ k]\). \(k\) represents the number of points on the two trajectories, respectively. Since \(Tra_{imi}\) and \(Tra_{gen}\) are discrete, the computation of the Frechet distance of the two trajectories is based on \(Eudis\). Step 2--Boundary conditions for Frechet distance:  
\[ \begin{array}{l}F\!r\hat{e}(1,1)=Eudis(seg,seg)\\ F\!r\hat{e}(a,1)=max(F\!r\hat{e}(a-1,1),Eudis(Tra_{imi},seg)),a>1\\ F\!r\hat{e}(1,b)=max(F\!r\hat{e}(1,b-1),Eudis(seg,Tra_{gen})),b>1\end{array}  \tag{3}\]  
where \(F\!r\hat{e}(1,1)\) in Equation (3) represents the Frechet distance between the first points (\(seg\)) of \(Tra_{imi}\) and \(Tra_{gen}\), the \(Eudis(\cdot)\) represents the distance between two elements in the bracket. \(Tra_{imi\_a}\) and \(Tra_{gen\_b}\) represent the ath point and the bth point in \(Tra_{imi}\) and \(Tra_{gen}\), respectively. The \(max(\cdot)\) the largest element in the brackets. Step 3--Recursive calculation for Frechet distance: Based on Equation (3), the Frechet distance between \(Tra_{imi}\) and \(Tra_{gen}\) can be calculated as shown in Equation (4):  
\[F\!r\hat{e}(a,b)=max \begin{pmatrix}\min(F\!r\hat{e}(a-1,b),F\!r\hat{e}(a,b-1),F\!r\hat{e}(a-1,b-1))\\,Eudis\!\left(Tra_{imi\_a},Tra_{gen\_b}\right)\end{pmatrix} ,a>1\;and\;b>1 \tag{4}\]  
where \(\min(\cdot)\) opts for the smallest value in brackets. When \(a=k\) and \(b=k\), the Frechet distance \(F\!r\hat{e}(Tra_{imi},Tra_{gen})\) between \(Tra_{imi}\) and \(Tra_{gen}\) is obtained. Based on the calculation results from Equation (4), \(Fresim(Tra_{gen},Tra_{imi})\) is calculated as shown in Equation (5):  
\[Fresim(Tra_{gen},Tra_{imi})=max(1-\frac{F\!r\hat{e}(Tra_{gen},Tra_{imi})}{ \frac{\sqrt{len(Tra_{gen})\times len(Tra_{imi})}}{\sqrt{2}}},0) \tag{5}\]  
where \(\sqrt{len(Tra_{gen})\times len(Tra_{imi})}\) is the geometric mean of the lengths of the \(Tra_{imi}\) and \(Tra_{gen}\). \(len(\cdot)\) represents the length of the trajectory calculated via \(Eudis\). \(Fresim(\cdot)\in[0,1]\). A score of 0 indicates complete dissimilarity between the two trajectories, whereas 1 signifies that the trajectories are identical. 2 To facilitate bias optimisation, \(Tra_{gen}\) needs to be scaled to the same scale as \(Tra_{imi}\). The target point of \(Tra_{imi}\) is represented by \(tar=(x_{o},y_{o},z_{o})\) as shown by the red dot in Figure 4. The calculated scaling vector is denoted as \(\mathit{scalefactor}\), as shown in Equation (6):  
\[\overrightarrow{scale_{factor}}=\overrightarrow{(\frac{x_{e}-x_{s}}{x_{o}-x _{s}},\frac{y_{e}-y_{s}}{y_{o}-y_{s}},\frac{z_{e}-z_{s}}{z_{o}-z_{s}})} \tag{6}\]\(\overline{scale_{factor}}\) includes scaling factors for x, y, and z axes, denoted as \(scale_{factor\_x}\), \(scale_{factor\_y}\), and \(scale_{factor\_z}\), respectively. The scaled trajectory of \(Tra_{gen}\) is defined as \(Tra_{s}\). Each coordinate in \(Tra_{s}\) can be calculated by Equation (7):  
\[