Activity Recognition Sensor Data Analysis

# Activity Recognition & Sensor Data Analysis

## Introduction & Motivation

Activity Recognition: classify human actions from sensor data. Accelerometer, gyroscope, inertial sensors. Applications: fitness tracking, healthcare, assistive technology.

Motivation: Enable context-aware applications; monitor health.

Applications: Fitness trackers, fall detection, behavior monitoring.

---

## Core Concepts & Theory

### Sensor Features

Acceleration, rotation rate, orientation.

### Temporal Patterns

Sliding windows, time-series features.

### Skeleton Tracking

Joint positions from depth sensors.

### Attention Mechanisms

Focus on relevant time windows.

---

## Mathematical Formulation

Acceleration Magnitude:
$$a = \sqrt{a_x^2 + a_y^2 + a_z^2}$$

Features Over Window:
$$ ext{features} = [ ext{mean}(w), ext{std}(w), ext{max}(w), ext{energy}(w)]$$

Temporal CNN:
$$y = ext{ReLU}(w * x + b)$$

---

## Advanced Theory & Extensions

### Skeleton-Based Action Recognition

Joint-level temporal graphs.

### Two-Stream Graph Convolutional Network

Spatial and temporal streams.

### Attention-Based LSTM

Weighted temporal aggregation.

---

## Computational Considerations

Window processing: O(window_size·features).

Feature extraction: O(data_points).

Classification: O(feature_dim).

---

## Practical Implementation Strategies

### Sensor Calibration

Account for device variations.

### Normalization

Standardize sensor values.

### Segmentation

Identify activity boundaries.

---

## Benchmark Datasets & Evaluation

UCI HAR: Accelerometer + gyroscope activities.

NTU RGB+D: Skeleton-based action recognition.

Kinetics: Large-scale video action dataset.

---

## Key Challenges & Limitations

### Sensor Noise

Noisy accelerometer data.

### Inter-subject Variability

Different people perform actions differently.

### Incomplete Data

Missing sensors or occlusions.

---

## Hyperparameter Tuning

Window size: 1-5 seconds.

Stride: 0.5-2 seconds.

Learning rate: 1e-4 to 1e-3.

---

## Real-World Applications & Case Studies

Fitness Trackers: Activity type detection.

Healthcare: Fall detection, rehabilitation.

Smart Homes: Activity-based automation.

---

## Integration with Other Methods

Activity recognition + anomaly detection for fall alerts; + user profiling for personalization.

---

## Summary & Key Takeaways

Activity Recognition via CNNs and skeleton models enables real-time action classification.

Principles:
1. Sensor features: Acceleration, rotation.
2. Temporal windows: Time-series analysis.
3. CNN architectures: Feature learning.
4. Skeleton tracking: Joint-level modeling.
5. Attention mechanisms: Temporal focus.

---

---

## Appendix: Practical Labs

### Lab 1: Sensor Features

import numpy as np

def extract_sensor_features(sensor_window):
 """Extract features from sensor window"""
 mean = np.mean(sensor_window, axis=0)
 std = np.std(sensor_window, axis=0)
 max_val = np.max(sensor_window, axis=0)
 min_val = np.min(sensor_window, axis=0)
 
 # Magnitude
 magnitude = np.linalg.norm(sensor_window, axis=1)
 energy = np.sum(magnitude ** 2)
 
 features = np.concatenate([mean, std, max_val, min_val, [energy]])
 return features

# Test
np.random.seed(42)
window = np.random.randn(100, 3)

features = extract_sensor_features(window)

assert len(features) == 10, "Correct feature count"
print("✓ Sensor feature extraction working")

if __name__ == "__main__":
 print("Lab 1: SensorFeatures - PASSED")

### Lab 2: Activity Classification

import numpy as np

def classify_activity(sensor_features, classifier_weights):
 """Classify activity from features"""
 # Simple linear classifier
 scores = sensor_features @ classifier_weights
 predicted_activity = np.argmax(scores)
 return predicted_activity

# Test
np.random.seed(42)
features = np.random.randn(10)
weights = np.random.randn(10, 6)

activity = classify_activity(features, weights)

assert 0 <= activity < 6, "Valid activity class"
print("✓ Activity classification working")

if __name__ == "__main__":
 print("Lab 2: ActivityClassification - PASSED")

### Lab 3: Skeleton Joint Angles

import numpy as np

def compute_joint_angles(skeleton_joints):
 """Compute angles between joint vectors"""
 angles = []
 
 # Example: shoulder-elbow-wrist angle
 for i in range(len(skeleton_joints) - 2):
 v1 = skeleton_joints[i] - skeleton_joints[i+1]
 v2 = skeleton_joints[i+2] - skeleton_joints[i+1]
 
 cos_angle = np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2) + 1e-8)
 angle = np.arccos(np.clip(cos_angle, -1, 1))
 angles.append(angle)
 
 return np.array(angles)

# Test
np.random.seed(42)
joints = np.random.randn(15, 3)

angles = compute_joint_angles(joints)

assert len(angles) > 0, "Angles computed"
print("✓ Joint angle computation working")

if __name__ == "__main__":
 print("Lab 3: JointAngles - PASSED")

### Lab 4: Windowed Segmentation

import numpy as np

def segment_activity_windows(data, window_size=100, stride=50):
 """Segment data into sliding windows"""
 windows = []
 
 for i in range(0, len(data) - window_size + 1, stride):
 window = data[i:i+window_size]
 windows.append(window)
 
 return windows

# Test
np.random.seed(42)
data = np.random.randn(500, 3)

windows = segment_activity_windows(data, window_size=100, stride=50)

assert len(windows) > 0, "Windows created"
assert windows[0].shape == (100, 3), "Correct window shape"
print("✓ Windowed segmentation working")

if __name__ == "__main__":
 print("Lab 4: WindowedSegmentation - PASSED")

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account