Context and context-aware computing
Overview of what context and context-aware computing mean, how systems acquire and use context, modelling and reasoning techniques, architectures and life-cycle, with exam-style examples and checks.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Context-aware computing is used by engineers to make systems adapt to the user's situation without explicit commands. Examples: a smartphone that mutes in a lecture, a wearable that warns when the user is drowsy, or a building control system that lowers lighting when rooms are empty.
Key ideas
Start with definitions. Define each term before using it.
Context — the set of information that can be used to characterize the situation of an entity (person, place, object). Define entity = any physical or virtual thing with state. Context includes location, time, activity, identity, environment, and social situation. State clearly: context is data about situation, not the application itself.
Context information / Context data — raw or processed observations about the environment or entities. Examples: GPS coordinates (raw), inferred activity "walking" (processed).
Context awareness — the ability of a system to sense, interpret, and respond to context. Exact statement: A system is context-aware if it can (1) acquire context information, (2) reason about context to produce higher-level conclusions, and (3) adapt behaviour or presentation based on that context.
Context-aware application / system — an application that implements context awareness as above.
Assumptions often used in university questions
- Sensors provide imperfect observations (noise, delay).
- Context values may be discrete (e.g., {home, work}) or continuous (GPS coordinates, temperature).
- Privacy constraints may limit what context can be collected or stored.
Important taxonomies (define before use):
- Primary context — context directly observed by sensors (e.g., GPS, accelerometer values, ambient light).
- Secondary context — context derived from primary context by processing or fusion (e.g., activity inferred from accelerometer; "in meeting" inferred from calendar + location).
- Sensed context — same as primary context; use consistently in an answer.
Context types (list to memorise): physical (location, movement, temperature), temporal (time, duration), logical (task, activity, calendar), social (nearby people, social graph), device state (battery, network connectivity), environmental (noise level, light), user profile (preferences, disabilities).
Context life-cycle — explain and derive steps (universities like to see this as a sequence):
- Context acquisition — getting data from sensors or sources (draw sensors connected to acquisition module).
- Context pre-processing — cleaning, smoothing, time-syncing sensor data.
- Context representation (modelling) — storing data in a form suitable for reasoning (e.g., key-value, XML/JSON, ontology).
- Context reasoning / inference — deriving high-level facts from low-level data (rule-based, probabilistic, ML, ontology reasoning).
- Context distribution / dissemination — sharing context with components or other systems.
- Context adaptation / actuation — changing application behaviour or controlling actuators.
- Context history / storage — logging for learning or auditing.
When asked to draw: draw a pipeline left-to-right labelled Sensors -> Acquisition -> Pre-processing -> Model Store -> Reasoner -> Policy/Adaptation -> Actuators/Presentation. Add arrows for feedback from Actuators to Sensors (closed-loop). Label sample data at each stage: raw accelerometer -> filtered acceleration -> inferred "running" -> policy: change UI.
Context modelling approaches (define each):
- Key-value models — context as pairs
key:value. Simple, efficient, weak for semantic queries. - Markup models (XML/JSON) — hierarchical, human-readable, interoperable.
- Object-oriented models — context as objects with methods and inheritance.
- Logic-based models — facts and rules in predicate logic; good for explicit inference.
- Ontology-based models — formal semantic models (use OWL/ RDF) that define classes, properties, and relations; enable reasoning with description logics.
Context reasoning techniques (define and state when to use):
- Rule-based reasoning — IF-THEN rules (good for explicit policies, deterministic inference). Assumes rules are complete and conflicts resolved by priority.
- Probabilistic reasoning — Bayesian networks, Hidden Markov Models (use when sensors are noisy and temporal patterns exist). Assumes statistical models and training available.
- Machine learning — classifiers (SVM, decision trees, neural nets) used for activity recognition; requires labelled data.
- Ontology reasoning — uses description logic reasoners to infer subclass relations and consistency. Assumes well-defined ontology.
Design concerns and trade-offs (state plainly):
- Accuracy vs battery (more sensing = better context but drains battery).
- Local reasoning vs cloud (latency/privacy vs compute power).
- Timeliness vs completeness (fast, partial context vs slow, complete).
- Quality of Context (QoC): define and cite attributes such as accuracy/precision, freshness/timeliness, completeness, and confidence/trust; explain how they influence decisions and conflict resolution.
Security and privacy brief note (define terms):
- Privacy — the right of users to control collection and use of their context.
- Anonymisation and access control are common countermeasures. Always mention that context can be sensitive (location, health). Keep this short because other topics cover security in detail.
Formulas
For a programming/representation topic we list the syntax to remember. Each line is one syntax example; then what symbols mean.
context["location"] = "12.9716N,77.5946E" — context is a key-value store; keys are strings, values can be strings, numbers or structured types.
<context><user id="u1"><location lat="12.97" lon="77.59"/></user></context> — XML markup example: attributes lat/lon are floats in degrees.
{ "user": "u1", "activity": "walking", "time": "2025-04-10T09:15:00Z" } — JSON example; use ISO 8601 for time strings.
IF activity == "driving" AND speed > 10 km/h THEN mode = "car" — rule syntax; == is equality, AND is logical conjunction; numeric unit shown.
ontology:Person rdfs:subClassOf ontology:Agent — ontology triple example in RDF/Turtle; use RDF/OWL to state class relations.
P(activity_t | accel_{t-4..t}) — probabilistic classifier notation: probability of activity at time t given accelerometer window. Symbols: P = probability, accel_{t-4..t} = accelerometer samples from t-4 to t.
Worked examples
Example 1 — Rule-based folding: Silent mode in lecture
Problem: Design rules so a phone mutes when user is in a scheduled lecture and inside the lecture room.
Given: Calendar says event "EC Lect" from 10:00–11:00 at location "LH-201". Phone current GPS = coordinates that map to LH-201. Time = 10:05.
Steps:
- Acquire: time=10:05 (system clock), location=GPS -> lat/lon.
- Pre-process: map lat/lon -> place name by geo-fence -> returns "LH-201".
- Represent:
context = { "time": "10:05", "location":"LH-201", "calendar_event": {"title":"EC Lect","start":"10:00","end":"11:00","location":"LH-201"} }. - Reason (rule): IF calendar_event.title contains "Lect" AND time in [start,end] AND location == calendar_event.location THEN set ringtone = silent.
- Adapt: phone sets silent. End.
What to draw: a timeline showing 10:00–11:00, an arrow from calendar to reasoner, an arrow from GPS to geo-fence, and final action on phone UI.
Example 2 — Probabilistic inference: Detecting "user is driving"
Given sensor stream: GPS speed = 45 km/h, accelerometer variance high, Bluetooth connected to car audio.
Model: Use simple Bayesian rule-set (informal): higher prior for driving when speed > 20 km/h and car audio connected.
Steps (numbers illustrative):
- Observations: speed=45 (>20), accel variance=1.2 (high), bluetooth_connected = true.
- Likelihood estimates (assumed): P(speed>20 | driving)=0.95, P(accelVarHigh | driving)=0.8, P(bt_connected | driving)=0.9. Priors: P(driving)=0.1. For not driving we assume complementary likelihoods for illustration: P(speed>20 | not driving)=0.05, P(accelVarHigh | not driving)=0.2, P(bt_connected | not driving)=0.1.
- Use naive Bayes proportional scoring: score_driving = 0.1 * 0.95 * 0.8 * 0.9 = 0.0684. Score_not_driving = 0.9 * 0.05 * 0.2 * 0.1 = 0.0009. Normalise -> P(driving) ≈ 0.987.
- Decision: infer "driving" and adapt UI (no text notifications). Final: user is driving (probability ~0.987).
State assumptions: the numerical likelihoods are example values for illustration; a real system learns these from data.
Example 3 — Trace of context fusion algorithm (small input)
Input: accelerometer samples over 4 timesteps: [0.1, 0.2, 0.15, 1.8] g. Window size = 4.
Algorithm: compute variance; if variance > 0.5 infer "movement", else "stationary".
Steps: mean = (0.1+0.2+0.15+1.8)/4 = 0.5625 g. Variance = ((0.1-0.5625)^2 + (0.2-0.5625)^2 + (0.15-0.5625)^2 + (1.8-0.5625)^2)/4 = compute -> 0.2139... + 0.1314... + 0.1702... + 1.5314... = 2.0469.../4 = 0.5117 g^2. Since 0.5117 > 0.5, infer movement.
Units: accelerometer in g (1 g = 9.81 m/s^2) but working in g for threshold matching sensor API.
Common mistakes
- Ignoring sensor noise: assuming sensor readings are perfect.
- Forgetting to state units (e.g., speed in km/h or m/s) when using numeric thresholds.
- Not describing an architecture diagram clearly (miss labelling acquisition, model, reasoner).
- Using ontology and logic terms without defining them (e.g., saying OWL without saying it's an ontology language).
For your exam
Question types you will see: short definitions (define context, context-awareness), short notes (context lifecycle, modelling approaches), derivations (justify lifecycle steps), design questions (draw architecture and label), numericals (simple probabilistic inference, threshold calculations), and trace problems (run a small rule set on given inputs).
What a full-marks answer must include:
- Clear definitions of bolded terms.
- Assumptions stated explicitly (sensor noise, time formats, units).
- A labelled diagram when asked for architecture or flow (sensors, acquisition, modelling, reasoning, adaptation) and example data flow.
- For reasoning problems: state the reasoning method (rule-based / probabilistic) and show all steps and intermediate values.
- For modelling: name the model type and justify choice (e.g., ontology for semantic queries).
Quick check
- Give one sentence definition of context.
- Name three context types.
- What is the typical next step after context acquisition in the lifecycle?
Answers: 1) Context = information that characterises the situation of an entity. 2) Physical (location), temporal (time), social (nearby people). 3) Context pre-processing (cleaning / smoothing / time-sync).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?