# Unsupervised Anomaly Detection for Time Series Data of Spacecraft Using Multi-Task Learning
## 3 Materials and Method
### iForest-Based Error Evaluation and Anomaly Detection  
Based on the multi-task model, i.e., \(\text{MTAD}_{\text{mt}}\), the features of \(X\) are extracted as \(Err(X)=[Err_{1}(X),Err_{2}(X),Err_{3}(X),Err_{4}(X)]\), where \(Err_{i}(X)\) is the loss of Proxy Task \(i\) for input \(X\).  
Next, the iForest-based [41] error evaluation and anomaly detection model, i.e., \(MTAD_{\text{ad}}\), is trained to perform anomaly detection from \(Err(X)\). In the iForest approach, a random hyperplane cuts the data space into two subspecies repeatedly, until no further subdivisions are possible. Hence, an isolated tree with only one data sample per leaf node is formed. In the present case, there is a low density of abnormal data samples and, thus, fewer splits are required to separate them individually for detection as anomalies. The MTAD method can be summarized as follows.  
Training Process: The training dataset is input to \(\text{MTAD}_{\text{mt}}\), the error is calculated and \(Err(X)\) is obtained. Then, the vector is input to \(\text{MTAD}_{\text{ad}}\) for training.  
Inference Process: The test data \(S\) are input to \(\text{MTAD}_{\text{mt}}\) to obtain \(Err(S)\). Then, \(Err(S)\) is input to \(\text{MTAD}_{\text{ad}}\) and the anomalies are detected.  
The MTAD Training Procedure is shown in Algorithm 1 as follows:  
```
Input: Dataset \(X\_train\)= \(\left\{X^{(1)},X^{(2)},\dots,X^{(N)}\right\}\) Output: Trained Multi-task model, \(\text{MTAD}_{\text{mt}}\); trained error evaluation and anomaly detection model, \(\text{MTAD}_{\text{ad}}\) \(\text{MTAD}_{\text{mt}}\) Training
1: Standardize \(X\_train\) and get parameters \(u_{train}\) and \(\delta_{train}\)// Equation (8), use a sliding window to transform each sample into \(X\in\Re^{M\times K}\).
2: Randomly initialize parameters
3:while epoch \(<\text{Total}_{\text{Epoch}}\)-\(\text{Num}\)do
4:for each \(X\)in \(X\_train\)
5: Get outputs \(\sigma_{\text{Task1}}\), \(\sigma_{\text{Task2}}\), \(\sigma_{\text{Task3}}\) from Tasks 1, 2, and 3//Equations (10), (13) and (16)
6: Get latent representations \(z_{ae}\) and \(z_{gae}\) from Tasks 2 and 3//Equations (14) and (17)
7: Combine \(z_{ae}\) and \(z_{gae}\) to obtain \(z_{input}\)= \([z_{ae},z_{gae}]\)
8: Get output \(\sigma_{\text{Task4}}\), from Task 4//Equation (19)
9: Compute\(Loss1\), \(Loss2\), \(Loss3\), \(Loss4\)// Equations (12), (15), (18) and (20)
10: Get final \(Loss_{total}=Loss1+Loss2+Loss3+Loss4\)//Equation (21)
11: Update parameters using gradient descent endfor
12:endwhile
13: Joint training to obtain \(\text{MTAD}_{\text{mt}}\)= \([\text{Task1}_{\theta_{1}},\text{Task2}_{\theta_{2},\theta_{2}},\text{Task3}_{ \theta_{3},\theta_{3}},\text{Task4}_{\theta_{2},\theta_{3},\theta_{4}}]\)\(MTAD_{\text{mt}}\) Training
14: Get the feature vector based on \(\text{MTAD}_{\text{mt}}\) on the training dataset \(Err(X\_train)\)= \([Err_{1},Err_{2},Err_{3},Err_{4}]//\)Equations (12), (15), (18) and (20)
15: Train \(\text{MTAD}_{\text{ad}}\) based on \(Err(X\_train)\)
```  
**Algorithm 1**MTAD Training Procedure.  
The MTAD Inference Procedure is shown in Algorithm 2 as follows: