# Robust Learning from Demonstration Based on GANs and Affine Transformation
## 3 Proposed Method
### Generalization Based on Affine Transformation  
The generalization performance of demonstration learning primarily pertains to the learning system's ability to adapt to diverse scenario demands, even when encountering new environments characterized by novel starting points, endpoints, intermediate points, and other factors. This adaptability is crucial for effective demonstration learning. Figure 3: The framework of proposed GANs with novel loss function. However, traditional trajectory demonstration learning algorithms often struggle with poor generalization performance: ProMP [25] lacks extrapolation ability, and promoted DMP [9] cannot specify intermediate points. To overcome these limitations, this paper introduces a trajectory generalization method based on affine transformation. This method automatically selects trajectory points using perpendicular bisectors, constructing affine transformation solving equations tailored to the generalization requirements of starting and target points, thereby directly obtaining the target trajectory. An affine transformation involves translation and linear mapping and serves as a deterministic approach that avoids convergence issues. Unlike DMP, in which learns trajectories based on external force terms, the proposed affine transformation method preserves the original attributes of the trajectory. While DMP algorithms struggle to control the trajectory's shape when modifying the endpoint, our method achieves the desired target trajectory by adjusting the scale factor. Additionally, our affine transformation-based approach allows for specifying intermediate point poses without encountering convergence issues. The subsequent section delineates the algorithm for two-dimensional trajectory imitation learning. We denote the trajectory generated by the generator as \(T_{origin}=\{p_{1},p_{2},\ldots,p_{N}\}\). For clarity, we denote original starting position of \(T_{origin}\) as \(a\) and the original ending position as \(b\). In a generalization task, the new starting position and ending position can be denoted as \(a^{\prime}\) and \(b^{\prime}\) (new starting position and ending position can be assigned by user directly), and the generalized trajectory can be denoted as \(T_{new}\). Our proposed method aims to find an affine transformation matrix \(M\) to satisfy the equation:  
\[T_{new}=M\times T_{origin}, \tag{18}\]  
where \(M\) is a \(3\times 3\) homogeneous matrix which has 6 degrees of freedom. To determine \(M\), 6 constraints are required, corresponding to 3 pairs of trajectory points. In order to find the third corresponding pair, we utilize the following method. The equation of the line passing through points \(a\) and \(b\), as well as the equation of the perpendicular bisector of the line segment joining \(a\) and \(b\), denoted as \(L_{origin}\) and \(PB_{origin}\), respectively, can be obtained from the following expressions:  
\[ \begin{array}{c}L_{origin}\triangleq y=kx+\tau,\\ PB_{origin}\triangleq y=-\frac{1}{k}\times\left(x-\frac{a_{x}+b_{x}}{2} \right)+\frac{a_{y}+b_{y}}{2}.\end{array}  \tag{19}\]  
where \(\triangleq\) represents 'is defined as'; \(k\) is the slope of \(L_{origin}\), given by \(k=\frac{a_{y}-b_{y}}{a_{x}-b_{x}}\); \(\tau\) is the \(y\)-intercept, which can be determined by substituting the coordinates of either point \(a\) or \(b\) into the equation; and \((\ )_{x}\) and \((\ )_{y}\) represent the \(x\)-coordinate and \(y\)-coordinate of the point, respectively. For discrete trajectory points, the approximate intersection point \(p_{mid}\) of the trajectory point \(p_{i}\) and the line is obtained by minimizing the distance between the trajectory point \(p_{i}\) and the line:  
\[\mathrm{c}=\underset{p_{i},p_{i}\in T_{origin}}{\mathrm{argmin}}dist\big{(}p_ {i},PB_{origin}\big{)}, \tag{20}\]  
where \(dist(\ )\) is used to calculate the distance between a point and a line. After changing the starting position and ending position of the trajectory, the two new lines \(L_{new}\) and \(PB_{new}\) can be obtained using Formula (19).