## 5 Anomaly Classification  
### Problem Formulation  
The anomaly classification is triggered once an anomaly is detected. A system can possibly address a wide variety of types of anomalies including low-level hardware anomalies--sensor and actuator noise or breakage--mid-level software contingencies--logic errors or run-time exceptions--or high-level misrepresentations--poor modeling of the robot, the world, their interactions, or external disturbances in the environment [44]). In [43], [PERSON] et al. identified both the anomaly class and the cause. In this work, we deal with anomalies caused by external disturbances generated either by intrusive human behavior or resulting from poor modeling or anticipatory ability on the robot side.  
We consider the problem of multiclass classification based on multivariate time series, that is, to find a function \(f(y^{n})=c^{n}\) given the \(i.i.d\) training data \(Y=\{y^{n}\}_{n=1}^{N}\), \(C=\{c^{n}\}_{n=1}^{N}\), where \(y^{n}=[y_{0}^{n},y_{1}^{n},\ldots,y_{1n}^{n}]\) is an observation sequence and \(c^{n}\in\{1,..,c\}\) its corresponding anomaly class. An observation \(y_{t}^{n}\in\mathbb{R}^{d}\) consists of the same multimodal features as described in Section 3.2 at time step \(t\). Our objective is classification, where given a new test observation sequence \(\hat{y}\), we must predict its corresponding anomaly class \(\hat{c}\). Here, the \(\hat{y}\) is recorded by considering a \(window\_size\) around the anomaly moment, and the \(\hat{c}\) is labeled manually during training procedure. We represent each anomaly class by a separate sHDP-VAR-HMM as outlined in Section 3.2; the \(\Theta_{c}\) are the parameters for class \(c\). It would be straightforward to estimate the posterior density of parameters \(p(\Theta_{c})|Y,C)\) by  
\[p(\Theta_{c}|Y,C)=p(\Theta_{c})\prod_{c^{n}=c}p(y^{n}|\Theta_{c})p(c). \tag{31}\]  
That is, each sHDP-VAR-HMM is trained separately and a conditional density \(p(y|c)\) for each class is trained throughout the procedure as defined in Algorithm 1.  
```
Input: \(N_{c}\): Number of sequences for class \(c\in\mathcal{C}\); \(\{y_{n}\}_{n}^{N_{c}}\): Dataset with \(N_{c}\) sequences, each of length \(T_{n}\); \(N_{i}\): Number of the maximum iterations for learning; \(N_{r}\): Number of runs for the whole learning; \(random\_state\): The random-number generator; \(k\_splits\): Number of folds; \(a,b,d,e\): Hyper-prior for concentration parameters; \(\
u,\Delta,V,M,s_{F}\): Hyper-prior for the MNIW distribution; \(\kappa\): The self-transition bias; \(K\): The truncation active states. Result: sHDP-VAR-HMM models for each class \(\{y_{n}\}_{train}\), \(\{y_{n}\}_{test}\) = Kfold_split(\(\{y_{n}\}_{n}^{N_{c}}\),\(k\_splits,random\_state\)) for\(k\) in \(k\_splits\)do for\(i\) in \(N_{r}\)do for\(n\) in \(N_{i}\)do ifnot convergedthen \(\Theta_{c}\), loss = HDP-HMM(\(\{y_{n}\}_{train},a,b,d,e,\
u,\Delta,V,M,s_{F},\kappa,K\)) else  sHDP-VAR-HMM with \(\Theta_{c}\) and loss  end if  end for \(\{loss\}_{i}^{N_{r}}\leftarrow loss\) if\(i==N_{r}\)then \(\Theta_{c}\leftarrow\) with the minimum loss value  end if \(\mathcal{L}_{test\_mean}=\frac{\sum_{i=1}^{N_{test}}p(\{y_{n}\}_{i}|\Theta_{c})} {N_{test}},i\in N_{test}\) \(\{\mathcal{L}_{test\_mean}\}_{k}^{k\_splits}\leftarrow\mathcal{L}_{test\_mean}\) if\(k==k\_splits\)then return\(\Theta_{c}\) with the maximum \(\mathcal{L}_{test\_mean}\)  end if
```  
**Algorithm 1**Training model for anomaly classification.