## 4 Anomaly Detection
### Local Outlier Factor  
Abnormity of residents' daily behavior refers to some event deviating from the general rule of events in daily life. For example, a resident with high blood pressure needs to take medicine on time to bring high blood pressure down. If one day he/she does not take medicine on time or take no medicine at all, it will be defined as his unusual behavior. A challenge in detecting residents' anomalous behavior is that residents' behaviors are dynamically changing. Hence, we cannot simply use occurrence of some events to judge if a behavior pattern of the resident some day is abnormal. Besides, anomalous behaviors of a resident are often very few, which cannot represent the distribution of abnormity very well. Since LOF (local outlier factor model) is an unsupervised learning approach and needs no training dataset when detecting outliers, it overcomes the difficulty of annotating anomalous behaviors in residents' behavior dataset and effectively reduces probability of erroneous judgment. Therefore, the paper employs LOF to detect residents' abnormal behavior pattern. Based on the method used to classify residents' behaviors in Section 4.1, this paper uses behavior characteristics, including duration, scene, times and start time, to calculate LOF outliers and show the final results.  
Define \(X=[x_{1},x_{2},\ldots,x_{t}]\), where \(x_{t}\) is an eigenvector used to describe residents' behavior at date \(t\in[1,2,\ldots,T]\). Based on users' every day activity, we find user's anomaly degree on that very day using LOF algorithm. Definition of behavior anomaly degree is shown as Equation (1).  
\[LOF_{k}(x_{t})=\frac{\sum_{y\in N_{k}(x_{t})}\frac{lrd_{k}(y)}{|I_{k}(x_{t})|} }{|N_{k}(x_{t})|}\ =\ \frac{\sum_{y\in N_{k}(x_{t})}lrd_{k}(y)}{|N_{k}(x_{t})|lrd_{k}(x_{t})} \tag{1}\]  
In Equation (1), \(N_{k}(x_{t})\) is the set of the \(k\)-nearest neighbors of \(x_{t}\) in the feature space \(X\). \(lrd_{k}(x_{t})\) is local reachability density of the feature vector \(x\) which can be calculated by Equation (2).  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Features** & **Duration** & **Times** & **Start Time** \\ \hline \multirow{4}{*}{Activity can be selected from} & Sleep, Read, & Enter Home, Leave home, Dress, Phone, Cook, Eat, & Bathe, Evening \\  & Watch TV, Sleep & Bed Toilet Transition, Toilet, Groom, Cook Lunch, & Meds, Morning \\  & Watch TV, Sleep & Eat Lunch, Wash Lunch, Personal Hygiene, Wash & Meds, Cook \\  & Out of Bed, & Dishs, Bathe, Evening Meds, Morning Meds, Cook & Breakfast, Eat \\  & Relax & Dinner, Cook Breakfast, Eat Breakfast, Eat Dinner, Wash Dinner, Wash Breakfast & Breakfast, Wash \\ \hline \hline \end{tabular}
\end{table}
Table 3: Activity characteristics used in calculation.  
\[lrd_{k}(x_{t})=1/\left(\frac{\sum_{y\in N_{k}(x_{t})}rd_{k}(x_{t},y)}{|N_{k}(x_{t} )|}\right) \tag{2}\]  
In Equation (2), \(rd_{k}(x,y)\) is the distance used to define what is called reachability distance, which can be calculated by Equation (3). \(d(x,y)\) represents the Euclidean distance between feature vector \(x\) and \(y\). \(k\) distance(\(x\)) is the max distance of the feature vector \(x\) to its \(k\)-nearest neighbors.  
\[rd_{k}(x,y)=\max\{k\;distance(y),d(x,y)\} \tag{3}\]  
Since abnormality of behavior is only in comparison to its several neighbors instead of the entire data set, the result is still valid in the case of residents with multiple potential lifestyles. Therefore, we can find resident abnormal behavior by LOF in the data set based on the regularity of resident's life.