{'fraction_non_alphanumeric': 0.029747836787311757, 'fraction_numerical': 0.013047639510127546, 'mean_word_length': 4.879421221864952, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
WiSleep: Scalable Sleep Monitoring and Analytics Using Passive WiFi Sensing

Sleep deprivation is a public health concern that significantly impacts one’s well-being and performance. Sleep is an intimate experience, and state-of-the-art sleep monitoring solutions are highly-personalized to individual users. With a motivation to expand sleep monitoring at a large-scale and contribute sleep data to public health understanding, we present WiSleep, a sleep monitoring and analytics platform using smartphone network connections that are passively sensed from WiFi infrastructure. We propose an unsupervised ensemble model of Bayesian change point detection to predict sleep and wake-up times. Then, we validate our approach using ground truth from a user study in campus dormitories and a private home. Our results find WiSleep outperforming established methods for users with irregular sleep patterns while yielding comparable accuracy for regular sleepers with an average 79.5% accuracy. This is comparable to client-side based methods, albeit utilizing only coarse-grained information. Finally, we show thatWiSleep can process data from 20,000 users on a single commodity server, allowing it to scale to large campus populations with low server requirements.


INTRODUCTION
Sleep is a vital activity that significantly impacts human wellbeing, productivity and performance [36]. Prior research has shown that 30% of the adult population does not get enough sleep, with many adults sleeping less than 7 hours per day [13,24]. Both work-related stress and the increasing use of mobile devices throughout the day, particularly in the evenings, have increased sleep disorders [39]. The repercussions of sleep deprivation leading to serious health consequences such as heart disease, stroke, and depression [2,32] have become a public health burden. The American Academy of Pediatrics confirms sleep deprivation as a public health epidemic, especially among students [15,32].
Sleep is an intimate experience; hence many sleep monitoring technologies are highly personalized for individual use. Monitoring data sources specific to sleep are challenging to acquire for public health understanding and benefits [32]. Such information could benefit professional health administrators to keep abreast of a community's needs and well-being. In particular, college students who reside in oncampus dormitories make an insightful study population of irregular sleepers due to overwhelming academic demands. Further, many college campuses, such as in the United States, are known for their social events during the semester. The active party culture exacerbates bad sleeping habits among students [40]. These irregular habits can significantly and negatively impact students' concentration and academic performance [27].
Numerous solutions have emerged for sleep monitoring. Polysomnography is a gold standard in medical research [37] practical for short-term monitoring. The consumer market witnessed growing alternatives for sleep trackers using accelerometers, heart rate sensors [4,12], and soon, research prototypes of in-ear devices [29] will follow. However, there remains a general reluctance to use wearable while sleeping [33], making it challenging to support long-term monitoring. Contactless methods utilizing doppler radar and RF signals have been proposed [19,33], but they require specific instrumentation in building infrastructures. Much prior work includes using smartphone sensors, such as microphones, cameras, phone activity, and screen usage [10,16,17,28,46]. Collectively, these client-side approaches require direct sensing of users' devices. Unfortunately, such methods cannot be easily scaled to large groups of users and would eventually face pushback over privacy concerns.
Our work puts on a strong focus on the challenge of developing sleep monitoring analytics at scale for public health benefits while still rendering personal wellness goals. In this regard, scalability is important to support sleep monitoring for a large community of users, such as on-campus student residents in a university. With the growing efforts in monitoring students' mental health and well-being using sensing technologies [42,45], our work's broader goal is to incorporate sleep monitoring analytics into these efforts and offer a holistic community well-being service.
In this paper, we present WiSleep 1 , a scalable sleep monitoring analytics platform utilizing coarse-grained WiFi events that are passively sensed from the WiFi infrastructure. Specifically, when a user's smartphone is connected to the WiFi network, it generates access point (AP) association and disassociation events, which we retrieve from the APs bypassing direct mobile sensing of users' devices. Therefore, we use these events as a proxy for user activity and predict sleep duration by discovering periods of declining network activity from the user's phone. We show that the passive observations of AP associations are adequate to infer a user's sleep schedule.
Our key design goal is scalability to promote and support adoptions at population-scale, for example, among large groups of students on college campuses. Firstly, choosing a network-side approach helps scale our technology rapidly to every device (and, by proxy every, user of these devices) as soon as they are connected to the WiFi network, without requiring active client participation. Second, our approach is sufficiently ready for immediate deployment without requiring additional hardware installation to the WiFi infrastructure. Third, although we focus on college campuses as our target community, we also demonstrate that our approach is general and work for users in private homes. This paper makes the following contributions: (

BACKGROUND AND RELATED WORK
In this section, we present the important aspects of sleep monitoring solutions and its prior efforts. Many sleep monitoring solutions are built on IoT and wearable devices to address individual users' sensing requirements. These devices are increasingly accepted for everyday use, but they are not as ubiquitous as other mobile devices such as smartphones. This is an important consideration as scalability is a key capability of our system. Our focus is to facilitate population-scale sensing while maintaining personal use. In this work, we consider on-campus students residing on campus as our large population sample. In what follows, we describe established approaches and how our technique aims to address their shortfalls. These works are summarized in Table 1.
Wearables. Sleep monitoring over long periods has become feasible due to the availability of wearables. Consumer trackers such as Fitbit [12] leverage accelerometer or heart rate data. Researchers have explored novel methods such as in-ear wearable sensors to precisely monitor sleep quality and duration [29]. By design, wearables are appropriate for individual monitoring. They can support population-scale monitoring, but all users must wear such devices and transmit the sensed data to the cloud for large-scale analysis. Fitness trackers are still not ubiquitous despite their increased popularity and impose a deployment cost for large users. More importantly, many users remain reluctant to wear an on-body device while sleeping [33].
Contactless Techniques. In contrast, contactless sleep monitoring overcomes adoption pushbacks by installing sensors in the environment (e.g., wall sensors). These efforts include Doppler radar or RF signals to sense sleep patterns [19,25,33]. While such techniques show significant promise, they incur a higher cost for population-scale sensing due to the need to deploy instrumentation in buildings (e.g., all dorm rooms in a college campus).
Mobile Sensing. The ubiquity of smartphones motivates many researchers to use phone-based sensors as sleep trackers. These works included microphones, cameras and phone activity logs [10,16,17,28,35,46]. Others have shown monitoring screen activities can be an effective method to infer sleep and wake [1,10] due to the strong correlation between (lack of) phone activity and user's sleep. Such a method does not incur any hardware deployment costs due to the ubiquity of smartphones. However, client-side smartphone-based methods face different challenges to scale up to a large number of users. First, they require dedicated apps, which can be a hurdle at population scales 2 . Second, longitudinal monitoring can be an issue when users change or upgrade phones. This practice is typical among tech-savvy student users, and device changes impose re-installation overheads, which is hard to automate.
Detection Mechanism. All of the above methods can be classified as being supervised or unsupervised. Supervised approaches require training data to build detection models. Since collecting large amounts of training data is challenging, a supervised approach is generally harder to scale. In contrast, unsupervised approaches, such as Bayesian methods, do not need any training data and are easier to deploy at a population scale. For example, Khadiri et al. and Cuttone et al. employed unsupervised Bayesian inference to infer sleep periods using different types of sensors [10,22]. Similarly, an unsupervised approach is best in our case to build a detection model without worrying about training models.

USING PASSIVE WIFI SENSING
The shortcomings of prior work inform our decision to leverage a network-based sensing approach. In what follows, we justify our considerations to adopt WiFi-based sensing.
Passive WiFi Sensing. Our work uses the Passive WiFi sensing method for sleep monitoring, which has previously been employed for respiration monitoring [23], social interaction monitoring, and campus health and activity monitoring [18,21,45]. We hypothesize that network activity from a student's phone is strongly correlated to the user's activity and awake state, thus simply observing these network activities through coarse-grained AP association events, is sufficient to infer sleep periods. Similar to techniques relying on phone's screen activity, we expect long periods of low network activity are correlated to sleep periods.
Network-centric Approach. Our approach is entirely networkbased, employing device association and disassociation messages generated by the APs in the network. This has several advantages over client-side methods: 1) Users do not need to download a dedicated mobile app, and our solution is impervious to any device change, 2) Many enterprise WiFi and home WiFi routers provide logging capabilities of coarsegrained network events for the network's performance and security monitoring; in such cases, our approach can utilize these logs without the need to collect any additional data. Overall, our approach is based on coarse-grain AP-level events rather than fine-grained events (e.g., network packet rates), which would impose a higher monitoring overhead on the network. We also utilize existing WiFi networks and ubiquitous smartphones, avoiding additional deployment costs. To the best of our knowledge, our approach is the first to infer sleep periods using a network-centric method and AP-level network events.  Figure 1 illustrates a time-series example of a user's smartphone network events over a 15-minutes interval throughout a 24-hour period. Consider a typical smartphone usage where it is connected to WiFi for online communication. In doing so, the device connects to a nearby AP. The device will periodically re-associate to stay connected to the best AP for as long as the user needs the connection, thus, triggering a sequence of association and disassociation events. The device eventually falls into a power-saving state when the user stops interacting with it. Periodically, the device 'wakes up' (e.g., every 15 to 30 minutes)and performs a network scan that triggers a re-association. The fluctuations in these events help us predict the user's activity and state. The main challenge is in determining which period of low network activity should accurately infer a user as (actually) sleeping. The key assumptions of our work are frequent smartphone and WiFi usage -as humans grow increasingly reliant on their smartphones [41], much of the common online access such as video streaming, mobile gaming, and virtual communication demand low latency and high bandwidth networks that WiFi can offer [38]. Because of this, WiFi is more preferred as home network solution, running more efficiently in the long run than relying on cellular networks [43].

Design Rationale and Challenges
Clearly, assuming that a reduction in WiFi network activity corresponds to sleep can be highly erroneous. We list several situations where noise can be introduced: (1) A user may be awake but did not immediately use their phones. (2) A user waking up briefly in-between sleep and using their phone, thus missing periods of actual sleep. (3) A user may have long inactive periods because they are not utilizing their phones, but they are awake. Further, our approach is susceptible to confounding factors, (4) when the smartphone switches between nearby APs for the most optimal WiFi connection, it produces what is known as the 'ping-pong effect,' (5) software updates that automatically run on the smartphone may be incorrectly inferred as user activity.
Overall, our predictions in sleep and wake-up times are expected to be less accurate. As illustrated in Figure 2, ceasing phone activities before bedtime does not immediately translate to sleep onset, as users may take some time to fall asleep. For these reasons, it is difficult to tackle our work as a simple binary classification problem where the longest sequence of low activity periods over a day is determined as the sleeping period.
In the rest of the paper, we describe how these challenges are addressed and can support compelling utility at a populationscale. We demonstrate through our primary use-case, focusing on sleep monitoring for the student population and its utility for the students' health and well-being services. A supplementary study on a private home shows how our approach remains relevant for personal use.

BAYESIAN SLEEP INFERENCE
Our detection mechanism is an ensemble method based on Bayesian change point model. In what follows, we describe the problem statement to build our model.
Problem Statement. As stated in Section 3.1, we assume the primary user's device to be smartphones. Consider an enterprise WiFi network deployed in a university campus with M access points and N users. We model each user as being in one of two states: awake or sleeping. When the user is 'awake', they can either be mobile (moving from one location to another) or localized at a given area and assumed to use their phone from time to time frequently. In either case, the phone generates AP association and disassociation events logged by the network, as discussed in Section 3.1. The phone may also generate authentication events (e.g., when adopting enterprise RADIUS authentication) to verify users using their credentials. The network also logs these authentication events.
With a 24-hour trace of time-stamped WiFi events, we use this trace to compute the rate of network events; we divide the 24-hour period into time slots and count the number of events in each slot. Let denote WiFi event rate seen at time and let denote the slot size (we choose a default slot size of =15min, yielding 96 slots per day). Given a time series of event rates , our problem is to estimate the sleep onset time, , and the wake-up time, for the user.

Bayesian Change Point Detection
We estimate the sleep and wake-up times from WiFi events based on Bayesian Change Point detection, well established to detect significant changes in time-series data and have been widely used for anomaly detection. As illustrated in Figure 1, we must as accurately detect a significant drop in the phone's network activity that occurs at sleep time and a corresponding rise that occurs upon a wake time. Hence, and are significant change points that we must detect in our time series data , based on Bayesian inference of change points.
We model as a Poisson process (i.e, a time series of event rates in a time slot is Poisson), where is the mean of the distribution.

( ) =
( , ) = − ! Since the mean event rate drops at sleep onset time and rises at wake-up time , therefore and denote the mean event rate when a user is asleep and awake.
Since the mean event rate is high when the user is awake and the event rate is low when asleep (see Figure 1), we assume that follows a gamma distribution with the following density function.
Given these assumptions, we need to detect two change points and when the event rate in the time series transitions from to and vice versa. Bayesian change point detection involves finding the posterior distribution of the change points for different values of and maximizing it to derive the Maximum A Posterior Estimates (MAP). This is done by using a Metropolis-Hastings algorithm [8] to estimate these parameters for each value of and choosing the that corresponds to MAP as the change point. As in any Bayesian approach, we need to assign priors to the model parameters (i.e, , , , ) and then use Metropolis sampling to derive posterior conditional distribution of each parameter from its joint distribution. As noted earlier, the value of where the distribution is maximized (MAP) represents the change point (and ).

Ensemble Model for Sleep Inference
The need for our Bayesian approach to be robust to noisy WiFi data and irregular sleep patterns (see Section 3.1) makes it challenging to build a model with strong priors -consequently, models with weak (or non-informative) priors impact model accuracy. Accordingly, we employ an ensemble method comprising three separate models, each with priors suitable for different scenarios, and finally, apply Bayesian Model Averaging (BMA) [14] to derive a combined estimate. The composition of our ensemble model is:

Model 1) Bayesian Model with Location-based Non-informative
Prior. assumes that the sleep periods occur in one or a small subset of locations, such as a dorm room. The location information is inferred directly from the AP placements without localizing the device itself. Priors for a particular day are chosen based on the times spent at these locations. This model is useful for users who have irregular sleep hours but consistent sleep locations. Such location based priors avoid choosing time periods spent outside the dorm areas for possible sleep periods.
To specify the prior for a specific day, we assume the mapping of all campus APs to their building locations are known a priori and only consider a subset of APs located in the residential dorms. For every user's 24-hour WiFi trace, we determine the longest duration spent in a dorm building (based on network activity observed by the dorm APs). Note, however, this assumption ignores sleeping behaviors outside the dorm area.
Let [ , ] denote the time-interval spent in dorm areas, hours as the minimum sleep duration (e.g., = 3 hours is equivalent to 12 time slots of 15-min intervals). Since sleep patterns can be irregular, we assume and are uniformly distributed within [ , ]. Hence, the model priors are given as: The event rate while awake is assumed to be 2.5 events/bin yielding a prior: The event rate while sleeping is assumed to be a low nonzero rate: Model 2) Bayesian Model with Normal Prior. assumes that the sleep onset and wake-up times are normally distributed (rather than uniformly distributed as in the previous model), thus suited for users with regular sleep and wake-up times. Let and denote the start and end times of their daily sleep period. and are normally distributed with a standard deviation . Assume that a student goes to sleep at 12:00 am and wakes up at 8:00 am the next day, with a standard deviation of 3 hours ( =12am, =8am, =3). The priors for and are the same for all models. Hence, the model priors are given as: Model 3) Bayesian Model with Hierarchical Prior. is useful when sleep behavior changes based on the day's events, resulting in varying standard deviation. Let and denote the start and end times of a sleeping period, normally distributed as per Model 2 ( =12am, =8am). As sleep behavior varies based on the day's events, and can be derived by adding hyper-priors , and to the normal priors. We set the hyper-priors to a non-informative distribution since we have no strong knowledge about them. The priors for and are the same for all models. Hence, the model priors are given as: Once all models are utilized for change point detection, these results are averaged using Bayesian Model Averaging. All models are weighted using a marginal likelihood where the weights are sensitive to the prior distribution. We generate the weights from the posterior distribution of these models using the Watanabe-Akaike Information Criteria (WAIC) [44]. WAIC relies on the complete posterior distribution rather than on a single point estimate, making it a more robust approach for generating a combined estimate from the ensemble predictions.

SLEEP MONITORING SYSTEM
We now describe how our model is integrated to deliver WiSleep, our sleep monitoring and analytics platform.

System Overview
WiSleep, illustrated in Figure 3, comprises four key components. The first is WiFi Data Collection Engine, which gathers all association and disassociation events from a WiFi network. Second, the Pre-processing Engine anonymizes all device MAC address in the raw WiFi event logs, creates event traces specific to a user's primary device and classifies on-campus student residents based on several heuristics. Change Point Detection Engine is the third and main component, which converts the 24-hour WiFi trace for each user into a time-series of event rates and perform change point detection using our ensemble model (see Section 4 for details). Fourth and finally, our Analytics Platform provides different levels of descriptive information to identify trends in sleep patterns. We have built a prototype of our system and deployed it on a university campus in the Northeastern United States (blinded for double-blind review). We discuss implementation of WiSleep in the context our campus deployment next.

Data collection Engine
WiSleep assumes the utilization of a WiFi network. In an enterprise setting such as campus, network of APs do the logging, whereas in a residential setting, typically a single AP or a WiFi mesh log the events. Our campus deployment consists of 5500 HP/Aruba wireless APs, managed by 7 wireless controllers. We leverage each AP's built-in logging capabilities that generate distinct types of syslog messages [5]. The syslog data is ultimately sent to a central syslog server for data aggregation of multiple IT systems and network components. WiSleep utilizes event types specific to device association, disassociation, re-association and successful authentication [5]. In a residential setting, logging is done by independent APS in each home separately uploading the logs to a prep server.
Scalability: WiSleep has no specific data collection scalability challenges to overcome for two reasons. First, enterprise networks are already designed to log events at a populationscale. For example, our campus WiFi network generates 2 GB of syslog data comprising up to 11.5 million total events from approximately 58,000 devices and 5,500 APs on a typical weekday. Second, WiSleep can use real-time location system (RTLS) reports the same way as syslog data. Specifically, reports of all devices by the RTLS are treated as association events. If a device reportedly disappears from an AP, it is treated as a disassociation event. WiSleep can thus use either RTLS or syslog data equipped in existing WiFi networks, such as Cisco and Aruba [20].

Preprocessing Engine
Our pre-processing engine takes in the syslog data (with anonymized MAC address) as input. Note, anonymization is performed on our campus IT department's server before data is copied to our system. The engine proceeds by partitioning event logs to construct per-device event logs of each user's primary device; the primary device is one that makes the largest number of daily AP associations (e.g., over a week). We maintain an up-to-date list of user devices to avoid pulling WiFi events from secondary and/or obsolete devices (e.g., a user may change their smartphone to a new model). Finally, we apply a heuristic to identify devices with high activity presence in dorm areas as on-campus student residents. The pre-processing engine is written in python using 900 lines of code.

Change Point Detection Engine
Processed per-device event logs are input for our detection engine. It computes WiFi event rates in 15 minutes time slots, spanning from 18:00 hours to 17:59 hours the next day. Accordingly, our model predicts the sleep and wake-up time of users and delivers population-scale and individual-level analytics. We describe our model's performance results in Section 6 and demonstrate our predictive analytics through several case studies in Section 8.
System Performance Metric: Two performance measures for our sleep monitoring analytics platform are accuracy and timeliness. As reasoned in Section 4, our engine runs on an ensemble of models based on Bayesian change point detection to yield more acceptable accuracy despite working with weak priors. In Section 6, we present results from comparing the efficacy of WiSleep compared to three baseline techniques (i.e., rule-based, normal and hierarchical priors) and tabulate the prediction accuracies in Table 3.
To achieve timeliness in delivering a population-scale analytics solution, our model utilizes Metropolis-Hashtings algorithm [8], which estimates the parameters and for one user in approximately 4 seconds. We demonstrate in Section 7.4 how WiSleep is computationally efficient in producing predictive analytics of 10,000 on-campus student residents under 12 hours. While a single server is adequate to handle the processing needs on our campus, WiSleep uses a cluster to scale to larger user populations by parallelizing the analysis of user device traces across servers 3 . In a practical use-case for our campus health administrators, WiSleep can generate reports of sleep deprivation quickly enough to render pertinent insights.

Analytics Platform
Our system extends descriptive analytics of users' predicted sleep data to provide insight into sleep patterns. Section 8 demonstrates several ways our data can be represented and how our findings support prior research on sleep studies, particularly on college students. Further, in Section 9, we discuss how our analytics feature can be operationalized to several end-users for public health and personal use while upholding ethical considerations.

EXPERIMENTAL EVALUATION
We experimentally evaluate our model by first, assessing model performance from conducting a study among users living in campus dorms and private housing. Next, we compare model performance with other rule-based and Bayesian techniques.

Datasets and User Study
WiSleep has been deployed on our campus and gathering event logs of all connected devices. Our university has over 31,000 students and close to 14,000 on-campus student residents. With approximately 58,000 detected devices, we anticipate 14,000 of these devices to be applicable for our sleep monitoring analyses. Table 2 summarizes our datasets. The first is an IRB-approved user study conducted among 15 on-campus undergraduate residents. We held in-class advertising to recruit students over two semesters (Fall 2019 and Spring 2020). We precisely identify these users' hashed MAC addresses by monitoring their WiFi events from a dedicated AP on-campus. Each student was given a Fitbit device for tracking their sleep, providing ground truth data. The second is for off-campus private housing for 1 homeowner. His event logs were collected from a home WiFi router (Note: event log collection is possible in any programmable router) with the MAC address specified. We also asked participants from both groups to maintain written logs of their sleep and wake times for added verification.
The other dataset consists of per-devices event logs of 7,000 students for a given day. Note that this dataset is only used for our scalability analysis in Section 7.4. The final dataset consists of 1000 anonymous student dataset collected over a week to provide an illustrative case study in Section 8, on the types of sleep analytics WiSleep can deliver.
Ethical Considerations. : This paper's data collection and analysis were conducted under safeguards and restrictions approved by our Institutional Review Board (IRB) and Data Usage Agreement (DUA) with the campus network IT group. All device MAC addresses and authentication information are anonymized using a strong hashing algorithm. User identities were blinded by assigning numeric identifiers. Ground truth was collected within the IRB approved protocol. It is important to note that our population-scale analysis was performed on aggregate data of anonymous users. Individual analyses were performed on users who had consented to this study.

Validation Study
Our first experiment aims to validate our approach and utilizes ground truth data from the user study dataset. We compare our prediction values, and , with the ground truth Fitbit data and compute four metrics: Accuracy, Precision, Recall, and F-score. Accuracy is the proportion of correct predictions (both sleeping or awake periods) relative to all predicted sleeping or awake periods. Precision is the ratio of all correct sleep/awake periods to the total number of predicted sleep/awake periods. F-score indicates the optimal balance that maximizes precision and recall (a score of 1 indicating a perfect predictor).  Table 3: WiSleep's performance compared against three baselines. Table 3 summarizes our results, with our technique obtaining an average accuracy of 79.5% (+/-6.3%, max: 90.2%, min: 69.6%), 74.8% precision, 87.1% recall, and 0.81 F-score in predicting sleep for participants in the user study. We further compare this performance to a baseline rule-based heuristic and state-of-the-art Bayesian approach in the next section.  To better understand scenarios where WiSleep performs well or yields higher errors (as its accuracy varies from 69.6% to 90.2%), we show data from two specific users in Figure 4 that represent the best and worst case for WiSleep. Figure  4(a) depicts the daily event trace for user 14 (with a high 85.8% accuracy). The user exhibits near-ideal behavior where sleep onset occurs soon after ceasing phone activity, while the resumption of phone activity occurs soon after waking up.

Accuracy Precision Recall Fscore
In contrast, Figure 4(b) depicts participant 13 who exhibits behavior that is the worst case from WiSleep's perspective -yielding errors of approximately 3 hours. In particular, the participant's phone exhibits clear WiFi activity for several hours after the initial sleep onset. The participant appears to exhibit restless sleep, waking up a few times in-between and use their phone; the resulting network activity is erroneously interpreted as an awake period by WiSleep. Similarly, the participant wakes up around 6 am as per ground truth data but did not immediately use their phone until 9 am, thus confuses WiSleep. This example highlights a key limitation of WiSleep -in particular WiSleep assumes that appropriate network activities from their phone will reflect users' physical behavior; that is, if the user is asleep, the phone will reduce its overall activity and vice versa. However, if this assumption is not true (as in the case for user 13), the accuracy of WiSleep will drop. The overall accuracy for participant 13 over the entire study was 76.8% and 85.8% for participant 14, as shown in Figure  5, with user 13 consistently showing worse performance.
It is important to note WiSleep accounts for transient network activity in its approach; such activity is effectively noise for our system caused by phone apps and services that independently activate without user behavior. For example, push notifications arriving when the user is asleep or background downloads are among the many common sources of noise. We particularly address these issues in Section 7.1 and 7.2.
Private Home Use. To demonstrate the applicability of our system in a private setting, we tested WiSleep with one home user and one WiFi AP deployed. In a typical home network setup, a user will have the option to set their mean bed and wake-up times as part of initializing WiSleep. For our user, these times were set to 11:00 pm and 7:00 am, respectively. It is important to note that in this study, we are only tracking a single home user. We discuss in Section 9 how multiple home users can be monitored by WiSleep. Upon running our model for a period of one week, WiSleep successfully yields approximately 85% accuracy. Figure 7 charts the number of WiFi events detected from the user's primary device, and accordingly, his predicted sleep duration and ground truth for two different days, 1 and 2 . As observed in 1 , WiSleep predicts the sleep time to be 10:45 pm despite the phone falling inactive since 7:30 pm. The predicted wake-up time is 6:15 am, that is, 45 minutes earlier than the initialized wake-up time as the phone network activity was recorded to be active once again. 2 illustrates a key aspect of our implementation. It is important to note that a completely inactive period of our user will not result in WiSleep falsely predicting sleep. In fact, on 2 , the user was confirmed to not be present at home between 8:00 am and 6:00 pm. For this reason, the WiFi network captured no network activity, including periodic pings, which would otherwise be recorded had the user (and his primary device) been physically present.

Comparison with State-of-the-art
Next, we compare WiSleep to three other techniques: a rulebased heuristic and two state-of-the-art Bayesian methods. Our rule-based heuristic first determines a user's residential dorm. It classifies the time (slot) spent in their dorm as active or inactive by checking if the observed WiFi rate > 2 ( 2 is chosen to ignore the periodic pings). Accordingly, the longest inactivity interval is decided as the user's sleeping period. Our first state-of-the-art Bayesian approach uses Normal priors based on a technique proposed by El-Khadiri et al. [11]. The second utilizes hierarchical priors based on a technique by Cuttone et al. [9]. Table 3 compares the efficacy of the four methods. Overall, WiSleep achieves the highest average accuracy of 79.5%, which is marginally better than   The box plots in Figure 6 show plots of time differences between predicted sleep and wake-up times, compare the predicted sleep duration with ground truth values. Our results indicate that WiSleep and the Hierarchical method tend to perform better in predicting sleep time (average time difference of WiSleep: 102 minutes, Normal: 146 minutes, Hierarchical: 94 minutes), while WiSleep and the Normal method perform better in predicting wake-up times (average time difference of WiSleep: 32 minutes, Normal: 36.5 minutes, Hierarchical: 62.5 minutes). The rule-based heuristic is less robust to noisy data and yields the highest errors. This result shows an ensemble model's ability to match the performance of a better Bayesian model depending on its scenario.
To illustrate the benefits of an ensemble approach, let us consider user 15, who demonstrates changing sleeping patterns (refer Figure 8) with significant day-to-day variations in the ground truth data provided. WiSleep yields a higher accuracy of 84.8% over the other two Bayesian methods (Normal: 74.9%, Hierarchical: 78.5%) because our ensemble method is already designed to handle these exceptions.

PRACTICAL CONSIDERATIONS
In Section 5.4, we presented accuracy and timeliness as two performance measures for our sleep monitoring analytics platform. Here, we evaluate the impact of noisy data and larger numbers of users on the efficacy of our approach. 7.1 Noisy Data: Ping-Pong Effects Figure 9: Ping pong events during a sleeping period for user P11. Green shaded area denotes the ground truth for the user's sleeping period. Cyan horizontal line denotes the primary AP that user is usually connected to, while black horizontal lines denote other APs in close proximity.
When a stationary device sees multiple APs with similar RSSI values, it may switch back and forth between them, causing a "ping-pong" effect. The noise from this effect can resemble network activity despite the absence of user interactions. To avoid such instances, we groups APs in an area, such as a dorm floor, and filters out patterns that resemble ping-pongs between nearby APs. To demonstrate the heuristic, consider user P11 from our user study, whose phone exhibits significant ping pong noise. Figure 9 illustrates a user's WiFi activity from different APs. We observe multiple ping-ponging events between 3:00 am -4:00 am, but the connection remains consistent with the primary AP throughout the rest of the sleep period. Without our heuristic, WiSleep would have predicted sleep only after the connection stabilizes at 4:00 am, with a 45 minutes delay from the actual sleep time (instead of 3:00 am which is closer to true value).

Noise from Background Activities
Background activities such as push notifications, software updates etc. can introduce noise by appearing to have active network usage when a user is asleep. Since such activities' frequency is typically low, our ensemble method is resilient to noise introduced by their presence. Also our validation study using real Android and iOS devices where such activities are already present demonstrate the efficacy of our approach despite such confounding factors. To evaluate the impact of such noise, we carefully introduced background activities in a controlled fashion. Here, we used an Android phone, alternating between long periods of idle, followed Figure 10: Ability of our approach to handle noise from a phone's background network activities. Shaded area denotes WiFi events detected in a residential area.
by some push notifications, and finally, a mobile app download from the Play store. We created a synthetic device trace where we inserted this noisy trace into an actual device during a nightly sleep period.
The synthetic trace, shown in Figure 10, was then subjected to our change point detection method. As shown, the sleep and wake-up times before and after the noise injection are quite similar (≈ 15 minutes difference in wake up time). This demonstrates WiSleep's ability to be robust to a modest amount of noise from background activities. Figure 11: Impact of inactive periods on WiSleep's model performance in non-residential (red shade) and residential (blue shade) areas.

Impact of Inactive Periods
There can be multiple device inactivity periods for a user in a day, leading to false positives. WiSleep accommodates false positives by picking only the relevant inactive periods using priors for sleep and wake-up times, and then considering a user's physical presence in their residential area. For instance, in Figure 11, we observe that a user was inactive at two time periods; first, 8:15 pm to 6:00 am and second, from 8:15 am to 5:30 pm. Inactivity between 8:15 pm to 6:00 am is typically classified as the eventual sleeping duration, primarily because the user is in residence. However, this example illustrates a different case -the user is in residence between 8:15 am to 5:30 pm (this is highlighted in light blue area). A similar situation can be seen in 7b), where WiSleepwas able to identify network absence, thus avoiding false positives.

System Scalability
In a real-world implementation of a sleep monitoring solution for on-campus student residents, WiSleep needs to scale to tens of thousands of users present on campus. Next, we evaluate the scalability of the WiSleep system to support a large number of users under accuracy and timeliness constraints.To validate our argument, we examine two factors -1) the number of samples needed for computation and 2) the CPU cost of the sampling process. First, we determine the number of samples needed for each user to create accurate estimates in the sampling process employed by WiSleep . Generally, the more samples used, the higher the accuracy. However, we must also consider that higher samples will result in higher CPU cost, affecting the results' timeliness.  Figure 12 shows the accuracy and the CPU cost of the computation for two different users obtained by varying number of samples from 10 to 2000 over a period of one week. We observe that using between 10 to 50 samples yields an accuracy of approximately 85%, which does not significantly change as the sample size is increased. Naturally, the more samples used, the higher the CPU cost. The results show that a good accuracy -computation tradeoff for WiSleep is to use 50 samples producing an accuracy of 85% with a CPU processing cost of approximately 4 seconds per user.
(a) distribution of time taken per user (b) CPU overheads for 1,000 to 20,000 users Figure 13: WiSleep scales to > 20k users on a single server Next, we examine how WiSleep scales when processing a large number of users. Figure 13 shows that the CPU time scales linearly with the number of users, and prediction cycle is completed in 23 hours for 20,000 users, thus showing that a single server is sufficient to handle all on-campus students at our university Hence, WiSleep can generate reports of sleep deprivation of a large number of users quickly enough to render pertinent insights on the same day. One key point here to mention is that our system currently uses unoptimized python libraries for Bayesian inference and does not use any hardware accelerators such as GPUs. Additionally, the computation is highly parallelizable and can be scaled nearlinearly by using a cluster of servers.

WISLEEP ANALYTICS
We present insights from two case studies to demonstrate how our population-scale aggregate analytics can benefit public health and personal use.

Population-scale Aggregate Analytics
Using our case study dataset of 1000 anonymous student users, we conduct an aggregate-level analysis of their sleep behavior for one week. Figure 14 plots the average sleep duration of all users by weekday. Our results support existing findings on college students reporting longer sleep duration over the weekends [7]. Specifically, we recognize a declining trend of sleep at the beginning of the week, before gradual increments later in the week, and a sharp and stable increment over the weekend. The decrease in sleep duration on weekdays was likely due to various academic demands, typically fulfilled while juggling class hours. Digging deeper, we want to understand the fraction of students who have irregular sleep patterns and how such users' sleep patterns vary compared to students with regular sleep patterns. We adapted the consistency metric proposed by Rashid et al. [34] to generate a sleep consistency score between 0 to 1 for each user -1 denotes the user as having regular sleep patterns throughout the week. We applied a median-split to determine the threshold for categorizing users into groups with regular sleep patterns (score 0.61 to 1) and irregular sleep patterns (0 to 0.6).
First, we find that 839 students out of our 1000 student dataset have irregular sleep patterns. Next, Figure 15 compares the sleep duration for users with regular and irregular sleep patterns, spread out on weekends versus weekdays. The box plot for users with regular sleep shows that the median sleep duration is approximately 9 hours on weekends and weekdays. In contrast, users with irregular sleep patterns show 1.5 hours less sleep on weekends. Most regular sleep users take between approximately 7 to 11.5 hours of sleep on weekends, far different from irregular sleep users who took between 5.5 hours to 10.6 hours of sleep. Overall, both groups show similar sleep patterns on weekdays. The plots also show less variability in sleep patterns during the weekday.
These observations provide several interesting insights. For example, most users in both groups maintain at least 7 hours of sleep on weekdays. Outliers (also irregular sleepers) who clocked less than 2.5 hours of sleep on weekdays generally make the worrisome cases as the lack of sleep will likely affect their class performance the next day. Second, 25% of users with regular sleep patterns would clock at least 7 hours of sleep on weekdays and weekends. In contrast, most students in this category would sleep for a minimum of 5 hours on weekends. Irregular sleepers who lie within the first quartile are more likely not to be getting enough rest, especially when the recuperation period is crucial for the weekend.

Individual-level Sleep Analytics
Next, we illustrate WiSleep's ability to perform sleep analytics for individual on-campus student users over the course of a semester. We randomly selected a subset of our user study participants and retrieved their WiFi events for approximately 70 days from the start of the semester till the semester-end. Note that we intentionally left out the first three weeks, as students were more likely to take this time still to settle into their student accommodation. Figure 16: How do sleep patterns change over a semester? Predicted sleep duration for two participants, P6 and P7, over the semester. Figure 16 illustrates the predicted sleep duration, averaged every three days for two anonymous users, P6 and P7. On the whole, both users display sleep inconsistencies throughout the semester. However, P7's sleep patterns seem fairly consistent at the start of the semester and showed high variability as they transitioned to mid-term week (20/10/2019 -03/11/2019). The same observation can be made for P6, whose largest dip also occurred on 28/11/2019. It is important to note that for P6, the two lowest points (of 3-hours sleep) were attributed to missing data. For example, P6 was not detected to be in the primary residential location for four days between 29/10/2019 to 3/11/2019, resulting in a low average for sleep duration.  On the other hand, P6 tends to sleep longer on weekends (avg = 10 hours 44 minutes, std = 1 hour 50 minutes) than on weekdays (avg = 9 hours 10 minutes, std = 2 hours 37 minutes). While P6 appears to get more sleep overall, we note that P6's sleep duration decreased much more (by one standard deviation) in Week 8 and Week 14, denoting mid-term and final exam weeks (Week 12 corresponds with Thanksgiving recess).
Distinguishing between a user who is present on campus but not getting sleep and a user absent from campus makes a key heuristic for a practical application of sleep intervention using our monitoring system. Since P6 was not detected on campus, the sharp dip (3 hours sleep) in our results should not sound unwanted alarms for intervention. In this example, our results suggest that both participants tend to recover from sleep loss -sleeping at least ten hours on average after only sleeping for ≈ 5 hours in the previous days.

DISCUSSION
We have addressed the challenges of predicting sleep duration and providing analytics for population and individual use. Here, we discuss the implication of WiSleep and its limitations.

Predicting Sleep Patterns
A key extension is detecting polyphasic sleep. Prior research suggests people who generally sleep < 5 hours during the night are more likely to sleep in daytime [26] and those who sleep > 1 hour at daytime are more likely to sleep less at night time [3]. We could conceivably apply a set of rules to check for secondary sleep on days users are monitored to have slept for < 5 hours, either before the sleep time ( −1 ) or after the wake-up time ( +1 ). Our model could use only a uniform prior (see Section 4.2) to find the longest inactive period at these two times. For instance, in Figure  11, if both the inactive periods had occurred in a residential building, the first or second inactive period could be classified as 'secondary sleep. ' This warrants further investigation.
As in Section 7.3, WiSleep handles false positives in several ways. In our campus implementation, sleep duration is only predicted for time spent in residential areas. Whereas in a home implementation, a user's absence is identified by observing ping-pong events from the user's primary device.

Opportunities for Public Health
Indeed, poor sleep hygiene has major health consequences and is a public health issue [2,15,32]. WiSleep can render actionable insights from its aggregated population-scale analytics. our system can play a key role in responding to the call-for-action to advance sleep disorder problems (e.g., provide "open-access" data sources for public health researchers [30]). Our privacy-preserving approach will ensure that trust and confidence can be upheld in data-sharing practices for public health practices [31].

Limitations
First, our approach assumes that device event data is available on a longitudinal basis for daily sleep monitoring. However, data for students may be absent from our logs for numerous reasons. Data unavailability will disrupt WiSleep from its daily monitoring. Our approach is also not free from periodic maintenance to ensure user devices are valid (i.e., users did not change their phones) and maintain current residents (e.g., students may no longer reside in dorms). Finally, unlike prior work [29,33], our approach is limited to predicting sleep duration. One key measure is sleep quality, which requires physiological indicators directly sensed from the user's body (i.e., wearable). There is no workaround to this limitation, but our focus is on analyzing aggregated sleep trends at a large-scale, to which coarse-grained WiFi information is more than adequate.
In this paper, we presented WiSleep, a network-based system to detect sleep periods by passively observing the network activity of a user's phone and provide aggregated and individual-level analytics to accommodate for public and personal use. We presented an ensemble-based Bayesian inference technique to infer sleep from coarse-grain WiFi association and disassociation events. We validated our approach using 16 users either living on-campus dormitories or private home in our study, and showed that it outperforms the state-of-the-art methods for users with irregular sleep patterns while yielding comparable accuracy (79.5% on average) for normal users. Further, we showed that WiSleep can process the data of 20k users on a single commodity machine, allowing it to scale to large campuses with low server requirements. Our large scale case study revealed several interesting insights for population-scale and individual sleep analytics. As future work, we plan to combine our sleep models with stress detection methods to develop a complete student well-being service.