Lecture 8 · AI4ST

HAR in Smart Home Environments

Binary sensors instead of accelerometers: event-based windowing, discounted counts and mutual information, GRUs and activity images — then activity curves, KL divergence and wandering detection to spot cognitive decline.

⏱ ~50 min 📚 6 sections ✅ 10 MCQ + 2 open-ended 🧩 Bridge between 7b and Q7/Q24 (Lecture 9)
1

Sensing in Smart Homes

Smart homes monitor the high-level activities (ADLs) of residents — crucial for ambient assisted living: monitoring elderly subjects for early symptoms of cognitive decline, emergency monitoring.

Key concept — dense sensing
The most common environmental sensors for smart-home HAR are binary sensors: they generate only two states, ON and OFF. They monitor the resident's interaction with the home environment — opening doors/drawers, presence in locations, appliance usage, sitting, lying on bed.

The binary sensor zoo

🧲

Magnetic

Door/drawer open-close via a magnet: magnet close → OFF (closed), otherwise ON (open). Fridge, closets, medicine drawers…

👁️

PIR (Passive InfraRed)

Detects motion/proximity in areas. Senses motion only — a still user is invisible to it!

🪑

Pressure mats

Detect sitting on a chair or standing up.

😴

Sleep mats

Unobtrusive sleep quality: phases (light, REM), snoring, heart rate.

🔌

Smart plugs

Detailed power usage (Lecture 6!) — but thresholded into binary ON/OFF appliance usage.

The raw output is a binary sensors log: timestamped lines like 2010-11-04 05:43:45 M003 ON — sensor ID + state change.

Enriching the picture

  • Indoor localization (Lecture 5): binary sensors sit in fixed positions, are not everywhere, and cannot identify the resident — localization gives richer position/trajectory context. Drawback: the resident must wear a device.
  • Mobile/wearables (Lecture 7b): alone they can't capture complex high-level activities, but combined with environmental sensors they add gestures and posture; some applications (e.g., fall detection) rely mainly on wearables.
  • Audio/video: possible context sources, but perceived as too privacy-intrusive (especially by elderly subjects) — not considered in this course.
2

Segmentation

Binary environmental sensors behave very differently from inertial sensors — and that changes how we window the stream.

Time-based windowing

  • Fixed time sliding windows: simple, efficient, great for continuous-value sensors (accelerometer — Lecture 7b)
  • Problem here: binary sensors have no fixed sampling rate → event distribution across windows is inconsistent
  • Many windows may contain no events at all when the subject is idle

Event-based windowing

  • Each window contains a fixed number of sensor events; the time interval covered is variable
  • The number of events is a parameter requiring proper tuning
  • Why better: events are dense during activities, sparse/absent in silent periods → avoids unrepresentative windows
3

Handcrafted Features

Basic feature extraction

Given a window of the latest k sensor events, build a fixed-dimensional feature vector with: timestamp of the first event, timestamp of the last event, temporal span of the window, and the activation count per sensor event type.

Problems of the basic approach
In event-based segmentation there may be significant time lags between consecutive events — temporally distant events shouldn't count as part of the same activity, so equal importance per event is wrong. And during transitions, one window may mix events of two different activities.

Classify the last event

Common strategy: each time a sensor event occurs, create a window with it and the previous k−1 events as context; the ground truth is the activity performed on the last event. This is a sliding window shifting by a single event — it also improves real-time recognition.

Time-dependency features — the discounted count

C(i, j) = exp( −χ (ti − tk) )
  • Each activation of sensor j is weighted by its time distance from the latest event in the window, with temporal decay rate χ; the feature for sensor type j is the sum of its contributions.
  • χ too low → temporally distant events impact the recognition rate. χ too high → even close events are considered unimportant. The trade-off is found empirically.

Sensor-dependency features — Mutual Information

  • During transitions, a window may contain temporally close events that are poorly related. Solution: a Mutual Information matrix computed on the training set — MI(i, j) is the chance of sensor events i and j occurring consecutively in the stream.
  • The MI w.r.t. the last event weights the activation count (like time dependency does). Drawback: the matrix may overfit the training set. Sensor and time dependency can be combined.

Past activities as features

Previously recognized activities hint at the current one (washing dishes likely follows eating) → the classifier's outputs on previous windows can become extra features. Not trivial: past classifications may be wrong, so their confidence should be used.

ThinkA window holds 20 events: 18 kitchen events from 9:00–9:06, then 2 bathroom events at 11:30. With a plain activation count, what goes wrong when classifying the activity at 11:30 — and which feature fixes it?
Answer: The plain count gives the 18 stale kitchen events equal importance as the 2 fresh bathroom events, so the window looks like "cooking" even though the resident moved on hours ago. The discounted count C(i,j)=exp(−χ(ti−tk)) fixes it: events 2.5 hours older than the last event get an exponentially tiny weight, so the recent bathroom events dominate the feature vector — as they should.
4

Automatic Feature Extraction

Deep models want to generate embeddings from raw data, and they usually require fixed-size input — so we are back to time-based segmentation, and we must encode binary events as time series.

Three encodings of sensor events

EncodingWhat gets a 1
Raw dataAt each instant of the window (e.g., each second), 1 if the sensor event is active, 0 otherwise
Change point1 only at the instants where the sensor's status changes (e.g., ON → OFF)
Last-firedAt each instant, 1 only for the latest sensor event that fired

Multiple encodings can be combined by creating more than one time series per sensor.

Models

  • LSTMs: stacked LSTM layers over the encoded temporal data, flattened into a dense classifier (Lecture 3!).
  • LSTM-CNN: 1D CNN with ReLU + pooling first, LSTM after — the same hybrid logic as Lecture 7b.
  • CNNs with image representation: windows become activity images — a binary matrix where the x-axis encodes time (with a chosen granularity, e.g., 1 cell = 1 second), each row is a sensor, and white pixels mark the instants where that sensor was active. A DCNN classifies the images (eating vs work vs sleeping look visually different!).

GRU — the small-data workhorse

Why GRU here?

  • With small datasets LSTM may overfit → GRUs often preferred in this domain
  • A light LSTM: only two gates and one memory (the long-term one, which is also the cell's output)
  • Faster to train, less overfitting on small datasets
  • Not adequate for long sequences

The two gates

  • Reset gate: determines the % of long-term memory to forget based on the input
  • Update gate: determines how to combine the input and the long-term memory to generate the output
  • Compare with LSTM (Lecture 3): three gates and two memories (cell state + hidden state)
5

Detecting Behavioral Changes

Why recognize ADLs at all? Analyzing behavior long-term can reveal significant changes in activity execution — possible early indicators of cognitive decline.

Activity curves

  • An activity curve models an individual's generalized activity routine, at different time granularities (daily, weekly, monthly).
  • How to build: segment an observation period into equal-size consecutive time windows and define a probability distribution over activities for each window (e.g., 1:00–2:00 AM: Sleep 0.95, Bed-to-toilet 0.05).
  • Aggregated activity curves average distributions over months of data (e.g., at 5-minute intervals).

Comparing routines — KL divergence

DKL(D₁ ∥ D₂) = Σᵢ d₁,ᵢ · log( d₁,ᵢ / d₂,ᵢ )
  • Changes are detected by computing the distance between probability distributions: a high distance may indicate a behavioral change (e.g., year-1 routine vs year-2 routine).
  • KL divergence is not symmetric → use the symmetric version: SDKL(D₁ ∥ D₂) = DKL(D₁ ∥ D₂) + DKL(D₂ ∥ D₁).
  • Two whole activity curves are compared by summing SDKL over all time intervals covered by the curve.
Temporal context matters
The same subject behaves differently by temporal context (short meals on weekdays, longer in weekends) — "normal behavior" must account for it. A hierarchical model builds normal-behavior models at fine granularity (e.g., each day) and groups them into larger ones (working days, weekends…).
6

Wandering Behavior

One symptom of cognitive decline is wandering: moving around aimlessly or without a clear purpose, often in repetitive patterns — usually characterized by loops in the trajectories.

Locomotion categorization

PatternDefinition
DirectA single straightforward path to a destination, not diverging significantly from the most efficient path
PacingAt least three consecutive repeated back-and-forth movements between two locations
LappingA circular repeated movement across at least 3 distinct points, repeated at least twice
RandomAn aimless movement across numerous locations, which is not direct

Where do trajectories come from?

  • Smart-home sensors: environmental sensors have fixed positions → map each to relative (x, y) coordinates; a sequence of triggered events yields a sequence of timestamped positions — an approximated trajectory.
  • Indoor localization (Lecture 5): periodically compute the position of a user wearing a tag (e.g., BLE anchors).

Detecting loops

Sequence of positions Find sub-sequences (trajectories) Algebraic sum of points ≈ 0 (within ε)? Loop → wandering
  • Beyond finding loops, clinically relevant wandering also considers: the loop's area, length, the relative coordinates of its centroid, and the time taken to walk it.
  • Supervised learning approaches classify the cognitive status from trajectories labeled with the subject's status (healthy, mild cognitive impairment, cognitively impaired).
ThinkAn elderly resident walks kitchen → corridor → living room → corridor → kitchen → corridor → living room… repeatedly. Is this pacing or lapping, and what would the algebraic-sum loop detector say?
Answer: Going back and forth between two endpoints (kitchen ↔ living room through the corridor) repeated ≥3 times is pacing — lapping would require a circular route across ≥3 distinct points repeated at least twice. The loop detector would still fire: each round trip returns to the starting point, so the displacement vectors of the sub-sequence sum to ≈ 0 (within ε), flagging a wandering segment. Its features (small area, elongated shape, centroid in the corridor, short walk time) then help the supervised classifier assess the cognitive status.

Final Quiz — Exam Style

10 MCQs + 2 open-ended in the simulation's style. (No simulation question targets Lecture 8 directly — but this lecture's smart-home setting is exactly where Q7 and the open-ended Q24 live, coming in Lecture 9.)

1
What is the key limitation of PIR sensors in smart-home HAR?
AThey can only be installed on doors and drawers
BThey only sense motion, so a still user goes undetected
CThey require the resident to wear a dedicated tag
DThey emit infrared light that disturbs other sensors
B — PIR detects human motion/proximity in specific areas; if the user is still, the sensor cannot reveal their presence. (A describes magnetic sensors; C is the drawback of indoor localization; PIR is passive, it emits nothing.)
2
Why is time-based windowing often a poor choice for binary environmental sensors?
ABecause binary sensors produce too many events per second
BBecause fixed windows cannot be implemented efficiently
CBecause the clocks of binary sensors cannot be synchronized
DBecause there is no fixed sampling rate, so windows are inconsistent
D — binary sensors fire only on interactions: the distribution of events across fixed time windows is inconsistent, and many windows contain no events at all during idle periods. (Time windows work well for continuous-rate sensors like accelerometers — Lecture 7b.)
3
In event-based windowing, what characterizes each window?
AA fixed number of sensor events over a variable time interval
BA fixed time interval containing a variable number of events
CA variable number of events and a variable time interval
DA fixed number of events from one single sensor type
A — the window holds a fixed number of events (a parameter to tune), while its temporal extent varies. Events are dense during activities and sparse in silence, so this avoids the unrepresentative windows of time-based segmentation. B describes time-based windowing.
4
When classifying with event-based windows, which activity is used as the window's ground truth?
AThe activity prevalent across the whole window
BThe activity performed on the first event
CThe activity performed on the last event
DThe most frequent activity in the training set
C — many methods classify the activity associated with the latest sensor event, using the past k−1 events as context. The window slides by a single event, which also improves real-time recognition. (A — "prevalent activity" — is the labeling rule for time-based windows in Lecture 7b: a classic exam trap!)
5
In the discounted count C(i,j) = exp(−χ(tᵢ−tₖ)), what happens if χ is too high?
ATemporally distant events impact the recognition rate
BEven temporally close events are treated as unimportant
CThe feature value grows exponentially with the window size
DAll the events receive exactly the same weight
B — a high decay rate χ makes the exponential drop so fast that even events close to the last one get near-zero weight. χ too low is the opposite problem (A): distant events still influence classification. The trade-off is found empirically.
6
What does the Mutual Information matrix used for sensor-dependency features encode?
AThe physical distance between each pair of sensors in the home
BThe correlation between each sensor and each target activity
CThe average time lag between activations of two sensors
DThe chance of two sensor events occurring consecutively in the stream
D — MI(i,j) is computed from the training set as the chance that events of type i and j occur consecutively. It weights the activation count w.r.t. the last event, mitigating transition windows with poorly related events. Drawback: the matrix may overfit the training set; it can be combined with time dependency.
7
In the last-fired encoding of binary sensor events for deep models, what is encoded with 1?
AOnly the latest sensor event, at each time instant
BEvery instant in which a sensor event is active
COnly the instants where a sensor's status changes
DOnly the first sensor event of each time window
A — last-fired: at each time instant, only the latest sensor event that fired is 1. B is the raw encoding; C is the change point encoding. Multiple encodings can be combined by creating more than one time series per sensor.
8
Why are GRUs sometimes preferred over LSTMs for smart-home HAR?
AThey capture much longer sequences than LSTMs
BThey have more gates, giving finer memory control
CThey train faster and overfit less on small datasets
DThey process the input both forwards and backwards
C — smart-home datasets are small and LSTMs may overfit. The GRU is a light LSTM: only two gates (reset = % of long-term memory to forget; update = how to combine input and memory into the output) and one memory. Faster, less overfitting — but not adequate for long sequences (A is exactly wrong). D describes BiLSTM.
9
When comparing two activity curves to detect behavioral changes, why is the symmetric KL divergence needed?
ABecause activity curves always contain negative probabilities
BBecause the standard formula only works on two activities
CBecause it is much faster to compute on long observation periods
DBecause the standard KL divergence is not symmetric
D — DKL(D₁∥D₂) ≠ DKL(D₂∥D₁), so differences are not reflected symmetrically; the fix is SDKL = DKL(D₁∥D₂) + DKL(D₂∥D₁). Two curves are compared by summing SDKL over all the time intervals; a high distance may indicate a behavioral change (possible early indicator of cognitive decline).
10
According to the locomotion categorization, what defines lapping?
AAt least three repeated back-and-forth movements between two locations
BA circular movement across at least 3 distinct points, repeated at least twice
CAn aimless movement across numerous locations that is not direct
DA single straightforward path that follows the most efficient route
B — lapping is circular and crosses ≥3 distinct points, repeated at least twice. A is pacing (two locations), C is random, D is direct. Loops are detected when the algebraic sum of a sub-sequence's points is ≈ 0 within ε; loop area, length, centroid and walking time then feed supervised classifiers of cognitive status.
11
Open-ended · Pre-processing smart-home sensor data
a) Why is time-based windowing problematic for binary environmental sensors, and how does event-based windowing address this? Which labeling strategy is commonly used?
b) Describe time-dependency and sensor-dependency features: which problems do they solve and what are their parameters/limits?
Model answer

a) Binary sensors generate events only when the resident interacts with the environment: there is no fixed sampling rate, so with fixed time windows the distribution of events is inconsistent, and many windows contain no events during idle periods. Event-based windowing segments the stream into windows with a fixed number k of sensor events (a parameter to tune) covering a variable time interval: events are dense while activities are performed and sparse otherwise, avoiding unrepresentative windows. Most methods build one window per incoming event (the event plus the previous k−1 as context) and use as ground truth the activity performed on the last event — a single-event sliding window that also benefits real-time recognition.

b) Time dependency: in event-based windows there can be large time lags between consecutive events, so equal importance per event is wrong. The activation count becomes a discounted count C(i,j) = exp(−χ(tᵢ−tₖ)): each activation of sensor j is weighted by its temporal distance from the latest event, with decay rate χ; the feature is the sum of the contributions. χ too low → distant events still influence recognition; χ too high → even close events are deemed unimportant; tuned empirically. Sensor dependency: transition windows may contain temporally close but poorly related events. A Mutual Information matrix, computed on the training set as the chance of two event types occurring consecutively, weights the activation count w.r.t. the last event. Limit: the MI matrix may overfit the training set. The two weightings can be combined; additionally, the classifier's outputs on previous windows ("past activities") can be used as features, weighted by their confidence since they may be wrong.

12
Open-ended · Long-term behavior analysis
a) What is an activity curve, how is it built, and how can significant behavioral changes be detected from activity curves?
b) What is wandering, which locomotion patterns exist, and how can wandering be detected from smart-home trajectories?
Model answer

a) An activity curve models an individual's generalized activity routine at a given time granularity (daily, weekly, monthly). It is built by segmenting an observation period into equal-size consecutive time windows and defining, for each window, a probability distribution over the activities (aggregated over the observation period). Significant routine changes — possible early indicators of cognitive decline — are detected by computing the distance between probability distributions: the KL divergence DKL(D₁∥D₂) = Σ d₁,ᵢ log(d₁,ᵢ/d₂,ᵢ). Since KL is not symmetric, the symmetric version SDKL = DKL(D₁∥D₂)+DKL(D₂∥D₁) is used, and two curves are compared by summing SDKL over all time intervals; a high distance may indicate a behavioral change. Because behavior depends on temporal context (weekday vs weekend), normal-behavior models are built at fine granularity and grouped hierarchically (working days, weekends…).

b) Wandering — a symptom of cognitive decline — is the tendency to move around aimlessly or without clear purpose, often in repetitive/looping patterns, characterized by loops in trajectories. Locomotion categories: direct (single efficient path), pacing (≥3 consecutive back-and-forth movements between two locations), lapping (circular movement across ≥3 distinct points repeated at least twice), random (aimless, non-direct movement across many locations). Trajectories come from environmental sensors mapped to fixed (x,y) coordinates (sequence of triggered events → approximated trajectory) or from indoor localization with a wearable tag. Loop detection: find sub-sequences whose algebraic sum of points is ≈ 0 within an approximation error ε → a loop, i.e., a wandering segment. Clinically relevant features — loop area, length, centroid coordinates, walking time — feed supervised classifiers of cognitive status (healthy, mild cognitive impairment, cognitively impaired).

0/10
MCQ score 0/10