# Abnormal Activity Detection Using Pyroelectric Infrared Sensors
## 5 Spectral Clustering
### Sequence Distance Measures  
After the likelihood matrix \(\mathbf{L}\) is constructed, the original variable-length sequence clustering problem is transformed to a typical similarity-based one. The \(j\)th column of \(\mathbf{L}\) represents the likelihood of sequence \(Y_{j}\) under each of the trained models. The next step is to define a meaningful distance measure for these sequences.  
A popular paradigm is to obtain likelihood-based distances between each pair of sequences [29]. Based on this work, several other distance measures have been proposed under a similar philosophy [27; 30; 31]. However, the main limitation of these methods is that they only consider the distance between two sequences each time, not including the global information of the whole set of data. Hence, we propose using the definition of distance measurement from a probabilistic perspective [32].  
We regard the likelihood of each of the sequences under the trained models as samples from the conditional likelihoods of the models given the data, which embeds information from the whole data set [32]. This gives rise to highly structured distance matrices to give a better performance in comparison with aforementioned distance-based methods [27; 29; 30; 31].  
According to the definition of likelihood matrix \(\mathbf{L}\), the \(j\)th column of \(\mathbf{L}\) can be regarded as the likelihood of the sequence \(Y_{j}\) under each of the trained models \(\lambda_{i},1\leq i\leq N\). These \(N\) models can be regarded as a set of \"sampled points\" from the model space \(\mathbf{\Lambda}\) surrounding the HMMs that actually span the data space. Thus, these \(N\) trained models become a good discrete approximation \(\bar{\mathbf{\Lambda}}=\{\lambda_{1},...,\lambda_{N}\}\) to the model space of interest.  
If we normalize the likelihood matrix \(\mathbf{L}\), which means each column adds up to one, we get a new matrix \(\mathbf{L}_{N}\) whose columns can be regarded as the probability density functions (pdfs) over the approximated model space conditioned on each of the individual sequences:  
\[\mathbf{L}_{N}=[f_{\bar{\mathbf{\Lambda}}}(Y_{1}),...,f_{\bar{\mathbf{\Lambda }}}(Y_{N})] \tag{6}\]This interpretation leads to the Kullback-Leibler (KL) divergence, which is a natural choice for the measurement of the dissimilarity between two pdfs. The discrete case of the KL divergence formulation is as follows:  
\[D_{KL}(f_{P}||f_{Q})=\sum_{i}f_{P}(i)\text{log}\frac{f_{P}(i)}{f_{Q}(i)} \tag{7}\]  
where \(f_{P}\) and \(f_{Q}\) are two discrete pdfs. Obviously, the KL divergence is not a proper distance because of its asymmetry; a symmetrized version is used as:  
\[D_{KL}^{sym}(f_{P}||f_{Q})=\frac{1}{2}[D_{KL}(f_{P}||f_{Q})+D_{KL}(f_{Q}||f_{P })] \tag{8}\]  
Thus, the distance between the sequences \(Y_{i}\) and \(Y_{j}\) can be defined as:  
\[d_{ij}=D_{KL}^{sym}(f_{\Lambda}(Y_{i})||f_{\Lambda}(Y_{j})) \tag{9}\]  
Distances defined this way are obtained according to the patterns created by each sequence in the probability space spanned by different models, and the distance measured between two sequences \(Y_{i}\) and \(Y_{j}\) involves information related to the rest of the data sequences.