# Robust Learning from Demonstration Based on GANs and Affine Transformation
## 3 Proposed Method
### Preprocess Method  
#### 3.2.1 Trajectory Mapping  
In this paper, we represent the trajectory using three-dimensional points in the Cartesian coordinate system. However, noise in the sensor's calculation of the end positions may result in outliers in the collected three-dimensional point sequences. To mitigate the  
Figure 1: Overview of GANs. GANs take a latent vector as input and generate desired data. These generated data are then compared with real data by the discriminator, guiding their subsequent updates.  
Figure 2: Overview of the proposed method. We outline a data acquisition approach for collecting data, setting the stage for training a GAN-based trajectory learning module. Subsequently, an affine transformation module is applied to ensure optimal generalization performance.  
impact of outliers, we employ the MAD (median absolute deviation) method. MAD utilizes two fundamental metrics to filter the data:  
\[\begin{split} P_{me}=median(P),\\ P_{mad}=median(|P-P_{me}|),\end{split} \tag{4}\]  
where function \(median(\ )\) means to find the median of the point set. Through (4) we can obtain \(P_{me}\) and \(P_{mad}\), which can help define the upper and lower bound of the algorithm:  
\[\begin{split} P_{up}=P_{me}+a\times b\times P_{mad},\\ P_{down}=P_{me}-a\times b\times P_{mad},\end{split} \tag{5}\]  
where \(a\) and \(b\) are two parameters that fit the outlier tolerance. We then apply the following filter to the collected data:  
\[P=\left\{\begin{aligned} P& P_{down}<P<P_{up}\\ P_{up}& P>P_{up}\\ P_{down}& P<P_{down}\end{aligned}\right., \tag{6}\]  
where \(P\) represents a set of 3D points \(P=\{p_{1},p_{2}\dots,p_{n}\}\), and each \(p_{i}=(x_{i},y_{i},z_{i})\) is a point in three-dimensional space. After processing, we obtain a set of 3D trajectory points.  
In order to decrease data dimensionality, we make the assumption that the three-dimensional trajectory points are situated within a common plane \(a^{T}p=b\), where \(a\) is the normal vector of the plane, and \(b\) is the distance of the plane from the origin. We can employ singular value decomposition (SVD) to model this plane and project all points onto it. Initially, we construct the data matrix \(A\), where each row represents a data point:  
\[A=\begin{bmatrix}x_{1}&y_{1}&z_{1}\\ x_{2}&y_{2}&z_{2}\\ \dots&\dots&\dots\\ x_{n}&y_{n}&z_{n}\end{bmatrix}. \tag{7}\]  
To simplify computations, the dataset is centered by subtracting the mean from each column:  
\[\begin{split}\mu=\begin{bmatrix}\overline{x}&\overline{y}& \overline{z}\end{bmatrix},\\ \overline{A}=A-\mu.\end{split} \tag{8}\]  
SVD is then performed on the centered data matrix \(\overline{A}\):  
\[\overline{A}=U\Sigma V^{T}, \tag{9}\]  
where \(U\) is an \(n\times n\) orthogonal matrix, \(\Sigma\) is an \(n\times 3\) diagonal matrix with singular values sorted in descending order, \(V\) is a \(3\times 3\) orthogonal matrix. The normal vector \(a\) of the plane is extracted from the right singular vector corresponding to the least singular value:  
\[\text{a}=V[:,-1]. \tag{10}\]  
Consequently, we can map the trajectory into 2D points, significantly improving the convergence of the model, as we will discuss later.  
To project a point \(p_{i}\) onto the fitted plane, the formula for vector projection is utilized:  
\[p_{i}=p_{i}-(\text{a}\cdot p_{i})a. \tag{11}\]  
This projection process is repeated for all data points, resulting in their projections onto the fitted plane.