# 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  
The optimal coordinates of each missing marker at a given frame will be estimated by translating a set of empirical principles into a nonlinear problem that is solved through least squares minimization. All empirical principles rely on the assumption that markers considered for the reconstruction of the other markers present a semi-rigid behaviour, i.e., their inter-markers' distance and relative motion will remain (roughly) constant over the course of the trajectory. In this problem, the independent variables consist of the the Cartesian coordinates of one or more missing markers, depending on whether the set of reconstruction markers of each of them may include (or not) other missing markers, i.e., whether they fulfilled condition two or one of Section 3.2.1. A marker that has fulfilled condition one is always considered alone: it will be reconstructed using a dedicated system of equations where the independent variable will solely consist of its coordinates. Taking marker one of Table 1 as an example, the independent variable (\(\mathbf{x}\)) consists of an array that can be expressed as \(\mathbf{x}=[x_{1},y_{1},z_{1}]\), where \(x_{1},y_{1}\) and \(z_{1}\) represent the Cartesian coordinates of marker one. Markers that fulfill condition two are considered simultaneously if they can contribute towards each other's reconstruction. Using the example of Table 1, this means that markers four and five will be considered in the same nonlinear problem, since they are included in each other's set of reconstruction markers. Thus, in this case, the independent variable can be expressed as \(\mathbf{x}=[x_{4},y_{4},z_{4},x_{5},y_{5},z_{5}]\). Each nonlinear problem will aim to minimize a \(m\)-dimensional real function of the \(n\)-dimensional \(\mathbf{x}\) with reference to the \(n\) variables. Let us consider, for each frame \(f\in\{1,2,\ldots,F\}\) (where \(F\) corresponds to the total number of frames in the trajectory), the following representations:  
* \(j\): A reconstruction marker of marker \(i\) in frame \(f\), where marker \(j\in R_{i}(f)\);
* \(d_{ij}(f)\): Euclidean distance between markers \(i\) and \(j\) in frame \(f\);
* \(\mu_{d_{ij}}(f)\): Average distance between markers \(i\) and \(j\) over the previous \(f\)-\(1\) frames;
* \(\sigma_{d_{ij}}(f)\): Standard deviation of the distance between markers \(i\) and \(j\) over the previous \(f\)-\(1\) frames. The first empirical principle assumes that the distance between markers \(i\) and \(j\) in \(f\) should follow a normal distribution with mean \(\mu_{d_{ij}}(f)\) and standard deviation \(\sigma_{d_{ij}}(f)\). This principle is inspired by the notion that there are markers that can maintain a (roughly) constant distance throughout the trajectory, as Figure 1 illustrates. Equation (5) translates this principle into a real function that shall be minimized, where \(d_{ij}(f)\) is a function of the independent variable \(\mathbf{x}\). The concept behind this equation is also illustrated by Figure 2. We aim to find an optimal \(X_{1}\) that minimizes the probability represented by the highlighted  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Missing Marker** & **Auxiliary Markers** & **Reconstruction Markers** \\ \hline
**1** & \(A_{1}=\{2,6,7,8,9,10\}\) & \(R_{1}(f)=\{6,7,8,9,10\}\) \\
**2** & \(A_{2}=\{1,6,7,8,9,10\}\) & \(R_{2}(f)=\{6,7,8,9,10\}\) \\
**3** & \(A_{3}=\{8,9,10,11,12,13\}\) & \(R_{3}(f)=\{8,9,10,11,12,13\}\) \\
**4**area, forcing a semi-rigid behaviour on the segment delimited by markers \(i\) and \(j\), which favors the case where \(d_{ij}(f)\) approximates \(\mu_{d_{ij}}(f)\). \[ \begin{array}{ll}\text{minimize}&P(-z_{1}\leq Z_{1}\leq z_{1}),\quad z_{1}= \frac{d_{ij}(f)-\mu_{d_{ij}}(f)}{\sigma_{d_{ij}}(f)}\\ &\\ &Z_{1}=\frac{x_{1}-\mu_{d_{ij}}(f)}{\sigma_{d_{ij}}(f)}\sim N(0,1)\end{array}