# Functional Outlier Detection by Means of h-Mode Depth and Dynamic Time Warping
### Ordering Score in the Feature Space  
Once all the parameters are fixed at their estimated values, it is possible to quantify the extremal behavior of any point in the considered multivariate space through the notion of _Level Set_[29]. Formally, given an absolutely continuous probability measure \(v\) with density \(p\), the Minimum Level Set \(D^{\theta}\) is the set of minimal volume (according to the Lebesgue measure) whose measure is \(\theta\):  
\[D^{\theta}=\underset{D\subset\mathbb{R}^{R},v(D)\geq\theta}{\text{argmin}} \lambda(D) \tag{5}\]  
where \(\lambda\) is the Lebesgue measure in \(\mathbb{R}^{R}\). Due to the concave downward nature of the GMM [30], the set \(D\) is unique and \(v(D^{\theta})=\theta\). This way, a probabilistic score of outlyingness for functional data can be obtained via the probability mass retained in the associated Level Set of each functional datum \(z_{i}\):  
\[\hat{\theta}_{i}=\int_{\mathbb{R}^{R}}\hat{p}(\mathbf{u})\mathbb{1}_{\{\hat{p}(\bm {u})\geq\hat{p}(\mathbf{u}_{i})\}}d^{R}\mathbf{u} \tag{6}\]  
where \(\mathbb{1}\) is an indicator function, and \(\hat{p}\) is the adjusted probability density function of the GMM with the estimated parameters:  
\[\hat{p}(\mathbf{u};\mathbf{\omega},\hat{\mathbf{\mu}}_{k},\hat{\mathbf{\Sigma}}_{k})=\sum_{k=1 }^{K}\hat{\omega}_{k}\frac{1}{2\pi\sqrt{|\hat{\mathbf{\Sigma}}_{k}|}}\exp\Big{(}- \frac{1}{2}(\mathbf{u}-\hat{\mathbf{\mu}}_{k})^{T}\hat{\mathbf{\Sigma}}_{k}^{-1}(\mathbf{u}- \hat{\mathbf{\mu}}_{k})\Big{)}. \tag{7}\]  
This integral must be solved by numerical methods. For \(R=1,2\), there exists efficient software able to solve it, whereas several algorithms based on the Cholesky decomposition have been developed for the higher-dimensional cases [31]. In the applications presented here we will limit ourselves to two components, orienting each one of them to magnitude or shape outlier detection. The above presented level set notion gives an unambiguous way of defining to what extend an observation is unlikely to be observed when assuming it was generated in accordance with the same probability law as the rest of the dataset. The GMM provides in turn the required underlying probabilistic model allowing this definition. With the resulting outlyingness scores \(\theta_{i}\), we have now available a properly constructed quantification tool for the degree of outlyingness of an observation. We can thus use common statistical approaches to implement an outlier detection procedure, such as considering the occurrence probability of a data point is too small when \(\theta_{i}<\alpha\), where \(\alpha\) is a significance level. Finally, let us consider the more realistic case where the availability of data is actually limited, and the sample of functional data is too small to generate the GMM with an acceptable level of reliability (the global convergence of the EM algorithm is not necessarily reached).This is for instance the case for expensive industrial simulation codes, such as mechanical or thermal-hydraulic simulators. In this case, a natural extension of this idea for outlier detection can be implemented via bootstrap resampling, [32]. \(B\) groups are formed by successively drawn with replacement in the original sample. This way, the absence of data can be mitigated through the re-estimation of the GMM for each bootstrap group. If for \(B\) bootstrap groups \(p_{b}(\mathbf{u})\) represents the GMM of the \(b\)th group, the form of the (bootstrap) estimator of outlyingness would then be:  
\[\hat{\theta}_{i}=\int_{\mathbb{R}^{R}}\frac{1}{B}\sum_{b=1}^{B}\hat{p}_{b}(\bm {u})\mathbb{1}_{\{p_{b}(\mathbf{u})\geq p_{b}(\mathbf{u}_{i})\}}.d^{R}\mathbf{u} \tag{8}\]Throughout this reasoning, the hyperparameter \(K\) (the number of components of the mixture model) has been supposed to be fixed, but in practice, this is yet another input parameter of the GMM that must be provided _a priori_ to the EM algorithm. Indeed, the actual form of the model is significantly different depending on the number of components that are considered.