# A Fully-Automatic Gap Filling Approach for Motion Capture Trajectories
## 3 Proposed Method
### Gap Filling Algorithm
#### 3.2.2 Least Squares Minimization of Systems of Equations
 \tag{5}\]  
In order to explain the second empirical principle, let us also consider the following representations, where marker \(h\) is the marker in \(R_{i}(f)\) with the lowest \(\sigma_{v_{1}/v_{h}}(f)\):  
* \(m_{i}(f)\): coordinates of marker \(i\) in frame \(f\);
* \(v_{i}(f)\): instant velocity of marker \(i\) in \(f\);
* \(v_{h}(f)\): instant velocity of marker \(h\) in \(f\);
* \(\mu_{v_{1}/v_{h}}(f)\): average of the ratio between the instant velocity of markers \(i\) and \(h\) over the previous \(f\)-1 frames;
* \(\sigma_{v_{1}/v_{h}}(f)\): standard deviation of the ratio between the instant velocity of markers \(i\) and \(h\) over the previous \(f\)-1 frames. The second empirical principle assumes that there are pairs of markers for which their relative movement is mostly constant over the course of the trajectory (Figure 3). This concept is depicted with the definition of marker \(h\) and the nature of its relationship with marker \(i\). If the ratio between the velocity of markers \(i\) and \(h\) is mostly constant (i.e., \(\sigma_{v_{1}/v_{h}}(f)\) is low), then \(v_{i}(f)\) can be obtained from (6); consequently, the direct application of the movement Equation (7) results in a possible position for a marker \(i\) in \(f\), i.e., \(pp_{i}(f)\). \[v_{i}(f)=v_{h}(f)\cdot\mu_{v_{1}/v_{h}}(f) \tag{6}\]  
Figure 1: Example of markers which maintain a (roughly) constant distance throughout a trajectory. Figure 2: Normal distribution curve. The probability to minimize using (5) is highlighted. Then, we try to minimize the distance between \(pp_{i}(f)\) and the coordinates of our missing marker \(i\). Let us represent this distance by \(d_{ipp}(f)\), which is a function of the independent variable \(\mathbf{x}\). We aim to find an optimal \(X_{2}\) that minimizes the probability function represented by (8). \[ \begin{array}{ll}\text{minimize}&P(-z_{2}\leq Z_{2}\leq z_{2}),\quad z_{2}= \frac{d_{ipp}(f)}{v_{h}(f)\cdot v_{i_{1}/v_{h}}(f)\cdot dt}\\ &Z_{2}=\frac{X_{2}}{v_{h}(f)\cdot v_{i_{1}/v_{h}}(f)\cdot dt}\sim N(0,1)\end{array}  \tag{8}\]  
The last empirical principle consists of minimizing a new distance, \(d_{ips}\), that is the distance between our missing marker \(i\) and its projection on the sphere centered in marker \(j\in R_{i}(f)\) and with radius \(d_{ij}(f)\). This principle is illustrated by Figure 4, which shows how the optimal point should lay somewhere around these projections. We will represent the coordinates of each projection point as \(ps_{ij}(f)\). This principle was implemented as described by (9) where both distances \(d_{ips}(f)\) and \(d_{ij}(f)\) are a function of the independent variable \(\mathbf{x}\). The normalization by the sphere's radius confers less penalization of greater distances between \(ps_{ij}(f)\) and the missing marker \(i\) for larger spheres, since greater distances are likely associated with greater estimation errors. \[ \begin{array}{ll}\text{minimize}&\frac{d_{ips}(f)}{d_{ij}(f)}\end{array}  \tag{9}\]  
These principles determine the number of functions to be simultaneously minimized by the least squares algorithm. As such, for each missing marker \(i\) from the first and third principles, (5) and (9), we will obtain one function per each marker \(j\) in \(R_{i}(f)\); from the second principle, in (8), only one function will be considered. The initial guess of the independent variable \(\mathbf{x}\) will be provided by the UKF prediction of position for the missing marker(s) under consideration. Our implementation considered a smooth approximation relative to an absolute value as a loss function of the least squares minimization algorithm. Figure 3: Example of a pair of markers for which their relative movement is mostly constant over the course of the trajectory.