Dynamic Programming
• Dynamic Programming is a general algorithm design technique
• It breaks up a problem into a series of overlapping sub-problems ( sub-problem whose results can be reused several times)
• Main idea:- set up a recurrence relating a solution to a larger instance to
solutions of some smaller instances- solve smaller instances once- record solutions in a table - extract solution to the initial instance from that table
Discussed topics
•Assembly-line scheduling
•Partition of Data Sequence
•Route Segmentation and Classification for GPS data
•Longest Common Subsequence (LCS)
Assembly-line scheduling
)]1[,]1[min(][ ,11,22,111 jjj atjfajfjf
Recursive equation:
where f1[j] and f2[j] are the accumulated time cost to reach station S1,j and S2,j
a1,j is the time cost for station S1,j
t2,j-1 is the time cost to change station from S2,j-1 to S1,j
Partition of Data Sequence
Partition of the sequence X into to K non-
overlapping groups with given cost functions
f(xi, xj) so that the total value of the cost
function is minimal:
min),(...),(),( 111 322 Niiii xxfxxfxxf
K
Partition of Data SequenceG(k,n) is cost function for optimal partition of n points into k non-overlapping groups:
k
jjj
iiifnkG
j 11
}{1,min),(
.0;,)1,1(min),( NnnjfjkGnkGnjk
Recursive equation:
Examples: Image QuantizationInput
Quantized
Here, cost function is:
2( , ) ( ) ( )
where ( )
i k j
i k j
f i j n k k q
q n k k
Square Error
Quantize value
Examples: Polygonal Approximation5004 points are approximated by 78 points.Given approximated points M, errors are minimized.Given error ε, number of approximated points are minimized.
Here, cost function is:
2or
( , ) max
{ }
( , )
i j i k j k
i j ki k j
f x x d
f x x d
Examples: Route segmentationSki
0 200 400 600 800 10000
5
10
15
20
25
time
spee
d
estimated segment result
0 1000 2000 3000 40000
1
2
3
4
5
6
time
spee
d
estimated segment result
0 1000 2000 3000 4000 5000 60000
2
4
6
8
10
time
spee
d
estimated segment result
Running and Jogging
Non-movingDivide the routes into several segments byspeed consistencyHere, cost function is:
( , ) ( ) ( )k i k j j if i j v t t
Speed variance Time duration
Frequent Moving type dependency of 1st order HMM
Examples: Route classification
0 10 20 30 40
0.2
0.4
0.6
0.8
1
Speed(km/h)
Pro
bab
ility
BikeRun
WalkStop
Car
Determine the moving type only by speed will cause mis-classification.
0 1000 2000 3000 4000 5000 60000
2
4
6
8
10
12
14
time
speed
estimated segment result
1st order HMM, maximize:
0 1000 2000 3000 4000 5000 60000
2
4
6
8
10
12
14
time
speed
estimated segment result
i 11
( | X , )M
i ii
f P m m
mi : moving type of segment i Xi : feature vector (e.g. speed)
Solve by dynamic programming similar with the Assembly-line scheduling problem
Examples: Route classification (cont.)
Longest Common Subsequence (LCS)
Find a maximum length common subsequence between two sequences.
For instance, Sequence 1: president Sequence 2: providence Its LCS is priden.
president
providence
How to compute LCS?
Let A=a1a2…am and B=b1b2…bn .
len(i, j): the length of an LCS between a1a2…ai and b1b2…bj
With proper initializations, len(i, j) can be computed as follows.
,
. and 0, if)),1(),1,(max(
and 0, if1)1,1(
,0or 0 if0
),(
ji
ji
bajijilenjilen
bajijilen
ji
jilen
i j 0 1 p
2 r
3 o
4 v
5 i
6 d
7 e
8 n
9 c
10 e
0 0 0 0 0 0 0 0 0 0 0 0
1 p 2
0 1 1 1 1 1 1 1 1 1 1
2 r 0 1 2 2 2 2 2 2 2 2 2
3 e 0 1 2 2 2 2 2 3 3 3 3
4 s 0 1 2 2 2 2 2 3 3 3 3
5 i 0 1 2 2 2 3 3 3 3 3 3
6 d 0 1 2 2 2 3 4 4 4 4 4
7 e 0 1 2 2 2 3 4 5 5 5 5
8 n 0 1 2 2 2 3 4 5 6 6 6
9 t 0 1 2 2 2 3 4 5 6 6 6
Running time and memory: O(mn) and O(mn).
i j 0 1 p
2 r
3 o
4 v
5 i
6 d
7 e
8 n
9 c
10 e
0 0 0 0 0 0 0 0 0 0 0 0
1 p 2
0 1 1 1 1 1 1 1 1 1 1
2 r 0 1 2 2 2 2 2 2 2 2 2
3 e 0 1 2 2 2 2 2 3 3 3 3
4 s 0 1 2 2 2 2 2 3 3 3 3
5 i 0 1 2 2 2 3 3 3 3 3 3
6 d 0 1 2 2 2 3 4 4 4 4 4
7 e 0 1 2 2 2 3 4 5 5 5 5
8 n 0 1 2 2 2 3 4 5 6 6 6
9 t 0 1 2 2 2 3 4 5 6 6 6
Output: priden
Time Series Matching using Longest Common Subsequence
0 20 40 60 80 100 120-4
-2
0
2Minimum Bounding Envelope (MBE) for LCSS
0 20 40 60 80 100 120
Point Correspondense, Similarity [=10, =0.3]
= 0.875
delta = time matching region (left & right)
epsilon = spatial matching region (up & down)
Recursive equation: 0 0, 0
( , ) ( 1, 1) 1 0, 0,| | , ( , )
max( ( 1, ), ( , 1))i j i j
i j
len i j len i j i j t t d p p
len i j len i j else
for 0, 0i j
Spatial Data Matching using Longest Common Subsequence
epsilon = spatial matching distance
Recursive equation:0 0, 0
( , ) ( 1, 1) 1 0, 0, ( , )
max( ( 1, ), ( , 1))i j
i j
len i j len i j i j d p p
len i j len i j else
Top Related