Chapter 1
Trajectory Preprocessing
Wang-Chien Lee John Krumm
Pennsylvania State University Microsoft Research
University Park, PA USA Redmond, WA USA
Location-Based Services
Traffic info Logistics
Mobile Commerce
Navigation
Local weather
Geographical Information
System (GIS)
Emergency service
Tracking
System Model for LBSs
• The locations of tracked moving objects are reported
to the location server via wireless communications.
• The LBS applications submit queries to the server to
retrieve moving object data for analysis or other
application needs.
Trajectories
{< x1, y1, t1>, < x2, y2, t2>, ..., < xN, yN, tN>}
Positioning technologies
• Global positioning system (GPS)
• Network-based (e.g., using cellular or wifi access points)
• Dead-Reckoning (for estimation)
Trajectory Preprocessing
• Problems to solve with trajectories
– Lots of trajectories → lots of data
– Noise complicates analysis and inference
• Employ the data reduction and filtering techniques
– Specialized data compression for trajectories
– Principled filtering techniques
Part 1 - Compression
Performance Metrics
• Trajectory data reduction techniques aims to reduce
trajectory size w/o compromising much precision.
• Performance Metrics
– Processing time
– Compression Rate
– Error Measure
• The distance between a location on the original
trajectory and the corresponding estimated location
on the approximated trajectory is used to measure
the error introduced by data reduction.
– Examples are Perpendicular Euclidean Distance or Time
Synchronized Euclidean Distance.
Illustration of Error Measures
• Perpendicular Euclidean Distance
• Time Synchronized Euclidean Distance
Trajectory Data Reduction
• Classification of Data Reduction Techniques.
– Batched Compression:
• Collect full set of location points and then compress the data set
for transmission to the location server.
• Applications: content sharing sites such as Everytrail and Bikely.
• Techniques include Douglas-Peucker Algorithm, top-down time-
ratio (TD-TR), and Bellman's algorithm.
– On-line Data Reduction
• Selective on-line updates of the locations based on specified
precision requirements.
• Applications: traffic monitoring and fleet management.
• Techniques include Reservoir Sampling, Sliding Window, and Open
Window.
Batch Compression -
Douglas-Peucker (DP) Algorithm
• Preserve directional trends in the approximated
trajectory using the perpendicular Euclidean distance
as the error measure.
1. Replace the original trajectory by an approximate line
segment.
2. If the replacement does not meet the specified error
requirement, it recursively partitions the original problem
into two subproblems by selecting the location point
contributing the most errors as the split point.
3. This process continues until the error between the
approximated trajectory and the original trajectory is below
the specified error threshold.
Illustration of DP Algorithm
• Split at the point with most error.
• Repeat until all the errors < given threshold
Batch Compression -
Top-Down Time-Ratio (TDTR)
and Bellman Algorithms
• DP uses perpendicular Euclidean distance as the error
measure. Also, it’s heuristic based, i.e., no guarantee
that the selected split points are the best choice.
• TDTR uses time synchronized Euclidean distance as
the error measure to take into account the geometric
and temporal properties of object movements.
• Bellman Algorithm employs dynamic programming
technique to ensure that the approximated trajectory
is optimal
– Its computational cost is high.
Joke
The one about the guy who joins a monastery
On-line Compression –
Sliding Window
• Fit the location points in a growing sliding window with a valid
line segment and continue to grow the sliding window until
the approximation error exceeds some error bound.
1. First initialize the first location point of a trajectory as the anchor
point pa and then starts to grow the sliding window
2. When a new location point pi is added to the sliding window, the line
segment pa pi is used to fit all the location points within the sliding
window.
3. As long as the distance errors against the line segment pa pi are
smaller than the user-specified error threshold, the sliding window
continues to grow. Otherwise, the line segment pa pi-1 is included as
part of the approximated trajectory and pi is set as the new anchor
point.
4. The algorithm continues until all the location points in the original
trajectory are visited.
Sliding Window - Illustration
• While the sliding window grows from {p0} to {p0, p1,
p2, p3}, all the errors between fitting line segments
and the original trajectory are not greater than the
specified error threshold.
• When p4 is included, the error for p2 exceeds the
threshold, so p0p3 is included in the approximate
trajectory and p3 is set as the anchor to continue.
Open Window
• Different from the sliding window, choose location
points with the highest error in the sliding window as
the closing point of the approximating line segment
as well as the new anchor point.
• When p4 is included, the error for p2 exceeds the
threshold, so p0p2 is included in the approximate
trajectory and p2 is set as the anchor to continue.
Part 1 Summary
Trajectory Data Compression
• Batch
– Douglas-Peucker (DP)
– Top-Down Time Ratio (TDTR) – time included
– Bellman – dynamic programming
• On-line
– Sliding window
– Open window (variation of sliding window)
Part 2 - Filtering
Walking Path Measured by GPS
500
Goals
• Smooth noise & outliers
450
• Infer higher level values
400 (e.g. speed)
350
300
Y (meters)
250
200 Techniques
• Mean and median
150
• Kalman filter
100 • Particle filter
50
0
0 50 100 150 200 250 300 350 400 450 500
X (meters)
Running Example
outlier
Track a moving person in (x,y) Walking Path Measured by GPS
• 1075 (x,y) measurements 500
• Δ = 1 second outliers (2)
• Manually added outliers 450
400
Notation
350
measurement vector
300
actual location outlier
Y (meters)
outlier
noise 250
𝒛𝑖 = 𝒙𝑖 + 𝒗𝑖
𝑥𝑖 𝑇
200
𝒙𝑖 = 𝑦 = 𝑥𝑖 , 𝑦𝑖
𝑖 start
150
(𝑥)
𝑣𝑖 𝑁 0,4 100
𝒗𝑖 = (𝑦)
~
𝑣𝑖 𝑁 0,4
50 outliers (3)
zero mean 0
0 50 100 150 200 250 300 350 400 450 500
standard deviation = ~4 meters X (meters)
Mean Filter
• Also called “moving average” and “box car filter”
• Apply to x and y measurements separately
Filtered version of this point is mean of points in solid box
zx
• “Causal” filter because it doesn’t look into future
• Causes lag when values change sharply
• Help fix with decaying weights, e.g.
• Sensitive to outliers, i.e. one really bad point can cause mean to take on any value
• Simple and effective (I will not vote to reject your paper if you use this technique)
Mean Filter
Walking Path Measured by GPS Mean Filter
500 500
450 450
400 400
350 350
300 300
Y (meters)
Y (meters)
250 250
200 outlier 200
150 150
100 100
50 50
0 0
0 100 200 300 400 500 0 100 200 300 400 500
X (meters) X (meters)
10 points in each mean
• Outlier has noticeable impact
• If only there were some convenient way to fix this …
Median Filter
Filtered version of this point is mean median of points in solid box
Insensitive to value
zx of, e.g., this point
Median is way less sensitive median (1, 3, 4, 7, 1 x 1010) = 4
to outliners than mean mean (1, 3, 4, 7, 1 x 1010) ≈ 2 x 109
Median Filter
Walking Path Measured by GPS Median Filter
500 500
450
400 400
350
300 300
Y (meters)
Y (meters)
250
200 outlier 200
150
100 100
50
0 0
0 100 200 300 400 500 0 100 200 300 400 500
X (meters) X (meters)
10 points in each median
Outlier has noticeable less impact
Joke
The one about the statisticians who go hunting
Kalman Filter
Assumed trajectory
is parabolic
• Mean and median filters assume smoothness
• Kalman filter adds assumption about trajectory
My favorite book on Kalman filtering
Weight data against Big difference #1: Kalman
assumptions about filter includes (helpful)
system’s dynamics assumptions about
behavior of measured
process
Kalman Filter
Kalman filter separates measured variables from state variables
outlier
Walking Path Measured by GPS
500
450
(𝑥) Running example:
𝑧𝑖 400
Measure: 𝒛𝑖 = measure (x,y) coordinates 350
(𝑦 )
Y (meters)
𝑧𝑖 (noisy) 300
250
200
150
100
𝑥𝑖 50
𝑦𝑖 Running example: 0
0 100 200 300 400 500
Infer state: 𝒙𝑖 = (𝑥)
𝑣𝑖 estimate location and X (meters)
(𝑦 ) velocity (!)
𝑣𝑖 Big difference #2: Kalman
filter can include state
variables that are not
measured directly
Kalman Filter Measurements
Measurement vector is related to state
vector by a matrix multiplication plus noise.
𝒛𝑖 = 𝐻𝑖 𝒙𝑖 + 𝒗𝑖
Running example:
𝑥𝑖
𝑧𝑖
(𝑥) 𝑦𝑖
1 0 0 0 (𝑥)
(𝑦 )
= 𝑣𝑖 + 𝑁 𝟎, 𝑅𝑖
𝑧𝑖 0 1 0 0
(𝑦)
𝑣𝑖
(𝑥) • In this case, measurements are
𝑧𝑖 = 𝑥𝑖 + 𝑁 0, 𝜎𝑟
just noisy copies of actual location
𝑧𝑖
(𝑦 )
= 𝑦𝑖 + 𝑁 0, 𝜎𝑟 • Makes sensor noise explicit, e.g.
GPS has σ of around 4 meters
Kalman Filter Dynamics
Insert a bias for how we think system will change through time
𝒙𝑖 = Φ𝑖−1 𝒙𝑖−1 + 𝑤𝑖−1
𝑥𝑖 𝑥𝑖−1
1 0 ∆𝑡𝑖 0 0
𝑦𝑖 𝑦𝑖−1
(𝑥) 0 1 0 ∆𝑡𝑖 (𝑥)
0
𝑣𝑖 = 𝑣𝑖−1 + 𝑁(0, 𝜎 )
0 0 1 0 𝑠
(𝑦) (𝑦) 𝑁(0, 𝜎𝑠 )
𝑣𝑖 0 0 0 1 𝑣𝑖−1
(𝑥)
𝑥𝑖 = 𝑥𝑖−1 + ∆𝑡𝑖 𝑣𝑖 location is standard straight-line motion
(𝑥) (𝑥)
𝑣𝑖 = 𝑣𝑖−1 + 𝑁(0, 𝜎𝑠 ) velocity changes randomly (because we don’t
have any idea what it actually does)
Kalman Filter Ingredients
1 0 0 0
H matrix: gives measurements for given state
0 1 0 0
𝑁 𝟎, 𝑅𝑖 Measurement noise: sensor noise
1 0 ∆𝑡𝑖 0
0 1 0 ∆𝑡𝑖 φ matrix: gives time dynamics of state
0 0 1 0
0 0 0 1
𝑁 𝟎, 𝑄𝑖 Process noise: uncertainty in dynamics model
Kalman Filter Recipe
(−) (+)
𝒙𝑖 = Φ𝑖−1 𝒙𝑖−1
(−) (+)
𝑇
𝑃𝑖 = Φ𝑖−1 𝑃𝑖−1 Φ𝑖−1 + 𝑄𝑖−1
(−) (−) −1
𝐾𝑖 = 𝑃𝑖 𝐻𝑖𝑇 𝐻𝑖 𝑃𝑖 𝐻𝑖𝑇 + 𝑅𝑖
(+) (−) (−)
𝒙𝑖 = 𝒙𝑖 + 𝐾𝑖 𝒛𝑖 − 𝐻𝑖 𝒙𝑖
(+) (−)
𝑃𝑖 = 𝐼 − 𝐾𝑖 𝐻𝑖 𝑃𝑖
• Just plug in measurements and go Big difference #3: Kalman
• Recursive filter – current time step uses filter gives uncertainty
state and error estimates from previous time estimate in the form of a
step Gaussian covariance matrix
Kalman Filter
Velocity model:
(𝑥) (𝑥)
𝑣𝑖 = 𝑣𝑖−1 + 𝑁(0, 𝜎𝑠 )
Kalman Filter
500
• Hard to pick process noise σs 𝜎_𝑠=6.62 meters/second
• Process noise models our 400
uncertainty in system dynamics
• Here it accounts for fact that 300
Y (meters)
motion is not a straight line
200
100
“Tuning” σs (by trying a bunch of
values) gives better result 0
0 100 200 300 400 500
X (meters)
Particle Filter
Dieter Fox et al.
WiFi tracking in a multi-floor building
• Multiple “particles” as hypotheses
• Particles move based on probabilistic motion model
• Particles live or die based on how well they match sensor data
Particle Filter
Dieter Fox et al.
• Allows multi-modal uncertainty (Kalman is unimodal Gaussian)
• Allows continuous and discrete state variables (e.g. 3rd floor)
• Allows rich dynamic model (e.g. must follow floor plan)
• Can be slow, especially if state vector dimension is too large
(e.g. (x, y, identity, activity, next activity, emotional state, …) )
Particle Filter Ingredients
• z = measurement, x = state, not necessarily same
𝑝 𝒛𝑖 𝒙𝑖 • Probability distribution of a measurement given actual value
• Can be anything, not just Gaussian like Kalman
E.g. measured • But we use Gaussian for running example, just like Kalman
speed (in z) will
be slower if
emotional state
(in x) is “tired”
p(zi|xi)
xi
zi
For running example, measurement
is noisy version of actual value
Particle Filter Ingredients
• Probabilistic dynamics, how state changes through time
𝑝 𝒙𝑖 𝒙𝑖−1 • Can be anything, e.g.
• Tend to go slower up hills
• Avoid left turns
• Attracted to Scandinavian people
• Closed form not necessary
• Just need a dynamic simulation with a noise component
• But we use Gaussian for running example, just like Kalman
xi
random vector
xi-1
Particle Filter Algorithm
Start with N instances of state vector xi(j) , i = 0, j = 1 … N
1. i = i+1
2. Take new measurement zi
3. Propagate particles forward in time with p(xi|xi-1), i.e. generate new,
random hypotheses
4. Compute importance weights wi(j) = p(zi|xi(j)), i.e. how well does
measurement support hypothesis?
5. Normalize importance weights so they sum to 1.0
6. Randomly pick new particles based on importance weights
7. Goto 1
Compute state estimate
• Weighted mean (assumes unimodal)
• Median
Particle Filter
Dieter Fox et al.
WiFi tracking in a multi-floor building
• Multiple “particles” as hypotheses
• Particles move based on probabilistic motion model
• Particles live or die based on how well they match sensor data
Particle Filter Running Example
Measurement model reflects true,
𝑝 𝒛𝑖 𝒙𝑖 simulated measurement noise. Same
as Kalman in this case. Particle Filter
500
p(zi|xi)
400
300
Y (meters)
xi
zi
200
100
Straight line motion with
𝑝 𝒙𝑖 𝒙𝑖−1 random velocity change. Same
as Kalman in this case. 0
0 100 200 300 400 500
(𝑥) location is standard X (meters)
𝑥𝑖 = 𝑥𝑖−1 + ∆𝑡𝑖 𝑣𝑖
straight-line motion
(𝑥) (𝑥) velocity changes randomly
𝑣𝑖 = 𝑣𝑖−1 + 𝑁(0, 𝜎𝑠 ) (because we don’t have
any idea what it actually Sometimes increasing the number of particles helps
does)
Part 2 Summary
• Measurement assumptions
• Mean and median filters
• Kalman filter Walking Path Measured by GPS
• Particle filter 500
450
400
350
300
Y (meters)
250
200
150
100
50
0
0 100 200 300 400 500
X (meters)
End