# Accelerometer-based Bed Occupancy Detection for Automatic, Non-invasive
Long-term Cough Monitoring

###### Abstract

We present a new machine learning based bed-occupancy detection system that
uses the accelerometer signal captured by a bed-attached consumer smartphone.
Automatic bed-occupancy detection is necessary for automatic long-term cough
monitoring, since the time which the monitored patient occupies the bed is
required to accurately calculate a cough rate. Accelerometer measurements are
more cost effective and less intrusive than alternatives such as video
monitoring or pressure sensors. A 249-hour dataset of manually-labelled
acceleration signals gathered from seven patients undergoing treatment for
tuberculosis (TB) was compiled for experimentation. These signals are
characterised by brief activity bursts interspersed with long periods of
little or no activity, even when the bed is occupied. To process them
effectively, we propose an architecture consisting of three interconnected
components. An occupancy-change detector locates instances at which bed
occupancy is likely to have changed, an occupancy-interval detector classifies
periods between detected occupancy changes and an occupancy-state detector
corrects falsely-identified occupancy changes. Using long short-term memory
(LSTM) networks, this architecture was demonstrated to achieve an AUC of 0.94.
When integrated into a complete cough monitoring system, the daily cough rate
of a patient undergoing TB treatment was determined over a period of 14 days.
As the colony forming unit (CFU) counts decreased and the time to positivity
(TPP) increased, the measured cough rate decreased, indicating effective TB
treatment. This provides a first indication that automatic cough monitoring
based on bed-mounted accelerometer measurements may present a non-invasive,
non-intrusive and cost-effective means of monitoring long-term recovery of TB
patients.

Index Terms: accelerometer, bed occupancy, cough monitoring, machine learning,
tuberculosis

##  1 Introduction

Coughing is a symptom of many lung diseases including tuberculosis (TB) and
COVID-19. Long term cough monitoring, over periods ranging from days to
months, may allow the progression of such conditions to be tracked in a cost-
effective and non-invasive manner [1]. For example, TB is commonly assessed by
the analysis of sputum samples. This is a time-consuming and costly clinical
practice that requires the engagement of trained medical personnel as well as
specialised laboratory facilities for the analysis [2]. However, experimental
evidence suggests that TB patients that are responding to treatment also
exhibit a reduction in cough frequency [3]. Cough monitoring would offer the
advantages that it requires neither a laboratory nor medical personnel and is
cost-effective since it could be implemented on a smartphone or similar
device.

Although our proposed system has wider applications, we consider the
particular scenario of long-term cough monitoring in the ward environment of a
TB clinic. The objective is to provide an alternative means of monitoring the
success of treatment received by the patients in this facility. Previously, we
have developed a system that can accurately detect coughs from the signal
obtained from the tri-axial accelerometer on-board a consumer smartphone [4].
The smartphone itself is attached to the bed-frame of the patient under
treatment. By not relying on audio signals, as many alternative approaches do,
the system sidesteps the privacy concerns that accompany such audio-based
classifiers [5]. Furthermore, since this is not a wearable sensor, it is less
intrusive and more convenient. However, since monitoring must take place
continuously and over extended periods, it is necessary to know at which times
the patient occupied the bed in order to reliably estimate a cough rate [6].
In this work, we consider such bed-occupancy detection using the same
acceleration signals. We note that eventually both the cough detector and the
bed occupancy detector can be implemented on the same smartphone as a single
integrated system.

The remainder of this paper is structured as follows. First, we provide some
background on bed occupancy detection and the use of accelerometers for human
activity monitoring in Section 2. Next, we describe the compilation of the
dataset we use to train and evaluate our algorithms in Section 3 and the
features extracted from this data in Section 4. The accelerometer-based bed
occupancy detection is presented in Section 5 along with the classification
strategy in Section 6. The subsequent application to the monitoring of long-
term cough rates is presented in Section 7. Experimental results are shown in
Section 8 and discussed in Section 9. Finally, Section 10 concludes our paper.

##  2 Background

###  2.1 Bed occupancy detection

One approach to the detection of bed occupancy is by means of automated video
analysis [7]. However, video surveillance is intrusive, raises privacy
concerns [8] and our own experience has shown strong resistance from patients
to this type of monitoring.

Another common way of determining bed occupancy is by means of pressure
sensors placed under the mattress [9]. While this is a very direct way of
establishing bed occupancy, it requires specialised and costly equipment.
Furthermore, such pressure sensors have sometimes been found to be sensitive
to factors such as the type of mattress and the weight of the patient, leading
to incorrect measurements [10].

To our knowledge, bed-occupancy detection based on accelerometer signals has
not been reported in the literature before.

###  2.2 Accelerometer-based patient monitoring

Accelerometers are well established as wearable sensors for human physical
activity [11, 12, 13, 14, 15, 16]. For example, accelerometer signals have
been used to successfully classify human movement such as walking, running,
sitting, standing and climbing the stairs with sensitivities and specificities
above 95% [17, 18], even at sampling rates as low as 5 Hz [19]. Similar
success has been achieved when using accelerometer signals to distinguish
between different walking styles [20, 21] and for human fall detection [22].

Recently, wearable consumer devices such as smartphones with on-board tri-
axial accelerometers have been used to classify human activity [23, 24, 25,
26, 27, 28] and vehicular motion [29]. While initial studies used simple
classifiers such as logistic regression (LR) and multi-layer perceptrons
(MLPs), more recently deep neural networks (DNNs) such as convolutional neural
networks (CNNs) have offered better performance in recognising human
activities from the wearable sensor data [30, 31]. Among deep approaches, CNNs
have been shown to be well-suited to real-time human activity recognition
using accelerometer measurements by offering the computational efficiency
required by mobile platforms [32, 33].

##  3 Data

We use a manually annotated dataset of continuous accelerometer measurements
obtained from seven patients to train and evaluate the classifiers used to
detect bed occupancy. All data has been collected as part of this study at a
small 24h TB clinic near Cape Town, South Africa. The clinic accommodates
approximately 10 staff and 30 patients in a number of wards each accommodating
up to four beds. Typically, patients spend between 5 and 15 days at the
clinic, during which time they undergo treatment and are monitored. All
patients for whom data was collected were adult male. No other patient
information was gathered due to the ethical constraints of this study.

###  3.1 Recording setup

The data collection process is shown in Figure 1. Acceleration signals were
captured by the on-board tri-axial accelerometer of a consumer smartphone
(Samsung Galaxy J4) that had been firmly attached to the back of the headboard
of each of the four beds in a ward. Data capture software implemented on this
device continuously monitored the accelerometer signals at a sampling
frequency of $100$ Hz. To reduce the volume of data captured, a simple energy
threshold detector was implemented to exclude long periods with no measured
acceleration. To further reduce the volume of data and also to remove
dependence on the orientation of the smartphone, only the vector magnitude of
the three tri-axial acceleration components was recorded, as indicated in
Equation 1. Here $a_{x}(t)$, $a_{y}(t)$ and $a_{z}(t)$ are the measured tri-
axial accelerations for a particular patient and $t$ is the time from the
start of monitoring. The total period of monitoring varied between 19 and 65
hours for the seven patients in our dataset. Finally, the respective
acceleration signal $a(t)$ was normalised so that its maximum value
corresponded to a value of 1 after completion of the recording for a patient.

$\displaystyle a(t)$ $\displaystyle=$
$\displaystyle\sqrt{a^{2}_{x}(t)+a^{2}_{y}(t)+a^{2}_{z}(t)}$ (1)

In addition to the acceleration signals captured by the smartphone, continuous
simultaneous video recordings were made using two ceiling-mounted cameras, as
shown in Figure 1. These video recordings were used only for the manual
annotation of the captured acceleration signals and hence to provide accurate
ground truth labels in terms of when each monitored bed was occupied.

Figure 1: Data collection set-up. A plastic enclosure housing an inexpensive
consumer smartphone (Samsung Galaxy J4) is firmly attached to the back of the
headboard of each bed and an Android data recording application continuously
monitors the accelerometer signal. To detect the bed occupancy, two ceiling
mounted cameras were used. The position of the beds, cameras and camera view-
angles are shown. Camera 1 monitors Beds 1 and 2, while Camera 2 monitors Beds
3 and 4.

###  3.2 Data Annotation

The accelerometer magnitude signals $a(t)$ were annotated using the ELAN
multimedia software (shown in Figure 2), since this allowed consolidation with
the video data from the ceiling-mounted cameras [34]. In this way the periods
during which each bed was occupied could be accurately labelled, providing
ground truth for our experiments. As every camera can view only two beds, the
labels indicate whether the left bed (L), the right bed (R) or both beds (B)
are occupied.

Figure 2: Annotation in ELAN. The bed on the left is occupied, hence the
annotation label ‘L’.

For a particular patient and therefore a particular acceleration signal
$a(t)$, this ground truth annotation is represented by the signal $n(t)$,
shown in Figure 3.

$n(t)=\quad\begin{cases}1&\text{if bed is occupied at time $t$,}\\\ 0&\text{if
bed is not occupied at time $t$.}\end{cases}$ (2)

We note further that, for all our patients, the bed is initially empty and
hence $n(0)=0$. Furthermore, $n(t)$ switches from 0 to 1 at the instant the
patient begins to get into the bed, and switches from 1 to 0 at the instant
the patient has completely left the bed. These conventions allowed the
accurate determination of these bed occupancy changes from the joint
inspection of the accelerometer and the video footage during manual
annotation.

###  3.3 Compiled dataset

Data was captured from a total of seven patients, each of whom was
continuously monitored for a period of between one and three days, as listed
in Table 1. In total, 249 hours of acceleration and video data was collected.
All of this data was annotated as described in the previous section. Table 1
shows that, of the 249 hours of collected data, patients occupied their beds
for only 95.5 hours. Furthermore, a total of only 104 occupancy changes
(either getting into or getting out of bed) were identified. Thus, despite the
many hours in our dataset, it remains very sparse in terms of bed occupancy
changes. Table 1 summarizes the ground truth dataset. A sample accelerometer
measurements and annotated data indicating a patient’s bed-occupancy pattern
are shown in Figure 3.

Figure 3: Example accelerometer signal $a(t)$ and ground-truth annotation $n(t)$ over a 24-hour period. The figure shows that the patient is often not very active while in the bed, indicated by usually very low accelerometer signal amplitudes.  Table 1: Dataset Summary. Bed numbers and cameras are as indicated in Figure 1. The number of continuous hours of data that were captured and annotated are indicated, as well as the portion of this period during which the bed was occupied. Occupancy changes refers to the total number of times the patient left or entered the bed in the observation period.  Patient | Bed | Camera | Total | Occupied | Occupancy
---|---|---|---|---|---
hours | hours | changes
1 | 2 | 1 | 65 | 23.33 | 18
2 | 3 | 2 | 57 | 14.47 | 20
3 | 4 | 2 | 45 | 11.67 | 18
4 | 4 | 2 | 21 | 9.02 | 10
5 | 1 | 1 | 21 | 15.89 | 12
6 | 3 | 2 | 19 | 9.42 | 14
7 | 2 | 1 | 21 | 11.71 | 12
Total | — | — | 249 | 95.51 | 104

##  4 Feature Extraction

Figure 4: Feature extraction process: Power spectra, RMS, kurtosis, moving
average and crest factor are extracted from the accelerometer measurements
a(t). Number of frames ($C$) is a feature extraction hyperparameter mentioned
in Table 2.

The accelerometer magnitude signal $a(t)$ is split into overlapping frames,
and features are extracted from each frame. The frame length ($\Psi$) as well
as the number of frames ($C$) are hyperparameters that are optimised by
varying the length of frame skip. We calculate the frame skips by dividing the
number of samples by the number of frames and take the next positive integer.
Extracted features include the power spectra, root mean square (RMS), moving
average (MA), kurtosis and crest factor; as they have shown promising results
in our previous studies [35, 4]. For a frame with $\Psi$ samples, the power
spectra has $\frac{\Psi}{2}+1$ coefficients, while RMS, MA, kurtosis and crest
factor are scalar. Hence, a $\frac{\Psi}{2}+5$ dimensional feature vector is
extracted from each frame.

We consider frames with $\Psi=32$ and $64$ samples, corresponding to 320 and
640 millisecond intervals. These frames are shorter than those commonly used
to extract features from audio for training and evaluating machine learning
classifiers [36]. This is because the accelerometer integrated into smartphone
have a lower sampling rate (in our case 100 Hz). Using longer frames was
observed to lead to deteriorated performance, because the acceleration signal
can then no longer be assumed to be approximately stationary.

Finally, we note that classification will generally consider not individual
feature vectors, but a sequence of feature vectors extracted from successive
frames. Thus features will be arranged as a feature matrix of size ($C$,
$\frac{\Psi}{2}+5$), with the features themselves along one dimension and the
frames along the other.

##  5 Bed Occupancy Detection Strategy

Bed occupancy detection based on bed-mounted accelerometer signals is
challenging, because these signals are characterised by bursts of activity (as
the patient either moves or enters or leaves the bed) separated by often very
long intervals of inactivity (Figure 3). These characteristics make, for
example, the direct application of recurrent neural networks ineffective. In
our preliminary experiments we found that even structures designed
specifically with long-term memory in mind, such as long short-term memory
(LSTM) networks, are not able to learn effectively when presented with signals
such as these.

Therefore, we have designed a system that incorporates three interconnected
detectors. The first is trained to recognise specific portions of the
acceleration signal that may be associated with a bed occupancy change, i.e.
the short time interval during which a patient enters or leaves the bed. The
second detector is trained specifically to determine whether the interval
between two such occupancy changes corresponds to a period during which the
bed is occupied or to a period during which it is not occupied. Finally, the
third detector is presented with the outputs of the first two detectors and is
designed to correct falsely detected bed occupancy changes. Figure 5
illustrates the overall structure of our proposed bed-occupancy detector.

Figure 5: Bed Occupancy Detection Process: Features are extracted from the
accelerometer signals for the occupancy-change and occupancy-interval
detection. Using these features, Detector 1 attempts to detect occupancy
changes while occupancy intervals are classified by Detector 2. Detector 1 is
seen to exhibit low specificity but high sensitivity, while Detector 2
displays high specificity but low sensitivity. Thus, Detector 3, the
occupancy-state detector, attempts to correct falsely-detected occupancy
changes based on the decisions by Detectors 1 and 2 , as shown in Figure 6. In
this particular case, there are 6 occupancy changes (the patient went ‘in’ and
‘out’ of the bed 3 times each) i.e. $\mathcal{K}=6$. So, the number of
intervals are: $\mathcal{K}+1=7$.

###  5.1 Occupancy-Change Detector

The bed occupancy-change detector (Detector 1) classifies a five-second
interval ($T_{oc}=5)$ as either containing an occupancy change or not. The
acceleration signal $a(t)$ is divided into successive overlapping five-second
(500 sample) frames, advancing in steps of 500ms (50 samples). From each of
these five-second frames, we extract $C_{OC}$ sub-frames, each containing
$\Psi_{OC}$ samples. The number of samples by which these sub-frames overlap
is determined to ensure that the $C_{OC}$ sub-frames are extracted evenly
across the full five-second interval. For each sub-frame, a feature vector is
extracted, and these vectors are arranged as a feature matrix. Early
experimentation showed that a five-second interval exhibits good performance,
and this quantity was not optimised further. However the sub-frame length
$\Psi_{OC}$ and sub-frame skip (indirectly determined by $C_{OC}$), both of
which influence the dimensionality of this feature matrix, are the
hyperparameters that are optimised.

We consider the instant $\tau_{k}$ at which the $k_{th}$ occupancy change
occurs to be the time at which the annotation signal $n(t)$ switches for the
$k_{th}$ time, where $k=1,2,3\ldots\mathcal{K}$ and where $\mathcal{K}=104$ is
the total number of occupancy changes in our dataset, as listed in Table 1.
Since a bed is always empty at $t=0$, $\tau_{1}$ always indicates a transition
from an empty to an occupied bed. Since in our data the bed is also empty at
the end of the recording period, $\mathcal{K}$ is always an even integer.

Inspection of our data confirmed that the location of the instant $\tau_{k}$
within the five-second interval presented to the classifier should depend on
whether the patient is entering or leaving the bed. When the patient enters
the bed, there is almost no activity before $\tau_{k}$, while when the patient
leaves the bed, there is almost no activity after $\tau_{k}$. Hence, during
classifier training, the five-second interval $N_{k}$ surrounding the time
instant $\tau_{k}$ that the classifier is presented with to make its decision
is specified differently for these two cases, as shown in Equation 3.

$N_{k}=\left\\{\begin{array}[]{lll}t:&\tau_{k}-\frac{T_{oc}}{5}\leq
t\leq\tau_{k}+\frac{4T_{oc}}{5}&\textrm{for}\,k\,\textrm{odd}\\\\[8.53581pt]
t:&\tau_{k}-\frac{4T_{oc}}{5}\leq
t\leq\tau_{k}+\frac{T_{oc}}{5}&\textrm{for}\,k\,\textrm{even}\end{array}\right.$
(3)

Thus, the $N_{k}$ are the time intervals from 1 sec before to 4 sec after the
instants $\tau_{k}$ at which the bed occupancy changes from unoccupied to
occupied and the time intervals from 4 sec before to 1 sec after the instants
$\tau_{k}$ at which the bed occupancy changes from occupied to unoccupied. We
will refer to the $N_{k}$ as “occupancy-changes” to distinguish them from the
“occupancy-intervals” considered in the next section.

Since most of the acceleration signal is not associated with an occupancy
change, the data is highly unbalanced in terms of the two classification
classes. In fact, Table 1 shows that there are only 104 occupancy changes. For
our five-second analysis intervals, this corresponds to a total of only 8.67
minutes of the 249-hour dataset. Since such imbalance can affect machine
learning detrimentally [37, 38], we have applied the synthetic minority over-
sampling technique (SMOTE) to balance data during training [39, 40, 41]. This
technique oversamples the minor class by generating synthetic samples, as an
alternative to for example random oversampling. We have also implemented other
extensions of SMOTE such as borderline-SMOTE [42, 43, 44] and adaptive
synthetic sampling [45]. However, the best results were obtained by using
SMOTE without any modification.

At classification time, the measured acceleration magnitude $a(t)$ is
presented to the occupancy-change detector, which provides a sequence of
hypothesised time instants $\hat{\tau}_{k}$ and associated intervals
$\hat{N}_{k}$ at which the occupancy of the bed is likely to have changed.
Early experimental evaluation revealed that this approach allows occupancy-
change intervals to be identified with high sensitivity (above 99%) but low
specificity. This means that, although most occupancy changes are predicted
correctly, other activities, such as movement of the patient while in the bed,
have also (wrongly) been classified as occupancy changes.

###  5.2 Occupancy-Interval Detector

We now consider the time interval between two consecutive occupancy-changes,
and focus on the task of determining whether this interval is associated with
the bed being occupied or the bed being empty. We will refer to these as
“occupancy-intervals” ($\mathbb{N}_{k}$) to distinguish them from the
“occupancy-changes” ($N_{k}$) considered in the previous section. The
occupancy-intervals $\mathbb{N}_{k}$ between occupancy-changes $N_{k}$ and
$N_{k+1}$ is given by:

$\mathbb{N}_{k}=\left\\{t:N_{k}<t<N_{k+1}\right\\}$ (4)

where $k=0,1,2,3\ldots{\mathcal{K}+1}$ and where $\mathbb{N}_{0}$ and
$N_{\mathcal{K}+1}$ indicate the start and the end of the signal respectively.

Note that since there are $\mathcal{K}$ occupancy changes, there are
$\mathcal{K}+1$ occupancy-intervals. Furthermore, $\mathbb{N}_{0}$ indicates
the time interval before the first occupancy change and in our data always
indicates an initial interval during which the bed is unoccupied, while
$\mathbb{N}_{\mathcal{K}}$ is the interval following the last occupancy
change, during which the bed is also empty.

For classification, we divide each occupancy-interval $\mathbb{N}_{k}$ into
ten-second (1000 sample) non-overlapping frames. From each of these ten-second
frames, we extract $C_{OI}$ sub-frames, each containing $\Psi_{OI}$ samples.
The number of samples by which these sub-frames overlap is determined to
ensure that the sub-frames are extracted evenly across the full ten-second
interval. For each sub-frame, a feature vector is extracted, and these vectors
are arranged as a feature matrix. Finally, the feature matrices extracted from
each ten-second frame in the occupancy-interval $\mathbb{N}_{k}$ are averaged.
In this way, information about the entire occupancy-interval is encoded as a
fixed-dimension feature matrix. This method of feature extraction is the
result of extensive experimentation. In particular, approaches such as the
direct application of LSTMs to features extracted from $\mathbb{N}_{k}$ in a
more conventional way were, for example, not effective.

According to Table 1, there are total 104 occupancy changes, thus there are
105 occupancy-intervals. This means that we generate a dataset containing only
105 feature matrices. This number is small, especially with a view to training
DNNs [46]. Thus, in order to provide justification for deeper architectures,
two shallow classifiers (logistic regression and multilayer perceptron) were
evaluated in addition to the CNN and LSTM for the occupancy-interval detector.

At classification time, the measured acceleration signal $a(t)$ as well as the
hypothesised occupancy-intervals $\hat{\mathbb{N}}_{k}$, which are derived
directly from the hypothesised occupancy-change intervals $\hat{N}_{k}$
provided by Detector 1, are presented to the occupancy-interval detector,
which in turn provides a classification decision
$f_{OI}(\hat{\mathbb{N}_{k}})$ for each occupancy-interval
$\hat{\mathbb{N}}_{k}$ as shown in Equation 5.

$f_{OI}\left(\hat{\mathbb{N}}_{k}\right)=\left\\{\begin{array}[]{lll}1&&\textrm{when
occupied}\\\\[8.53581pt] 0&&\textrm{when unoccupied}\end{array}\right.$ (5)

Early experimental evaluation showed that this approach allows occupancy-
intervals to be identified with high specificity (above 99%) but lower
sensitivity. Periods during which the bed is unoccupied are reliably
identified, but for some patients, who are very quiet when sleeping, an
occupied bed was identified as an empty bed.

The misclassifications by Detector 1 and Detector 2 are addressed by a third
and final component, the occupancy-state detector.

###  5.3 Occupancy-State Detector

As pointed out in the previous two sections, the occupancy-change detector
exhibits high sensitivity but low specificity while the occupancy-interval
detector high specificity but low sensitivity. A third detector, the
occupancy-state detector, corrects some of the resulting errors by considering
the outputs of both the occupancy-change and the occupancy-interval detectors.
The process begins by viewing each occupancy-change $\hat{N}_{k}$ hypothesised
by Detector 1 as a true occupancy change, and labelling all occupancy-
intervals accordingly. This results in a labelling sequence for the occupancy-
intervals that alternates at every hypothesised occupancy change and where the
first interval $\hat{\mathbb{N}}_{0}$ is always assumed to be unoccupied. Now
the hypothesised changes are considered in turn, beginning with the first. In
each case, if the occupancy-intervals to the left and right of a hypothesised
change are the same, indicating a false positive by Detector 1, the
hypothesised occupancy-change is discounted. This process is illustrated in
Figure 6, where a false positive by Detector 1 at $\hat{N}_{2}$ is removed,
thereby associating the accelerometer activity in this interval with patient
movement rather than an occupancy change.

Figure 6: Bed Occupancy Detection Process. (a) The measured acceleration
signal $a(t)$ and its ground-truth annotation $n(t)$. (b) The occupancy
changes $N_{i}$ are hypothesised by the occupancy-change detector (Detector 1)
and labelled as ‘in’ and ‘out’ successively, while the occupancy-interval
detector (Detector 2) decides whether each interval $\mathbb{N}_{i}$ between
these occupancy changes is classified as ‘occupied’ or ‘unoccupied’. (c) the
occupancy-state detector (Detector 3) considers the decisions by Detectors 1
and 2 and reclassifies some occupancy changes asserted by Detector 1 from
‘change’ to ‘activity’, meaning the accelerometer signal was associated with
patient movement in the bed and not with the patient entering or leaving the
bed. (d) This automatically-determined bed occupancy $\hat{n}(t)$ is compared
with the hand-annotated bed occupancy $n(t)$ in order to generate the results
shown in Table 6.

Hence, Detector 3 is based on a fixed decision rule. Experimentation indicated
that it is so far not possible to improve on this simple rule by for example
making Detector 3 a trainable architecture. This may be due to the very small
training set for this detector, which consists of only 104 hypothesised
occupancy changes and 105 occupancy intervals.

##  6 Classification Process

Classification proceeds as follows. First, the accelerometer magnitude signal
$a(t)$ is divided into successive five-second frames overlapping by 1 second
and from which feature matrices are extracted, as described in Section 5.1.
Detector 1, the occupancy-change detector, classifies each such 5-second
frame, and results in a set of time instants $\hat{\tau}_{k}$ and associated
intervals $\hat{N}_{k}$ at which occupancy changes are likely to have occurred
(Figure 6). From these intervals $\hat{N}_{k}$, the corresponding occupancy-
intervals $\hat{\mathbb{N}}_{k}$ are determined, and these are used to extract
a new set of feature matrices as described in Section 5.2. These are presented
to the occupancy-interval detector, which labels each interval
$\hat{\mathbb{N}}_{k}$ as either occupied or unoccupied. Finally, these labels
for the $\hat{\mathbb{N}}_{k}$, together with the intervals $\hat{N}_{k}$
hypothesised by Detector 1, are processed by Detector 3, resulting in a final
set of hypothesised occupancy instants $\tilde{\tau}_{k}$, which allow a bed-
occupancy signal $\hat{n}(t)$ to be determined. These can be compared with the
ground truth annotation signal $n(t)$ in order to determine performance, as
described in Section 6.3.

###  6.1 Classifier Architectures

We have considered four classifier types to implement the bed occupancy
detection strategy described in the previous section. These are logistic
regression (LR), multilayer perceptron (MLP), convolutional neural network
(CNN) and long short-term memory (LSTM) architectures. Of these, the first two
are shallow architectures which have only been used to classifying occupancy-
intervals since in this case the training dataset was especially small.

LR models have been found to outperform other state-of-the-art classifiers
such as classification trees, random forests, artificial neural networks and
support vector machines in some clinical prediction tasks [47, 48, 49]. We
have used gradient descent weight regularisation as well as lasso ($l1$
penalty) and ridge ($l2$ penalty) estimators during training [50, 51]. These
regularisation hyperparameters are optimised during cross-validation, as
described in Section 6.2.

MLP models [52] are capable of learning non-linear relationships and have for
example been shown to be effective when discriminating influenza coughs from
other coughs [53]. MLPs have also been applied to tuberculosis coughs [54] and
to cough detection in general [55, 56]. During training, we have applied
stochastic gradient descent with the inclusion of an $l2$ penalty. This
penalty, along with the number of hidden layers have been considered as
hyperparameters.

CNNs are a deep neural network architecture which is popular especially in
image classification [57]. CNNs have successfully solved complex tasks such as
cough classification [58, 59, 60, 4], face recognition etc [61]. Our CNN
architecture [62, 63] consists of $\alpha_{1}$ 2D convolutional layers with
kernel size $\alpha_{2}$, rectified linear unit (RELU) activation functions, a
dropout rate $\alpha_{3}$ and max-pooling. The convolutional layers are
followed by a dense layer with $\alpha_{4}$ units, also using RELU activation
functions and then another dense layer with 8 units with rectified linear unit
as activation function has been applied. Finally, the network is terminated by
a two-dimensional softmax layer, indicating an occupancy change for Detector 1
and an occupied bed for Detector 2. During training, feature matrices are
presented to the classifier in batches of $\xi_{1}$ for a total of $\xi_{2}$
epochs.

LSTMs are a recurrent neural network (RNN) architecture which has been found
to be effective for the modelling of sequential patterns in data. Originally
suggested in [64], LSTMs have been successfully used in automatic cough
detection and classification in our previous studies [65, 4, 58]. It can also
be used for other sort of acoustic feature detection as well [66, 67]. Our
LSTM architecture [68] uses $\beta_{1}$ LSTM units with RELU activation
functions and a dropout rate $\alpha_{3}$. The LSTM layer are followed by
dense layer with $\alpha_{4}$ units, also using RELU activation functions and
then another dense layer with 8 units and rectified linear unit as activation
function has been applied. Finally, the network is terminated by a two-
dimensional softmax layer, indicating an occupancy change for Detector 1 and
an occupied bed for Detector 2. During training, feature matrices are
presented to the classifier in batches of $\xi_{1}$ for a total of $\xi_{2}$
epochs, where the feature vectors comprising each feature matrix are presented
to the RNN in sequence.

The hyperparameters associated with these classifiers, as listed in Table 3,
were optimised using a leave-one-out cross-validation scheme.

###  6.2 Training and Hyperparameter Optimisation

Table 2: Feature extraction hyperparameters used in feature extraction for occupancy change and occupancy interval detection. Frame lengths are varied between 320 and 640 milliseconds and the number of frames is varied between 20 and 100.  Hyperparameter | Description | Range
---|---|---
$\Psi_{OC}$ | Number of samples per frame used by occupancy-change detector (Detector 1) |  $2^{k}$ where $k=5,6$
$C_{OC}$ | Number of frames in feature matrix for occupancy-change detector (Detector 1) | 20, 50
$\Psi_{OI}$ | Number of samples per frame used by occupancy-interval detector (Detector 2) |  $2^{k}$ where $k=5,6$
$C_{OI}$ | Number of frames in feature matrix for occupancy-interval detector (Detector 2) | 50, 100
Table 3: Classifier hyperparameters, optimised using the leave-one-out cross-validation (Section 6.2)  Hyperparameter | Description | Classifier | Range
---|---|---|---
$\nu_{1}$ | Regularisation strength of penalty ratios | LR |  $10^{i}$ where $i=-7,-6,\ldots,6,7$ $(10^{-7}$ to $10^{7})$
$\nu_{2}$ |  $l1$ penalty ratio | LR | 0 to 1 in steps of 0.05
$\nu_{3}$ |  $l2$ penalty ratio | LR | 0 to 1 in steps of 0.05
$\eta_{1}$ | No. of hidden layers | MLP | 10 to 100 in steps of 10
$\eta_{2}$ |  $l2$ penalty ratio | MLP |  $10^{i}$ where $i=-7,-6,\ldots,6,7$ $(10^{-7}$ to $10^{7})$
$\eta_{3}$ | Stochastic gradient descent | MLP | 0 to 1 in steps of 0.05
$\xi_{1}$ | Batch Size | CNN, LSTM |  $2^{k}$ where $k=6,7,8$
$\xi_{2}$ | No. of epochs | CNN, LSTM | 10 to 200 in steps of 20
$\alpha_{1}$ | No. of Conv filters | CNN |  $3\times 2^{k}$ where $k=3,4,5$
$\alpha_{2}$ | Kernel size | CNN | 2 and 3
$\alpha_{3}$ | Dropout rate | CNN, LSTM | 0.1 to 0.5 in steps of 0.2
$\alpha_{4}$ | Dense layer size | CNN, LSTM |  $2^{k}$ where $k=4,5$
$\beta_{1}$ | LSTM units | LSTM |  $2^{k}$ where $k=6,7,8$
$\beta_{2}$ | Learning rate | LSTM |  $10^{k}$ where $k=-2,-3,-4$

As our dataset contains only seven patients (Table 1), a leave-one-patient-out
cross-validation scheme [69, 70] has been used to train and evaluate all
classifiers. In this scheme, one patient is held out as a test-patient in an
outer loop. Among the remaining six patients, five are used in an inner loop
to train the classifier while the sixth is used as a development set to
optimise the hyperparameters listed in Table 3. The optimised hyperparameters
are used to train the classifier using all six patients in the outer loop
which is then evaluated on the seventh patient, which had been set aside for
independent testing. This procedure is repeated so that all seven patients are
used as as an independent test set in turn. The area under receiver operating
characteristic (AUC) is used to optimise the hyperparameters. Final classifier
performance is determined as the average sensitivity, specificity, accuracy
and AUC over the seven outer-loop test sets.

The combination of hyperparameters for which the highest AUC has been obtained
inside an outer loop, is defined as the ‘best hyperparameters’ in Table 4 and
5.

###  6.3 Evaluation Process

We evaluate the performance achieved by our bed-occupancy detection system by
comparing the true bed occupancy $n(t)$ with the predicted bed occupancy
$\hat{n}(t)$ on a per-sample basis (Figure 6). The actual bed occupancy has
been confirmed by manual annotation, as described in Section 3.2, while
$\hat{n}(t)$ is determined as described at the start of this section. Since
the dataset is imbalanced in terms of the two classes (bed occupied and bed
unoccupied), we evaluate classifier performance primarily in terms of the area
under the curve (AUC) of the receiver operating characteristic (ROC). However,
we also specify specificity, sensitivity and accuracy in our results.

In addition to evaluating the overall performance of the bed-occupancy
detection system, the individual performance of the occupancy-change detector
(Detector 1) and the occupancy-interval detector (Detector 2) are also
evaluated separately using the same method and performance indicators.

##  7 Long-term Cough Monitoring

We now describe how the bed occupancy detection system (developed in this
study) and the cough detection system (developed in our previous work [4]) can
be integrated to allow the long-term cough monitoring of a patient who was
undergoing TB treatment over a period of 14 days. The bed-mounted
accelerometer signal was recorded for this patient, who was not part of the
dataset compiled in Section 3. Furthermore, since the patient in question was
undergoing treatment, the normal laboratory analyses used to assess state of
health were available.

###  7.1 Cough Counting

Figure 7: Threshold based event detection. A simple energy threshold detector
is used to isolate portions of the accelerometer signal that are passed to the
occupancy-change detector (Detector 1).

We have previously developed a system that is able to reliably detect coughs
from the same accelerometer signals $a(t)$ we are using for bed-occupancy
detection in this work [4]. Since the cough detector uses the accelerometer
signal, it is insensitive to the coughs of other patients or visitors. This is
especially useful in a multi-bed ward environment such as the TB clinic at
which we are attempting to accomplish automatic long-term cough monitoring. A
simple threshold-based acoustic event detector, shown in Figure 7, was used
was used to select the portions of the acceleration signal to pass to the
cough detector. This algorithm extracted sections of the accelerometer signal
for which the mean sample amplitude exceeded a small threshold (1% of the
full-scale amplitude) for more than 0.5 seconds. Figure 8 provides a high-
level diagram of the long-term monitoring system.

Figure 8: Long-term cough monitoring. A cough detection system provided the
start and end times of all detected coughs in the accelerometer magnitude
signal $a(t)$. The bed-occupancy detection system provides the start and end
times of all intervals during which the bed is believed to have been occupied.
These two sources of information can be used to calculate a cough rate, which
is the number of coughs per unit time, for a patient on a certain bed, shown
in Figure 10.

###  7.2 Daily Cough Rate

The average daily cough rate (coughs per 24 hour period) is a means of
quantifying how much a patient coughs. It has been postulated that this figure
is related to the state of the patient’s heath, and therefore can be used as a
means of monitoring [3].

$\mathbb{R}=\mathbb{C}\times\frac{\mathbb{B}}{24}$ (6)

Let $\mathbb{C}$ be the number of coughs detected by the cough detector over a
24-hour period and $\mathbb{B}$ the total time (hours) within this same 24h
period that the bed-occupancy detection system believes the patient to have
been present in the bed. Then, the daily cough rate ($\mathbb{R}$) is
determined using Equation 6.

###  7.3 Laboratory Indicators

For the patient whose cough rate we monitored, we also obtained the colony
forming unit (CFU) and time to positivity (TTP) values for the same 14-day
period. These are both indicators routinely used to monitor the effectiveness
of TB treatment.

The colony forming unit (CFU) count is the number of TB bacterial colonies
formed at a certain dilution and it is calculated by Equation 7.

$\text{CFU}=\log_{10}{\frac{\mathcal{P}_{1}+\mathcal{P}_{2}}{2}}\times 2\times
5\times{10}^{\mathcal{D}}$ (7)

The quantities $\mathcal{P}_{1}$ and $\mathcal{P}_{2}$ are the number of
formed TB colonies in every 1 ml for the two plates used during culturing and
$\mathcal{D}$ is the dilution strength, measured in ml [71].

The time to positivity (TTP) is the number of hours taken for the sputum
samples to show signs to being TB positive. When two plates are cultured, the
TPP is calculated as the average:

$\text{TTP}={\frac{\mathcal{H}_{1}+\mathcal{H}_{2}}{2}}$ (8)

where $\mathcal{H}_{1}$ and $\mathcal{H}_{2}$ are the number of hours taken
for TB samples to become positive for the two plates respectively [71].
Generally, a decrease in CFU is reflected as an increase in TPP, and therefore
both can be used as a measure of successful TB treatment [71].

The estimated cost of calculating CFUs is around USD 100 and TTPs is around
USD 90 and requires usually 3 to 4 weeks per patient to receive the results.

##  8 Results

In the following, Sections 8.1, 8.2 and 8.3 will present experimental results
for Detectors 1, 2 and 3 respectively for the dataset described in Section 3.
Then, Section 8.4 presents results for the long-term cough monitoring
described in Section 7.

###  8.1 Detector 1: Occupancy-Change Detection Results

For the occupancy-change classifier (Detector 1), only the two DNN
architectures (CNN and LSTM) were considered. Both alternatives were trained
and evaluated on the data introduced in Section 3 using the nested cross-
validation procedure described in Section 6.2. The two best-performing (in
terms of AUC) systems for each architecture are presented in Table 4. We note
again that the hyperparameters listed in this table were optimised as part of
the nested cross-validation, and that the classification performance
indicators specificity, sensitivity, accuracy and AUC are averages over the
seven outer loops of this process. In addition, the standard deviation of the
AUC, also calculated over the outer loops, is presented and provides and
indication of the robustness of the classifiers to variations in the training
and testing data.

We see that best bed occupancy change classification performance is achieved
by the LSTM when features are extracted using a frame length $\Phi_{OC}=64$
samples (640ms) and extracting $C_{OC}=20$ sub-frames from each five-second
classification frame. This system achieves a mean specificity of 71%, a mean
sensitivity of 99%, a mean accuracy of 85% and a mean AUC of 0.87. We also
see, as already commented in Section 5, that all four systems in Table 4
exhibit a high sensitivity, meaning that very few occupancy-changes are
missed, but a lower specificity, meaning that activities such as movement by
the patient while in bed are sometimes miss-classified as occupancy changes.
Nevertheless, we note that the overall success of Detector 1 in identifying
occupancy changes implies that the accelerometer signal for this type of event
carries some distinguishing patterns that can be used for automatic
classification.

Table 4: Leave-one-patient-out cross-validation results in detecting occupancy-change: The best two performances are shown for each classifier along with the best hyperparameters. The results show high sensitivity, but low specificity.  Classifier | Frame | Seg | Mean | Mean | Mean | Mean | SD | Best
---|---|---|---|---|---|---|---|---
($\Psi_{OC}$) | ($C_{OC}$) | Spec | Sens | Acc | AUC | AUC | Hyperparameters
CNN | 32 | 20 | 69% | 99% | 84% | 0.86 | 0.0172 | $\xi_{1}=2^{7},\xi_{2}=100,\alpha_{1}=24,\alpha_{2}=2,\alpha_{3}=0.3,\alpha_{4}=2^{4}$
64 | 50 | 68% | 99% | 83.5% | 0.85 | 0.0278 | $\xi_{1}=2^{7},\xi_{2}=160,\alpha_{1}=48,\alpha_{2}=2,\alpha_{3}=0.5,\alpha_{4}=2^{5}$
LSTM | 64 | 20 | 71% | 99% | 85% | 0.87 | 0.0179 | $\xi_{1}=2^{8},\xi_{2}=180,\alpha_{3}=0.3,\alpha_{4}=16,\beta_{1}=2^{7},\beta_{2}=10^{-3}$
32 | 50 | 69% | 99% | 84% | 0.86 | 0.0146 | $\xi_{1}=2^{7},\xi_{2}=140,\alpha_{3}=0.3,\alpha_{4}=16,\beta_{1}=2^{7},\beta_{2}=10^{-2}$

###  8.2 Detector 2: Occupancy-Interval Detection Results

For the occupancy-interval classifier (Detector 2), two shallow (LR and MLP)
and two DNN architectures (CNN and LSTM) were considered. All four were
trained and evaluated on the data introduced in Section 3 using the nested
cross-validation procedure described in Section 6.2. The best-performing (in
terms of AUC) two systems for each architecture are presented in Table 5. As
before, the listed hyperparameters were optimised during cross-validation, and
classification performance is indicated by the averages over the seven outer
cross-validation loops.

We see that best classification performance is again achieved by an LSTM, in
this case extracting features using a frame length of $\Phi_{OI}=64$ samples
(640ms) and 50 sub-frames from each ten-second classification frame. This
system achieves a mean specificity of 99%, a mean sensitivity of 85%, a mean
accuracy of 92% and a mean AUC of 0.94. We also see, as already commented in
Section 5, that all eight systems in Table 5 exhibit a high specificity,
meaning that intervals are rarely classified as “occupied” when in fact the
bed was empty, but a lower sensitivity, meaning that in some cases the bed is
classified as unoccupied when in fact it is not because its occupant exhibits
very little movement.

Table 5: Leave-one-patient-out cross-validation results in detecting intervals: The best two results are shown for each classifier along with the best hyperparameters. The results show high specificity, but low sensitivity.  Classifier | Frame | Seg | Mean | Mean | Mean | Mean | SD | Best
---|---|---|---|---|---|---|---|---
($\Psi_{OI}$) | ($C_{OI}$) | Spec | Sens | Acc | AUC | AUC | Hyperparameters
LR | 32 | 100 | 98% | 81% | 89.5% | 0.91 | 0.0371 | $\nu_{1}=10^{-4},\nu_{2}=0.35,\nu_{3}=0.45$
64 | 50 | 98% | 80% | 89% | 0.90 | 0.0295 | $\nu_{1}=10^{-3},\nu_{2}=0.7,\nu_{3}=0.3$
MLP | 64 | 100 | 99% | 82% | 90.5% | 0.92 | 0.0309 | $\eta_{1}=70,\eta_{2}=10^{-2},\eta_{3}=0.55$
32 | 50 | 98% | 81.5% | 90% | 0.91 | 0.0205 | $\eta_{1}=50,\eta_{2}=10^{-5},\eta_{3}=0.2$
CNN | 32 | 100 | 99% | 84% | 91.5% | 0.93 | 0.0249 | $\xi_{1}=2^{8},\xi_{2}=140,\alpha_{1}=24,\alpha_{2}=2,\alpha_{3}=0.3,\alpha_{4}=16$
64 | 100 | 99% | 83% | 91% | 0.92 | 0.0239 | $\xi_{1}=2^{7},\xi_{2}=100,\alpha_{1}=48,\alpha_{2}=3,\alpha_{3}=0.1,\alpha_{4}=2^{4}$
LSTM | 64 | 50 | 99% | 85% | 92% | 0.94 | 0.0288 | $\xi_{1}=2^{8},\xi_{2}=180,\alpha_{3}=0.3,\alpha_{4}=2^{4},\beta_{1}=2^{7},\beta_{2}=10^{-3}$
32 | 100 | 99% | 83% | 91% | 0.93 | 0.0190 | $\xi_{1}=2^{8},\xi_{2}=180,\alpha_{3}=0.1,\alpha_{4}=16,\beta_{1}=2^{8},\beta_{2}=10^{-3}$

###  8.3 Detector 3: Bed Occupancy Detection

As described in Section 5.3, the best performing occupancy-change and
occupancy-interval classifiers from Sections 8.1 and 8.2 are considered by the
occupancy-state classifier (Detector 3) in order to correct some false
positive classification made by Detector 1. The resulting performance when
using either CNN or LSTM classifiers for Detectors 1 and 2 is presented in
Table 6, while Figure 9 shows the ROC curves for the two best systems. The
results in this table reflect the overall per-sample classification
performance of our accelerometer-based bed-occupancy detection system. The
best performance has been achieved by combining the outputs of the two LSTM
classifiers used for Detectors 1 and 2, resulting in an AUC of 0.94, a
specificity of 91.71% and a sensitivity of 94.51%. Hence the simple procedure
implemented by Detector 3 has resulted in an overall system for which both
sensitivity and specificity are high.

Table 6: Final leave-one-patient-out cross-validation results in detecting patient’s bed occupancy: The best two results are shown for each classifier along with the best hyperparameters. The results are reliable as they show both high specificity and sensitivity. The highest AUC of 0.94 has been obtained from a LSTM classifier.  Classifier | Detector 1 | Detector 2 | Mean | Mean | Mean | Mean | SD
---|---|---|---|---|---|---|---
Frame ($\Psi_{OC}$) | Seg ($C_{OC}$) | Frame ($\Psi_{OI}$) | Seg ($C_{OI}$) | Specificity | Sensitivity | Accuracy | AUC | AUC
CNN | 32 | 50 | 64 | 50 | 93.09% | 89.77% | 91.43% | 0.93 | 0.0205
64 | 50 | 32 | 100 | 91.01% | 89.91% | 90.46% | 0.92 | 0.0192
LSTM | 32 | 50 | 64 | 100 | 94.51% | 91.71% | 93.11% | 0.94 | 0.0218
32 | 20 | 64 | 50 | 92.53% | 90.88% | 91.71% | 0.93 | 0.0271

Figure 9: Mean ROC curve for bed occupancy detection, which shows the best
results for LSTM and CNN classifiers. The highest AUC of 0.94 has been
achieved for the LSTM classifier, detailed in Table 6.

###  8.4 Long-term Cough monitoring

The best LSTM-based bed-occupancy detection system has been used to determine
the daily cough rates $\mathbb{R}$ for a new patient over a 14-day period, as
described in Section 7. Figure 10 shows the cough rate for this patient,
together with the CFU and TPP values over the same period. Firstly, we see
that the CFU decreases over time, indicating that the number of colonies
formed in the sample dilution on average decreases with time. We also see that
the TTP increases, over time, showing that the time taken for a TB sample to
become positive is also increasing. Therefore both microbiological indicators
indicate that, in general, TB treatment which the patient was receiving was
successful. Finally, we also see that the daily cough rate decreases over the
same time interval, This suggests that automatic long-term cough monitoring,
such as that implemented by the system we present in this study, may be an
alternative viable means of monitoring the health of patients in a TB clinic.
We note that our observations are also in line with the observations found by
[3], where the cough frequency was measured manually.

Figure 10: Daily cough rate ($\mathbb{R}$), TTP and CFU for a patient
undergoing treatment for TB over a 14 day period. The graphs indicate that
daily cough rate decreases while the TPP increases and CFU decreases over
time, suggesting that long-term cough monitoring system presented in this
study can be a useful mean of monitoring patient’s improvement on TB
treatment.

##  9 Discussion

The results in Section 8 demonstrate that bed-occupancy detection is possible
to high accuracy based on only the signal captured by a bed-mounted
accelerometer. Since cough detection is also possible using this signal, this
allows the cough rate to be accurately determined by allowing periods during
which the patient leaves the bed to be discounted from the calculation. Basing
classification decisions only on the accelerometer signal allows a convenient,
non-intrusive and privacy-preserving form of cough monitoring.

Since the accelerometer is bed-mounted, the system is insensitive to coughs
from persons other than the patient in the bed. Therefore the system is
suited, for example, for a multi-bed ward environment. The results in Section
7 show that, for a patient undergoing standard TB treatment, the cough rate
decreases over a period of 14 days while laboratory indicators such as CFU
counts and TPP indicate that the treatment is effective. Even though we have
shown this for only a single patient and therefore further validation is
necessary, this is promising empirical evidence to suggest that cough rate can
be used as a method of monitoring the effectiveness of treatment for TB
patients, and perhaps also patients with other lung ailments. This could be of
benefit because the proposed system is easier, quicker, less invasive and much
less costly to implement than laboratory analyses.

##  10 Conclusion and Future Work

We have described a machine learning based bed-occupancy detection system that
uses the accelerometer signal captured by a consumer smartphone attached to
the patient’s bed. Such bed-occupancy detection is required to allow the
implementation of automatic long-term cough monitoring using the same
accelerometer signal, since the time which the monitored patient is present in
the bed must be known in order to accurately calculate a cough rate. Using a
bed-mounted sensor is more convenient and less intrusive than wearable
alternatives or video monitoring, and using only acceleration measurements
intrinsically preserves privacy.

For experimental evaluation, we compiled a 249-hour dataset of manually-
labelled acceleration signals gathered from seven patients undergoing
treatment for tuberculosis (TB). Inspection of these acceleration signals
revealed that they are challenging, since they are characterised by brief
activity bursts interspersed with long periods of little or no activity, even
when the bed is occupied. Initial experimentation revealed that recursive
neural architectures, such as long short-term memory (LSTM) networks, which in
other applications often deliver state-of-the-art performance for tasks that
require the modelling of complex sequential data, are ineffective when
presented with the acceleration signals in our dataset. Hence, to process this
signal effectively, we developed three interconnected components. The first,
termed the occupancy-change detector, locates instances in time at which the
occupancy of the bed is likely to have changed as a result of the patient
entering or leaving the bed. The second, termed the occupancy-interval
detector, considers the periods between detected occupancy changes and
classifies them as being associated with either an occupied or an unoccupied
bed. The third and final component, termed the occupancy-state detector, uses
the results of the first two detectors to correct some of the falsely-
identified occupancy changes.

To implement the system, we consider two shallow (liner regression and
multilayer perceptron) and two deep (convolutional neural network (CNN) and
LSTM) neural architectures. We employ nested cross-validation to train,
optimise and evaluate these architectures and find that a system using LSTM
network for both the occupancy-change and the occupancy-interval detectors
achieves the best performance, with an area under the ROC curve (AUC) of 0.94.
For all considered combinations, we observed that the occupancy-change
detector exhibits a high sensitivity but a lower specificity while the
occupancy-interval detector exhibits a high specificity but a lower
sensitivity. Thus, the final occupancy-state detector was able to rectify many
falsely-identified occupancy changes and achieve an overall system exhibiting
both high sensitivity and high specificity.

As a final step, we implemented a complete cough monitoring system by
integrating a previously-developed cough detector, which uses the same
acceleration signal, with our proposed bed-occupancy detection system. The
cough detector provides the time instances of detected coughs, while the bed-
occupancy detector provides the time intervals during which the bed was
occupied. Together, this information can be used to calculate an accurate
estimate of the daily cough rate. We evaluated this cough rate monitor using
acceleration signals gathered over a period of 14 days from a separate patient
undergoing TB treatment. The evolution of the resulting cough rate was
compared with the evolution of the colony forming unit (CFU) counts as well as
the time to positivity (TPP) determined for sputum samples from the same
patient obtained by standard microbiological laboratory analyses. We were able
to show that, as the CFU decreased with time and the TPP increased with time,
indicating that TB treatment was effective, the measured cough rate decreased
with time. This provides empirical evidence indicating that cough monitoring
based on bed-mounted accelerometer measurements may present a quick, non-
invasive, non-intrusive and cost-effective means of monitoring the long-term
recovery of TB patients.

As immediate future work, we aim to apply the presented cough monitoring
system to a larger number of patients undergoing tuberculosis treatment, to
verify whether the link between cough rate and the clinical indicators
remains. We would also like to determine whether accuracy can be improved by
replacing the occupancy-state detector with a trainable architecture. Although
our first attempts at this have not met with success, the extension of our
dataset, which is an ongoing process, may make this possible. Finally, we
would like to experiment with other neural architectures, such as residual
networks (ResNets [72]).

## References

  * [1] Itzhak Pinhas, Avner Halperin, Arkadi Averboukh, Daniel Lange, and Yosef Gross,  “Methods and systems for monitoring patients for clinical episodes,” May 24 2007,  US Patent App. 11/552,872.
  * [2] Gerjo J de Knegt, Laura Dickinson, Henry Pertinez, Dimitrios Evangelopoulos, Timothy D McHugh, Irma AJM Bakker-Woudenberg, Gerry R Davies, and Jurriaan EM de Steenwinkel,  “Assessment of treatment response by colony forming units, time to culture positivity and the molecular bacterial load assay compared in a mouse tuberculosis model,”  Tuberculosis, vol. 105, pp. 113–118, 2017.
  * [3] Alvaro Proaño, Marjory A Bravard, José W López, Gwenyth O Lee, David Bui, Sumona Datta, Germán Comina, Mirko Zimic, Jorge Coronel, Luz Caviedes, et al.,  “Dynamics of cough frequency in adults undergoing treatment for pulmonary tuberculosis,”  Clinical Infectious Diseases, vol. 64, no. 9, pp. 1174–1181, 2017\.
  * [4] Madhurananda Pahar, Igor Miranda, Andreas Diacon, and Thomas Niesler,  “Deep Neural Network based Cough Detection using Bed-mounted Accelerometer Measurements,”  in ICASSP 2021 - 2021 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), 2021, pp. 8002–8006.
  * [5] Yonglin Ren, Richard Werner, Nelem Pazzi, and Azzedine Boukerche,  “Monitoring patients via a secure and mobile healthcare system,”  IEEE Wireless Communications, vol. 17, no. 1, pp. 59–65, 2010.
  * [6] Abdul Kader Mohiuddin,  “Patient Behavior: an extensive review,”  Nurse Care Open Access Journal, vol. 6, no. 3, pp. 76–90, 2019\.
  * [7] Michele Cournan, Benjamin Fusco-Gessick, and Laura Wright,  “Improving patient safety through video monitoring,”  Rehabilitation Nursing, 2016.
  * [8] Pamela T Sanders, Barbara J Cysyk, and Mary A Bare,  “Safety in long-term EEG/video monitoring,”  Journal of Neuroscience Nursing, vol. 28, no. 5, pp. 305–314, 1996\.
  * [9] M Howell Jones, Rafik Goubran, and Frank Knoefel,  “Identifying Movement Onset Times for a Bed-Based Pressure Sensor Array,”  in IEEE International Workshop on Medical Measurement and Applications, 2006. MeMea 2006. IEEE, 2006, pp. 111–114.
  * [10] Matthew Taylor, Theresa Grant, Frank Knoefel, and Rafik Goubran,  “Bed occupancy measurements using under mattress pressure sensors for long term monitoring of community-dwelling older adults,”  in 2013 IEEE International Symposium on Medical Measurements and Applications (MeMeA). IEEE, 2013, pp. 130–134.
  * [11] Henry J Montoye, Richard Washburn, Stephen Servais, Andrew Ertl, John G Webster, and Francis J Nagle,  “Estimation of energy expenditure by a portable accelerometer.,”  Medicine and Science in Sports and Exercise, vol. 15, no. 5, pp. 403–407, 1983.
  * [12] Margarita S Treuth, Kathryn Schmitz, Diane J Catellier, Robert G McMurray, David M Murray, M Joao Almeida, Scott Going, James E Norman, and Russell Pate,  “Defining accelerometer thresholds for activity intensities in adolescent girls,”  Medicine and Science in Sports and Exercise, vol. 36, no. 7, pp. 1259, 2004.
  * [13] Charles E Matthew,  “Calibration of accelerometer output for adults.,”  Medicine and Science in Sports and Exercise, vol. 37, no. 11 Suppl, pp. S512–22, 2005.
  * [14] Stewart G Trost, Kerry L Mciver, and Russell R Pate,  “Conducting accelerometer-based activity assessments in field-based research,”  Medicine and Science in Sports and Exercise, vol. 37, no. 11, pp. S531–S543, 2005.
  * [15] Dianne S Ward, Kelly R Evenson, Amber Vaughn, A Brown Rodgers, and Richard P Troiano,  “Accelerometer use in physical activity: best practices and research recommendations.,”  Medicine and Science in Sports and Exercise, vol. 37, no. 11 Suppl, pp. S582–8, 2005.
  * [16] Stewart G Trost, Paul D Loprinzi, Rebecca Moore, and Karin A Pfeiffer,  “Comparison of accelerometer cut points for predicting activity intensity in youth,”  Medicine and Science in Sports and Exercise, vol. 43, no. 7, pp. 1360–1368, 2011.
  * [17] Carlijn Bouten, Klaas Westerterp, Maarten Verduin, and Jan Janssen,  “Assessment of energy expenditure for physical activity using a triaxial accelerometer,”  Medicine and Science in Sports and Exercise, vol. 26, no. 12, pp. 1516–1523, 1994.
  * [18] MJ Mathie, Branko G Celler, Nigel H Lovell, and ACF Coster,  “Classification of basic daily movements using a triaxial accelerometer,”  Medical and Biological Engineering and Computing, vol. 42, no. 5, pp. 679–687, 2004.
  * [19] Cliff Randell and Henk Muller,  “Context awareness by analysing accelerometer data,”  in Digest of Papers. Fourth International Symposium on Wearable Computers. IEEE, 2000, pp. 175–176.
  * [20] Nishkam Ravi, Nikhil Dandekar, Preetham Mysore, and Michael L Littman,  “Activity recognition from accelerometer data,”  in AAAI, 2005, vol. 5, pp. 1541–1546.
  * [21] Davrondzhon Gafurov, Kirsi Helkala, and Torkjel Søndrol,  “Biometric gait authentication using accelerometer sensor.,”  JCP, vol. 1, no. 7, pp. 51–59, 2006.
  * [22] AK Bourke, JV O’brien, and GM Lyons,  “Evaluation of a threshold-based tri-axial accelerometer fall detection algorithm,”  Gait & Posture, vol. 26, no. 2, pp. 194–199, 2007.
  * [23] Ling Bao and Stephen S Intille,  “Activity recognition from user-annotated acceleration data,”  in International Conference on Pervasive Computing. Springer, 2004, pp. 1–17.
  * [24] Tomas Brezmes, Juan-Luis Gorricho, and Josep Cotrina,  “Activity recognition from accelerometer data on a mobile phone,”  in International Work-Conference on Artificial Neural Networks. Springer, 2009, pp. 796–799.
  * [25] Pierluigi Casale, Oriol Pujol, and Petia Radeva,  “Human activity recognition from accelerometer data using a wearable device,”  in Iberian Conference on Pattern Recognition and Image Analysis. Springer, 2011, pp. 289–296.
  * [26] Jennifer R Kwapisz, Gary M Weiss, and Samuel A Moore,  “Activity recognition using cell phone accelerometers,”  ACM SigKDD Explorations Newsletter, vol. 12, no. 2, pp. 74–82, 2011\.
  * [27] Akram Bayat, Marc Pomplun, and Duc A Tran,  “A study on human activity recognition using accelerometer data from smartphones,”  Procedia Computer Science, vol. 34, pp. 450–457, 2014.
  * [28] Pekka Siirtola and Juha Röning,  “Recognizing human activities user-independently on smartphones based on accelerometer data,”  International Journal of Interactive Multimedia and Artificial Intelligence, vol. 1, no. 5, pp. 38–45, 2012.
  * [29] Samuli Hemminki, Petteri Nurmi, and Sasu Tarkoma,  “Accelerometer-based transportation mode detection on smartphones,”  in Proceedings of the 11th ACM Conference on Embedded Networked Sensor Systems, 2013, pp. 1–14.
  * [30] Licheng Zhang, Xihong Wu, and Dingsheng Luo,  “Recognizing human activities from raw accelerometer data using deep neural networks,”  in 2015 IEEE 14th International Conference on Machine Learning and Applications (ICMLA). IEEE, 2015, pp. 865–870.
  * [31] Song-Mi Lee, Sang Min Yoon, and Heeryon Cho,  “Human activity recognition from accelerometer data using convolutional neural network,”  in 2017 IEEE International Conference on Big Data and Smart Computing (BigComp). IEEE, 2017, pp. 131–134.
  * [32] Andrey Ignatov,  “Real-time human activity recognition from accelerometer data using convolutional neural networks,”  Applied Soft Computing, vol. 62, pp. 915–922, 2018.
  * [33] Mohammed Mehedi Hassan, Md Zia Uddin, Amr Mohamed, and Ahmad Almogren,  “A robust human activity recognition system using smartphone sensors and deep learning,”  Future Generation Computer Systems, vol. 81, pp. 307–313, 2018\.
  * [34] Peter Wittenburg, Hennie Brugman, Albert Russel, Alex Klassmann, and Han Sloetjes,  “ELAN: a professional framework for multimodality research,”  in 5th International Conference on Language Resources and Evaluation (LREC 2006), 2006.
  * [35] Madhurananda Pahar, Igor Miranda, Andreas Diacon, and Thomas Niesler,  “Automatic non-invasive cough detection based on accelerometer and audio signals,”  arXiv preprint arXiv:2109.00103, 2021.
  * [36] Gen Takahashi, Takeshi Yamada, Shoji Makino, and Nobutaka Ono,  “Acoustic scene classification using deep neural network and frame-concatenated acoustic feature,”  Detection and Classification of Acoustic Scenes and Events, 2016\.
  * [37] Jason Van Hulse, Taghi M Khoshgoftaar, and Amri Napolitano,  “Experimental perspectives on learning from imbalanced data,”  in Proceedings of the 24th International Conference on Machine Learning, 2007, pp. 935–942.
  * [38] Bartosz Krawczyk,  “Learning from imbalanced data: open challenges and future directions,”  Progress in Artificial Intelligence, vol. 5, no. 4, pp. 221–232, 2016.
  * [39] Nitesh V Chawla, Kevin W Bowyer, Lawrence O Hall, and W Philip Kegelmeyer,  “SMOTE: synthetic minority over-sampling technique,”  Journal of Artificial Intelligence Research, vol. 16, pp. 321–357, 2002.
  * [40] Guillaume Lemaître, Fernando Nogueira, and Christos K Aridas,  “Imbalanced-learn: A Python toolbox to tackle the curse of imbalanced datasets in machine learning,”  The Journal of Machine Learning Research, vol. 18, no. 1, pp. 559–563, 2017.
  * [41] Anthony Windmon, Mona Minakshi, Pratool Bharti, Sriram Chellappan, Marcia Johansson, Bradlee A Jenkins, and Ponrathi R Athilingam,  “Tussiswatch: A smart-phone system to identify cough episodes as early symptoms of chronic obstructive pulmonary disease and congestive heart failure,”  IEEE Journal of Biomedical and Health Informatics, vol. 23, no. 4, pp. 1566–1573, 2018.
  * [42] R. Blagus and L Lusa,  “SMOTE for high-dimensional class-imbalanced data,”  BMC Bioinformatics, vol. 14, pp. 106, 2013.
  * [43] Hui Han, Wen-Yuan Wang, and Bing-Huan Mao,  “Borderline-SMOTE: a new over-sampling method in imbalanced data sets learning,”  in International Conference on Intelligent Computing. Springer, 2005, pp. 878–887.
  * [44] Hien M Nguyen, Eric W Cooper, and Katsuari Kamei,  “Borderline over-sampling for imbalanced data classification,”  International Journal of Knowledge Engineering and Soft Data Paradigms, vol. 3, no. 1, pp. 4–21, 2011.
  * [45] Haibo He, Yang Bai, Edwardo A Garcia, and Shutao Li,  “Adasyn: Adaptive synthetic sampling approach for imbalanced learning,”  in 2008 IEEE International Joint Conference on Neural Networks (IEEE World Congress on Computational Intelligence). IEEE, 2008, pp. 1322–1328.
  * [46] Jia Pan, Cong Liu, Zhiguo Wang, Yu Hu, and Hui Jiang,  “Investigation of deep neural networks (DNN) for large vocabulary continuous speech recognition: Why DNN surpasses GMMs in acoustic modeling,”  in 2012 8th International Symposium on Chinese Spoken Language Processing. IEEE, 2012, pp. 301–305.
  * [47] Evangelia Christodoulou, Jie Ma, Gary S Collins, Ewout W Steyerberg, Jan Y Verbakel, and Ben Van Calster,  “A systematic review shows no performance benefit of machine learning over logistic regression for clinical prediction models,”  Journal of Clinical Epidemiology, vol. 110, pp. 12–22, 2019.
  * [48] GHR Botha, G Theron, RM Warren, M Klopper, K Dheda, PD Van Helden, and TR Niesler,  “Detection of tuberculosis by automatic cough sound analysis,”  Physiological Measurement, vol. 39, no. 4, pp. 045005, 2018.
  * [49] Saskia Le Cessie and Johannes C Van Houwelingen,  “Ridge estimators in logistic regression,”  Journal of the Royal Statistical Society: Series C (Applied Statistics), vol. 41, no. 1, pp. 191–201, 1992.
  * [50] Yoshimasa Tsuruoka, Jun’ichi Tsujii, and Sophia Ananiadou,  “Stochastic gradient descent training for l1-regularized log-linear models with cumulative penalty,”  in Proceedings of the Joint Conference of the 47th Annual Meeting of the ACL and the 4th International Joint Conference on Natural Language Processing of the AFNLP, 2009, pp. 477–485.
  * [51] Hiroshi Yamashita and Hiroshi Yabe,  “An interior point method with a primal-dual quadratic barrier penalty function for nonlinear optimization,”  SIAM Journal on Optimization, vol. 14, no. 2, pp. 479–499, 2003\.
  * [52] H Taud and JF Mas,  “Multilayer perceptron (MLP),”  in Geomatic Approaches for Modeling Land Change Scenarios, pp. 451–455. Springer, 2018.
  * [53] Lokanath Sarangi, Mihir Narayan Mohanty, and Srikanta Pattanayak,  “Design of MLP based model for analysis of patient suffering from influenza,”  Procedia Computer Science, vol. 92, pp. 396–403, 2016.
  * [54] Brian H Tracey, Germán Comina, Sandra Larson, Marjory Bravard, José W López, and Robert H Gilman,  “Cough detection algorithm for monitoring patient recovery from pulmonary tuberculosis,”  in 2011 Annual International Conference of the IEEE Engineering in Medicine and Biology Society. IEEE, 2011, pp. 6017–6020.
  * [55] Jia-Ming Liu, Mingyu You, Zheng Wang, Guo-Zheng Li, Xianghuai Xu, and Zhongmin Qiu,  “Cough detection using deep neural networks,”  in 2014 IEEE International Conference on Bioinformatics and Biomedicine (BIBM). IEEE, 2014, pp. 560–563.
  * [56] Justice Amoh and Kofi Odame,  “Deepcough: A deep convolutional neural network in a wearable cough detection system,”  in 2015 IEEE Biomedical Circuits and Systems Conference (BioCAS). IEEE, 2015, pp. 1–4.
  * [57] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E Hinton,  “Imagenet classification with deep convolutional neural networks,”  Communications of the ACM, vol. 60, no. 6, pp. 84–90, 2017.
  * [58] Madhurananda Pahar, Marisa Klopper, Robin Warren, and Thomas Niesler,  “COVID-19 cough classification using machine learning and global smartphone recordings,”  Computers in Biology and Medicine, vol. 135, pp. 104572, 2021.
  * [59] Madhurananda Pahar and Leslie S Smith,  “Coding and Decoding Speech using a Biologically Inspired Coding System,”  in 2020 IEEE Symposium Series on Computational Intelligence (SSCI). IEEE, 2020, pp. 3025–3032.
  * [60] Madhurananda Pahar, Marisa Klopper, Byron Reeve, Rob Warren, Grant Theron, and Thomas Niesler,  “Automatic cough classification for tuberculosis screening in a real-world environment,”  Physiological Measurement, vol. 42, no. 10, pp. 105014, oct 2021\.
  * [61] Steve Lawrence, C Lee Giles, Ah Chung Tsoi, and Andrew D Back,  “Face recognition: A convolutional neural-network approach,”  IEEE Transactions on Neural Networks, vol. 8, no. 1, pp. 98–113, 1997.
  * [62] Saad Albawi, Tareq Abed Mohammed, and Saad Al-Zawi,  “Understanding of a convolutional neural network,”  in 2017 International Conference on Engineering and Technology (ICET). IEEE, 2017, pp. 1–6.
  * [63] Xingqun Qi, Tianhui Wang, and Jiaming Liu,  “Comparison of support vector machine and softmax classifiers in computer vision,”  in 2017 Second International Conference on Mechanical, Control and Computer Engineering (ICMCCE). IEEE, 2017, pp. 151–155.
  * [64] Sepp Hochreiter and Jürgen Schmidhuber,  “Long short-term memory,”  Neural Computation, vol. 9, no. 8, pp. 1735–1780, 1997.
  * [65] Igor DS Miranda, Andreas H Diacon, and Thomas R Niesler,  “A comparative study of features for acoustic cough detection using deep architectures,”  in 2019 41st Annual International Conference of the IEEE Engineering in Medicine and Biology Society (EMBC). IEEE, 2019, pp. 2601–2605.
  * [66] Erik Marchi, Fabio Vesperini, Felix Weninger, Florian Eyben, Stefano Squartini, and Björn Schuller,  “Non-linear prediction with LSTM recurrent neural networks for acoustic novelty detection,”  in 2015 International Joint Conference on Neural Networks (IJCNN). IEEE, 2015, pp. 1–7.
  * [67] Justice Amoh and Kofi Odame,  “Deep neural networks for identifying cough sounds,”  IEEE Transactions on Biomedical Circuits and Systems, vol. 10, no. 5, pp. 1003–1011, 2016.
  * [68] Alex Sherstinsky,  “Fundamentals of recurrent neural network (RNN) and long short-term memory (LSTM) network,”  Physica D: Nonlinear Phenomena, vol. 404, pp. 132306, 2020.
  * [69] “Leave-one-out cross-validation,”  in Encyclopedia of Machine Learning, Claude Sammut and Geoffrey I. Webb, Eds., Boston, MA, 2010, pp. 600–601, Springer US.
  * [70] Tzu-Tsung Wong,  “Performance evaluation of classification algorithms by k-fold and leave-one-out cross validation,”  Pattern Recognition, vol. 48, no. 9, pp. 2839–2846, 2015.
  * [71] AH Diacon, JS Maritz, A Venter, PD Van Helden, R Dawson, and PR Donald,  “Time to liquid culture positivity can substitute for colony counting on agar plates in early bactericidal activity studies of antituberculosis agents,”  Clinical Microbiology and Infection, vol. 18, no. 7, pp. 711–717, 2012.
  * [72] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun,  “Deep residual learning for image recognition,”  in Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 2016, pp. 770–778.