# Adaptive Refinement in Advection-Diffusion Problems by Anomaly Detection: A Numerical Study
## 2 Problem Formulation
### Anomaly Detection  
The term anomaly detection is used in the context of time-series or Big Data whenever there are outliers or anomalous points to be identified. In particular, points that follow a standard trend or can be observed to have expected behavior are labeled as normal; otherwise, they become anomalous. In the present work, we use the Isolation Forest (IF) algorithm [23; 24], which refers to an unsupervised technique developed to detect anomalies in the considered dataset. In order to isolate the points that deviate from the expected trend, the IF constructs a forest of binary trees by randomly selecting a feature and then randomly selecting a split value. The resulting number of required splittings is equivalent to the path length from the root node to the terminating node. Anomalies usually produce rather shorter paths compared to normal points. IF has a linear time complexity and it does not need any labeled data; hence, it works in a completely unsupervised fashion. In the present work, we use the implementation provided by the Python library scikit-learn[25]. In order to control the randomness, and hence to make the experiments reproducible, we set the parameter random_state = 0. All the other parameters are used with the default settings. The algorithm that we propose employs any error estimator described in the previous subsection in order to acquire an estimate of the error function, localized at every triangle. Then, the IF takes as input an array of values containing the error estimator for each triangle. The anomalies are those values where the estimated error is rather large. Therefore, the anomalous values correspond to those triangles that should be refined. In order to improve the performance of the adopted error estimator, we also ran some benchmarks by setting the contamination parameter \(c=0.3\). The contamination acts as a cutoff on the returned values. In particular, \(c=0.3\) means that only the top 30% negative scores are labeled as anomalies. The set-up for \(c\) was experimentally derived and was in line with the fact that the boundary layers are usually confined to specific regions; hence, usually, there is no need to refine large areas of the computational domain. In certain cases, the use of \(c=0.3\) helped to achieve a final refinement even more localized to the problematic areas and, thus, the performance of the three error estimators became equivalent in terms of the reached accuracy per number of refinements. An outline of the proposed algorithm is presented in Algorithm 1.  
```
Data: Given \(\varepsilon,\mathbf{b},\alpha,f,\Omega\) Result: Adapted Triangulation begin  Create a triangulation \(\mathcal{T}\) of \(\Omega\);  Solve with Galerkin SUPG; for\(T\in\mathcal{T}\)do  Compute \(\eta_{T}\);  Store \(\eta_{T}\) into \(\eta\);  end while  begin  Isolation-Forest \(\longleftarrow\)\(\eta\); \(A\longleftarrow\) Isolation-Forest; \(A\): vector containing \(1\) for normal \(\eta_{T}\) and \(-1\) for anomalous \(\eta_{T}\);  end for  end for  begin Construction of anisotropic mesh adaptation function \(h\); for\(T\in\mathcal{T}\)do  Compute the diameter \(h_{T}\); if\((A(\eta_{T})==-1)\)then \(h_{T}\longleftarrow h_{T}/4\); else continue;  end if  end for  end for
```  
**Algorithm 1**Pseudo-code for the proposed algorithm.