Exact Algorithms for Partial Curve Matching via the Frйchet Distance∗

Exact Algorithms for Partial Curve Matching via the Fréchet Distance ∗
Kevin Buchin
†
Maike Buchin†
Yusu Wang
‡
Alt and Godau [4] presented an algorithm to compute
the Fréchet distance between two polygonal curves with
n and m vertices, respectively, in O(mn log(mn)) time.
An Ω((m + n) log(m + n)) lower bound for the decision
problem in the algebraic computation tree model is
known [12]. Efficient approximation algorithms have
been developed for special families of curves [7, 8].
However, so far, no algorithm, exact or approximate,
with running time o(nm) is known for general curves.
Where the Fréchet distance falls short is when there
are outliers or when the two curves share only partial
similarity. An interesting recent work in [19] combined
time-warping to compute an integral (summed) version
of the Fréchet distance, which can “smooth out” the
impact of some outliers. Properties of different types
of summed Fréchet distance were also studied in [14].
However, summed versions do not fully resolve the issue
of
partial similarity, especially when significant parts of
1 Introduction
the curves are dissimilar. To this end, we investigate the
Measuring similarity between curves is a fundamental partial curve matching problem, where given a threshold
problem that appears in many fields, including com- δ, we wish to find the best matching such that the
puter graphics, pattern recognition, geographic infor- largest possible fraction of two input curves are matched
mation systems, and structural biology. A natural mea- within (Fréchet) distance δ.
sure of curve similarity is the Fréchet distance. IntuPartial similarity between curves has previitively, imagine that a dog and its handler are walking ously been measured by partial similarity between
on their respective curves with a leash between them. their vertices, using the popular Hausdorff distance
Both can control their speed, but they can only go for- [15, 22], or (variants of) the RMSD (root-meanward. The Fréchet distance of these two curves is the square-deviation) distance. The latter is widely
minimal length of a leash necessary for the dog and used in communities such as structural biology [25],
the handler to move from the starting points of the two which treats a curve as an ordered set of points.
curves to the endpoints. The Fréchet distance takes the Since only vertices are considered in such discrete
order between points along the curves into considera- measures, they may sometimes fail to reflect simtion, making it a better measure of similarity for curves ilarity. For example, the two curves in the right
than alternatives such as the Hausdorff distance [5, 7]. figure are similar, but have large distance between their
The Fréchet distance and its variants have been vertices (due to the long edges). In this paper, we aim to
widely used in many applications [9, 10, 23, 24, 26, 28]. develop a continuous partial similarity measure, where
every point in the polygonal curve is considered.
∗ Research by the first two authors were supported by the
Alt and Godau [4] considered one natural continuNetherlands’ Organisation for Scientific Research (NWO) under ous partial similarity measure by computing the Fréchet
BRICKS/FOCUS project no. 642.065.503. Research by the last
distance between a single consecutive piece of subcurve
author was supported in part by National Science Foundation
of
P and another curve Q, and presented an efficient
under grants CCF-0747082 and DBI-0750891, and by Department
O(mn log(mn)) algorithm to solve the decision-version
of Energy under grant DE-FG02-06ER25735.
† Dept. of Information and Comp. Sci., Utrecht Univ., Netherproblem, given an error threshold δ. However, their
lands; {buchin,maike}@cs.uu.nl.
measure
only allows to have outliers in one of the input
‡ Dept. of Comp. Sci. and Engineering, The Ohio State Univ,
curve, and more importantly, it does not allow outliers
Abstract
Curve matching is a fundamental problem that occurs in
many applications. In this paper, we study the problem
of measuring partial similarity between curves. Specifically,
given two curves, we wish to maximize the total length
of subcurves that are close to each other, where closeness
is measured by the Fréchet distance, a common distance
measure for curves. The resulting maximal length is called
the partial Fréchet similarity between the two input curves.
Given two polygonal curves P and Q in IRd of size m
and n, respectively, we present the first exact algorithm
that runs in polynomial time to compute Fδ (P, Q), the
partial Fréchet similarity between P and Q, under the L1
and L∞ norms. Specifically, we formulate the problem of
computing Fδ (P, Q) as a longest path problem, and solve
it in O(mn(m + n) log(mn)) time, under the L1 or L∞
norm, using a “shortest-path map” type decomposition.
To the best of our knowledge, this is the first paper to
study this natural definition of partial curve similarity in the
continuous setting (with all points in the curve considered),
and present a polynomial-time exact algorithm for it.
Columbus, OH 43016; [email protected].
appearing in different (non-consecutive) locations along
the input curve. Algorithms for clustering subcurves using the Fréchet distance have been considered [11] but
also these algorithms do not allow for outliers. In many
applications, such as in structural biology, proteins may
be similar only in several key locations, potentially corresponding to functional sites. Hence it is important to
capture all pieces of matching subcurves. See the left
figure for an example where we wish to capture both
pairs of matching subcurves
(thick subcurves in the figure).
We aim to develop a more genδ
eral partial similarity measure
for curves.
Other related work includes minimizing the Fréchet
distance under various classes of transformations [6, 17,
31], extending it to graphs [3, 9], to piecewise smooth
curves [29], to simple polygons [13], to surfaces [2], and
to more general metric spaces [16, 18]. It was also
used in high-dimensional approximate nearest-neighbor
search [21], curve simplification [1] and morphing [20].
Our results. Currently, continuous partial curve similarity, though important, has not been extensively studied. Previous measures have limitations in handling
outliers. In this paper, we introduce a natural continuous partial curve similarity measure that allows general types of outliers, and develop an exact algorithm to
compute it. Specifically, given a distance threshold δ, let
Fδ (P, Q) denote the partial Fréchet similarity between
two polygonal curves P and Q, which is the total length
of longest subcurves of P and Q that are matched with
Fréchet distance at most δ (a formal definition will be
introduced shortly). The Fréchet distance can be measured under any Lp norm, and we consider the L1 and
L∞ norms in this paper.
The partial Fréchet similarity can be considered as
the length of the longest monotone path in a certain
polygonal domain with weighted regions, where the
weight is either 0 or 1. Hence computing Fδ (P, Q)
bears similarity with the standard shortest path queries
in weighted regions. However, the properties of this
domain and the monotonicity requirement of the paths
considered provide more structure to the problem which
our algorithm will exploit. We describe the domain and
these longest paths in more detail in Section 3.
In Section 4, we present an exact algorithm to compute Fδ (P, Q). Based on the properties of longest monotone paths, we show how to compute Fδ (P, Q) by constructing a “shortest path map” type decomposition [27]
of the polygonal domain. We first bound the complexity
of the decomposition. An explicit representation of the
decomposition would have complexity O(mn(m + n)2 ).
However, by efficiently propagating longest path information, a longest monotone path can be computed
faster, i.e., in O(mn(m + n) log(mn)) time1 .
2
Problem Definition and Preliminaries
A curve in IRd can be represented as a function
f : [0, 1] → IRd . A (monotone) reparametrization α is
a continuous non-decreasing function α : [0, 1] → [0, 1]
with α(0) = 0 and α(1) = 1. A matching between f
and g is simply a pair of monotone reparametrizations
(α, β) of f and g respectively, where the point f(α(x)) is
matched to the point g(β(x)), for any x ∈ [0, 1]. Given
two curves f, g : [0, 1] → IRd , the Fréchet distance between them under the Lp norm, D(f, g), is defined as
D(f, g) := inf max dp f(α(t)), g(β(t)) ,
α,β t∈[0,1]
where dp (x, y) denotes the distance between points x
and y under the Lp norm, and α and β range over all
monotone reparametrizations.
Given a distance threshold δ > 0 and a matching
(α, β) of curves f and g, the score of (α, β) under the Lp
norm, also referred to as the partial similarity Sα,β (f, g)
between f and g for a matching (α, β), is defined as
Z
(||(f ◦ α)0 (t))|| + ||(g ◦ β)0 (t))||)dt,
dp (f(α(t)),g(β(t))≤δ
where ||v|| is the L2 norm of a vector v; namely, the
score is the total length of the portions of the two curves
f and g that are matched with Lp distance smaller than
δ. Naturally, we would like to maximize the length
of these portions, and the partial Fréchet similarity
between f and g for a threshold δ is defined as the
maximum score of any matching of f and g; that is,
Fδ (f, g) := maxα,β Sα,β (f, g) where α and β range over
all monotone reparametrizations. For curves in IRd , the
partial Fréchet similarity between P and Q under the
L1 (resp. L∞ ) norm w.r.t. a distance threshold δ is at
least the optimal partial Fréchet similarity between P
and
√ L2 norm w.r.t. a distance threshold
√ Q under the
δ/ d (resp. δ d). In this sense, the partial Fréchet
similarity under the L1 or L∞ approximates that under
the L2 norm.
Free space diagram. For two polygonal curves P =
hp1 , . . . , pn i and Q = hq1 , . . . , qm i, an alternative way
to view the partial Fréchet similarity Fδ (P, Q) is via
the following free space diagram D = Dδ (P, Q) (see
also [4]): D is an n by m diagram such that its
ith column corresponds to the ith edge of P and has
width ||pi pi+1 ||, while its jth row corresponds to the
1 This run-time is a factor of (m + n) faster than in an earlier
version of this paper [30].
jth edge of Q and has width ||qj qj+1 ||. For a set of
segments X in the plane, let lenp (X) denote the total
length of the segments of X under the Lp norm. Let
f : [0, len2 (P )] → IRd and g : [0, len2 (Q)] → IRd represent
the arc-length parametrization of P and Q, respectively.
Then every point (x, y) in D corresponds to a pair of
points f(x) ∈ P and g(y) ∈ Q. From now on, we abuse
the notation slightly and use P (x) and Q(y) to represent
f(x) and g(y), respectively.
A point (x, y) ∈ D is white if
dp (P(x), Q(y)) ≤ δ. By convexity
of the Lp norm, white points within Q
any cell D[i][j] of D form a connected convex region. Under the
P
L2 norm, this white region is the
intersection between an ellipse with the cell D[i][j]. For
curves in IRd , the white region is the intersection between the cell D[i][j] with a convex polygon of complexity O(d) under the L∞ norm, and with a convex
polygon of complexity O(2d ) under the L1 norm. The
boundary edges of the white regions are referred to as
free space edges. In this paper we consider only the
L∞ and the L1 norms and assume d to be a constant.
Thus the white region in each cell is polygonal, and has
constant complexity.
Finally, a monotone path in D is a path monotone in
both the horizontal and the vertical direction. There is a
one-to-one correspondence between all possible matchings of P and Q, and the set of monotone paths in
D from its bottom-left corner to its top-right corner.
Given any monotone path π, let πW denote its intersection with the white regions of D. Then Sπ (P, Q), the
partial similarity between P and Q induced by π, also
referred to as the score of π, is simply the L1 -length
len1 (πW ) of πW . To compute Fδ (P, Q), the goal is to
find an optimal monotone path whose score is maximized. This corresponds to an optimal partial matching
between P and Q.
The problem of finding the longest monotone path
under the L1 -norm can also be converted to the shortest
monotone path problem over a weighted domain. Since
any monotone path from s to t has the same L1 -length,
maximizing the L1 -length inside white regions is the
same as minimizing the L1 -length inside black regions.
3 Longest Monotone Paths
In this section, we present properties of (longest) monotone paths in the free space diagram.
b and grid G. ConRefined free space diagram D
sider a cell C = D[i][j] of the free space diagram D. For
every vertex v of the white region in C, we extend a horizontal as well as a vertical line from v until it reaches
the boundaries of C. See (a) in the right figure, where
dotted segments are these extension segments. Next,
if a vertical extension edge
intersects a free space edge,
then we extend another
horizontal extension segment from the intersection
point (the double-points in
(b)
(a)
(b) in the right figure).
We process every cell of D
by this two-level extension.
The resulting diagram is
called the refined free space
b see (c) in the
diagram D;
right figure for an example.
b denote the ar(c)
Let Arr(D)
b each region in Arr(D)
b is convex. Since
rangement of D;
the complexity of the white space within each cell of D
b is still O(mn).
is O(1), the complexity of Arr(D)
Let G be the set of grid edges from the original
diagram D as well as the extension segments from the
b Let Arr(G) be the arrangement of
refined diagram D.
G — each cell in Arr(G) is a rectangle. By construction
b every cell C ∈ Arr(G) can contain at most two
of D,
free space edges that have either both positive or both
negative slopes, and these edges cannot intersect the
vertical boundary edges of C. Hence there are only
eight possible configurations of C as shown in Figure 1.
(a)
(b)
(c)
(d)
(e)
(f)
(g)
(h)
Figure 1: Possible configurations of a cell in Arr(G).
Cell ordering on Arr(G). For two
(rectangular) cells C1 and C2 from
Arr(G), we say that C1 ≺ C2 (or
e1 e
2
C2 C1 ) if there is a monotone
π1
path that visits C1 before C2 . It
π2
is easy to verify that this order
relation is well-defined. That is, either it does not exist
(no monotone path connects them). Or if it exists, then
there cannot exist two monotone paths π1 and π2 , such
that π1 visits C1 before C2 , while π2 visits C2 before
C1 . One can then find a total order of cells in Arr(G)
that is consistent with all these pairwise partial order
constraints. We remark that this ordering relationship
b See
may not be well-defined for two edges in Arr(D).
the right figure for an example, where path π1 intersects
e1 and e2 in order, while another monotone path π2
traverses e2 first and then e1 .
Conformal monotone paths. A path is conformal if
it is monotone, polygonal with vertices lying on edges of
b and its intersection with any region in Arr(D)
b
Arr(D),
has at most one segment. Since the score of a path is
the L1 -length of its intersection with the white regions,
b is convex,
and any region in the arrangement of D
any monotone path can be converted into a conformal
path without decreasing its score. Thus from now on,
we consider only conformal paths.
q
We now describe a simple but useful
observation. Consider a cell C ∈ Arr(G).
Let p be a point on the left or bottom
edge of C, and q a point on the top or
right edge. One can connect p and q
optimally (i.e, with largest score) by a p
monotone polygonal chain with at most three pieces,
which we refer to as a three-piece configuration. The first
(resp. last) segment will be degenerate if and only if p
(resp. q) is inside the white region. The middle segment
is contained in the white region. The configuration of
the polychain is such that the L1 -length of the middle
segment is maximized. See the right figure for an
example where the last piece is degenerate. The optimal
three-piece configuration can be computed in constant
time once the entry and exit points are given.
cell due to the monotonicity of the path. Thus, the
path-score functions Sb→eR and Sb→eT on the right
and top edge of a cell C only depend on the functions
Sb→eL and Sb→eB on the left and bottom edge of
C and on (slope) edges in C. Specifically, we have
that Sb→eR (t) = max(Sb→eL →eR (t), Sb→eB →eR (t)) and
Sb→eT (t) = max(Sb→eL →eT (t), Sb→eB →eT (t)).
In Section 4 we will show how to compute Sb→e0 →e
from Sb→e0 for a right or top edge e and a left or bottom
edge e0 of a cell in Arr(G). To compute Sb→eR and
Sb→eT , it is important that taking the maximum of the
scores via eL and eB is a simple operation. For this the
following observation is needed.
Path-score function. Now consider π ∗ (b, p), an
b b, to
optimal path from the left-bottom vertex of D,
b
a point p ∈ D. Define the path-score at p as the
score of this optimal path; that is, Sb (p) = S(π ∗ (b, p)).
b → IR measures the
Thus, the path-score function Sb : D
longest length under the L1 -norm and the monotonicity
constraint. We will in particular consider paths to an
b and paths restricted to go
edge e = q1 q2 of Arr(D)
0
b For t ∈ [0, 1], let Sb→e (t)
through an edge e of Arr(D).
denote the best score of any path reaching the point
e(t) = (1 − t)q1 + tq2 and let Sb→e0 →e (t) denote the best
score reaching e(t) via a point of e0 . We will always
parameterize horizontal edges from left to right, and
vertical edges from bottom to top.
This is in fact a special case of the following
observation.
Cell boundaries. We will compute the path-score
function on the edges of Arr(G), i.e., on the boundaries
of the cells of the refined free space diagram. Since a
path can always be continued to the right or top, the
following observation holds.
Observation 3.1. The score function Sb→e on any
horizontal (resp. vertical) edge e is non-decreasing.
A longest monotone path from the left-bottom
vertex of the free space diagram to a point on the
right edge eR or top edge eT of a cell of Arr(G) will
go through the left edge eL or bottom edge eT of the
Observation 3.2. For all cells of Arr(G) there is a
t0 ∈ [0, 1] such that one of the two following cases holds
(
Sb→eL →eT (t) for t < t0 ,
and
1. Sb→eT (t) =
Sb→eB →eT (t) for t ≥ t0
Sb→eR (t) = Sb→eB →eR (t),
2. Sb→eT (t) = S
(b→eL →eT (t) and
Sb→eL →eR (t) for t > t0 ,
Sb→eR (t) =
Sb→eB →eR (t) for t ≤ t0 .
Observation 3.3. For all cells of Arr(G) a longest
monotone path from b to a point on eR or eT cuts the
cell into two parts such that for points on eR and eT
in one part there is a conformal longest monotone path
through a point on eL or eB in the same part.
4
Algorithm for Partial Fréchet Similarity
4.1 Overview of the Algorithm. Our goal is to
compute a longest monotone path in a weighted domain
(weight 1 for white regions, and 0 otherwise).
For
this, consider a total order hC1 , . . . , CM i of the set of
rectangular cells in Arr(G) where Ci ≺ Cj implies i < j.
We process the Ci s in increasing order of i, and for each
cell C we compute the score functions Sb→eR and Sb→eT
on its right and top boundary edge. Since the cells
neighboring C to the left and to the bottom precede C
in the total order, the score functions Sb→eL and Sb→eB
on the left and bottom boundary edge of C have already
been computed. Our algorithm first computes the score
functions for paths restricted to go through the left edge
and for paths restricted to go through the bottom edge,
i.e., we compute Sb→eL →eR , Sb→eL →eT , Sb→eB →eR , and
Sb→eB →eT . As an intermediate step we compute score
b in C. In a final step
functions on the edges of Arr(D)
we compute the maximum of the scores on eR and eB ,
A
Type (C1):
B
A
b
b
a
a
B
A
b
a
B
A
B
Type (C2):
A
Type (C3):
A
a
b
a
B
A
A
B
b
B
A
B
A
B
a
a
b
b
B
Type (C4):
B
B
b
a
A
a
b
A
a
a
B
b
a
A
b
a
B
b
b
A
b
a
b
B
B
b
A
a
a
B
b
A
a
A
b
Figure 2: Configurations for two consecutive edges ab and AB in an edge sequence from Arr( D).
i.e., we compute Sb→eR from Sb→eL →eR and Sb→eB →eR ,
and compute Sb→eT from Sb→eL →eT and Sb→eB →eT .
In what follows, we describe in Section 4.2 how to
b
propagate score functions from edge to edge in Arr(D)
and how to merge the score functions on the edges of
Arr(G). In Section 4.3 we present a data structure for
efficiently updating the score functions. We summarize
and analyze the entire algorithm in Section 4.4.
4.2 Computing Sb→eR and Sb→eT . The main
building block here is to propagate the score function
b
from edge to edge in Arr(D).
First, we consider the
following simpler problem: Let S = he1 , . . . , e|S| i be an
b and C(S) the class of paths
edge sequence from Arr(D)
visiting the edges of S in order. Given a source point s
and a destination point t, we wish to compute a longest
monotone path π ∗ ∈ C(S) connecting s to t. We later
extend this to the case of merging score functions coming through different edge sequences.
Propagating scores from edge to edge. First
observe that not all points in ei are reachable by a
monotone path from the source s via the edge sequence
Si := he1 , . . . , ei i. We preprocess S by keeping only
the portion of ei that is reachable from s via Si . It
is easy to verify that the reachable portion on each ei
is a single subsegment. The preprocessing takes O(|S|)
time. From now on, we assume that S is the set of edges
after this preprocessing.
b we can enumerate
Since edges in S are from Arr(D),
the configurations of any two consecutive edges in S
based on the eight cell-configurations shown in Figure 1.
There are altogether 17 configurations as shown in
Figure 2; ab and AB denote the two consecutive edges
ei and ei+1 , respectively. Each configuration is decided
by the sign of the slopes and the relative sidedness of
ab and AB. Let H(ab, AB) denote the convex hull of ab
b are convex, H(ab, BA)
and AB. Since all cells in Arr(D)
is either all white or all black.
Φ
Let S(p, q, S 0 ) denote the optimal score of any path from p
to q, passing through the edge
sequence S 0 . For each ei ∈ S,
we maintain the score function
Φi : ei → IR, defined as Φi (p) = S(s, p, Si ) for any p ∈ ei .
In what follows, we will show that each Φi is a concave
piecewise-linear(pwl) function, where the slopes of the
linear pieces are non-increasing. We will also show that
the number of linear pieces in Φi , called its descriptive
complexity |Φi |, satisfies |Φi | = O(i), and Φi can be
computed from Φi−1 in O(i) time. We say that an object X is visible from a point p, denoted by p / X, if for
any point q ∈ X, there is a monotone path from p to q.
Observation 4.1. Given a point u and an edge e
such that u / e, the function hu : e → IR, defined as
hu (p) = len1 (pu) for p ∈ e, is a linear function over e.
Furthermore, given another point vsuch that v / e, hu
and hv share the same slope.
Observation 4.2. Given any edge e = ab with a / b, a
point u, and an edge sequence S 0 , the function f : e →
IR, defined as f (p) = S(u, p, S 0 ) for p ∈ ab, is a nondecreasing function. Furthermore, if ab is white, then
f (q) ≥ f (p) + len1 (pq) for any two points p / q on e.
Lemma 4.1. For any 1 ≤ i ≤ |S|, Φi is a concave
pwl function of O(i) descriptive complexity, and can
be computed from Φi−1 in O(i) time. A corresponding
monotone path can also be computed in the same time
complexity.
Proof. We prove the lemma by induction. The base
case (i.e, i = 1) follows from Observation 4.1. Now
assume the lemma holds for F = Φi−1 . To prove that it
holds for H = Φi , we verify it for each configuration
of ei−1 = ab and ei = AB in Figure 2 — the 17
configurations are classified into 4 types (C1) – (C4),
and those of the same type can be handled similarly. For
simplicity, we assume without loss of generality that the
region H(ab, AB) is white. The case when H(ab, AB) is
black is similar and simpler.
(1). Type (C1): Configurations of this type have the
property that a / b, and that all points in AB are visible
from every point in ab. Since a / b / AB, for any point
p ∈ ab and q ∈ AB, len1 (pq) = len1 (pb) + len1 (bq). It
then follows from Observation 4.2 that F (p)+len1 (pq) ≤
F (b) + len1 (bq). Thus for any point q ∈ AB, H(q) =
maxp∈ab [F (p) + len1 (pq)] = F (b) + len1 (bq), and there is
an optimal path from C(Si ) to q coming from the point
b. Hence H is a concave pwl function with just one piece
and can be computed in O(1) time.
(2). Types (C3) and (C4): We describe how to
update for configurations in (C3), and those in (C4)
can be handled in a symmetric manner. Given a point
p, let p.x and p.y denote its x- and y-coordinates,
respectively; p can also be written as the tuple hp.x, p.yi.
It follows from the monotonicity requirement and the
preprocessing that a.x ≤ A.x. For simplicity we
assume that a.x = A.x = 0 — if a.x < A.x, we
simply remove the extra portion from the function H
obtained, and the resulting function can only have
a smaller complexity. Similarly, we assume without
loss of generality that b.x ≤ B.x. Now parametrize
segments ei−1 and ei by their projection on the xaxis and represent ei−1 (resp. ei ) as ei−1 (x) = a +
hx, ρi−1 xi for x ∈ [0, b.x] (resp. ei (x) = A + hx, ρi xi
for x ∈ [0, B.x]), where ρi−1 (resp. ρi ) is the slope of
ei−1 (resp. ei ). From now on, we abuse the notations
slightly by using F and H to denote F ◦ ei−1 and
H ◦ ei , respectively.
Given an edge e, let e[x0 , x1 ] deei(x)
A
note the subsegment of e from e(x0 ) to
e(x1 ). For any x ∈ [0, b.x], an imporB
tant property for configurations of type a
b
ei−1(u)
(C3) is that the point ei−1 (x) can reach
all points in the segment ei [x, B.x] (via a monotone
path). Now consider the function fu : [0, B.x] → IR,
where fu (x) is the best score of any path in C(Si ) to
ei (x) via the point ei−1 (u). For x < u, fu (x) does not
exist and we set fu (x) = 0. For x ≥ u the best connection between ei−1 (u) to ei (x) is simply connecting them
by a segment (see the right figure for an example). Since
we have assumed that H(ab, BA) is all white, we have
that fu (x) = F (u) + (ei (u).y − ei−1 (u).y) + ρ(x − u),
where ρ = 1 + ρi depends only on the edge ei , and
(ei (u).y − ei−1 (u).y) + ρ(x − u) is the distance between ei−1 (u) and ei (x) under the L1 norm. Hence
the graph of fu is a ray of slope ρ, originated from the
point hu, F (u) + (ei (u).y − ei−1 (u).y)i. Furthermore,
H(x) = maxu∈[0,b.x] fu (x) for every x ∈ [0, B.x], implying that the graph of H is the upper-envelope of the
graphs of fu s for all u ∈ [0, b.x].
The above observations suggest the following twostage procedure to construct H from F . In the first
lifting stage, we compute F1 (u) = F (u) + (ei (u).y −
ei−1 (u).y), for u ∈ [0, b.x]. That is, we lift each point
in the graph of F (u) vertically by V (u) := ei (u).y −
ei−1 (u).y = (A.y − a.y) + (ρi − ρi−1 )u. Obviously, the
function V : [0, b.x] → IR is a linear function with slope
ρi − ρi−1 . Now, the graph of the function fu is simply
the ray γu originated from the point hu, F1 (u)i with
slope ρ. All rays for different u ∈ [0, b.x] share the
same slope and H is the upper envelope of them. The
computation of the upper envelope of such rays is the
second enveloping stage.
Since F1 is the sum of F
p∗
and a linear function V , it is
also a concave pwl function
with |F1 | = |F |. This is because adding V to any linear
piece in F increases the slope
B.x
b.x
of that linear function by the
slope of V . Hence the order of the slopes of all linear
pieces in F remains the same after adding V . In the
−
second enveloping stage, let →
v denote the common direction shared by all rays. Since F1 is concave, the only
ray that can appear on the upper envelope must origi−
nate from p∗ = hu∗ , F1 (u∗ )i, such that →
v is a tangent
∗
direction at p . See the right figure for an example,
where the solid concave chain is the graph of F1 , and
the graph of H is the concatenation between the portion of the concave chain before p∗ and the thick dashed
ray. No other rays (thin dashed rays) can appear on the
upper envelope. Hence we have |H| ≤ |F1 |+1 ≤ |F |+1.
(3). Type (C2): The main difference between the configuration of
type (C2) and those of types (C3) is A
that a point ei−1 (u) ∈ ab can reach
(via a monotone path) only ei [u, û] a
B
in AB, instead of reaching ei [u, B.x]
b
as in the previous case, where ei (û)
û
u
is the intersection point between ei
and the horizontal line passing through ei−1 (u). See
the right figure. Similar to the previous case, we assume again that a.x = A.x = 0, and b.x ≤ B.x without
loss of generality. Note that both ρi−1 and ρi are necessarily negative in this case.
Consider again the function fu : [0, B.x] → IR,
where fu (x) is the best score of any path in C(Si ) to
ei (x) via the point ei−1 (u). Set ρ = 1 + ρi . We have:
is restricted to go through a certain set of edges S in
O(|S|2 ) time. (The time complexity can be improved
fu (x) =
(
to near linear with the data structure in Section 4.3.)
F (u) + (ei (u).y − ei−1 .y) + ρ(x − u), for x ∈ [u, û] However, different edge sequences may reach an edge
0
for x ∈ (0, u) ∪ (û, B.x]. e, and the score function on e is the maximum of the
functions corresponding to these edge sequences. The
This means that during the second enveloping stage, general score function on an edge is still continuous
instead of extending a ray from each point hu, F1 (u)i, we and pwl, as the maximum of a finite number of pwl
now extend a segment from hu, F1 (u)i over the interval function is again pwl. But it is not necessarily concave.
[u, û]. All such extension-segments share the same slope To ensure that the complexity of the score function on
ρ. However, they may be of different length.
each edge in Arr(G) is still small, we need to bound
Furthermore, since ei−1 (u).y = ei (û).y, we have the increase of the number of break points of the pwl
ρi
that u = ρi−1
û + A.y−a.y
= c1 û + c2 ; c1 is positive score functions as they are propagated from cell to cell
ρi−1
as both ρi−1 and ρi are negative. We also note that in Arr(G). To achieve this, we use two parameters on
u ≤ û for any u ∈ [0, b.x] (as the two input segments each edge: the number of break points and the minimum
do not intersect), and that û is non-decreasing w.r.t u. number of concave pieces into which the score function
Now assume that we have already obtained F1 = F + V can be decomposed, where on each of the concave pieces
after the lifting stage. In the second stage, we extend the slopes of the linear pieces are non-increasing. In
a segment of slope ρ from hu, F1 (u)i over the interval particular, for the edges eL , eB , eR , and eT of a cell
[u, û], and we trace the right endpoint of this segment. of Arr(G) we denote the number of break points by
More specifically, let g(u) = d1 u + d2 be one linear piece BL , BB , BR and BT and the number of concave pieces
from F1 . For each point hu, g(u)i, the right endpoint of by PL , PB , PR and PT , respectively. We bound these
the corresponding extending segment is hû, h(û)i, where numbers for the right and the top edge by those for the
left and the bottom edge.
h(û) = g(u) + ρ(û − u) = (d1 − ρ)u + d2 + ρû
Lemma 4.2. For each rectangular cell C in Arr(G),
= [c1 (d1 − ρ) + ρ]û + c2 (d1 − ρ) + d2 .
Hence h(û) is a linear function, and its slope depends only on ei−1 , ei , and the slope of the linear
piece g. Thus as hu, F1 (u)i changes, h(û) is a pwl
function with |F1 | number of pieces. Furthermore,
since c1 is positive, given two linear pieces from F1
with slopes d1 and d01 , the resulting pieces in h still
maintain the order between d1 and d01 . Hence h is
also concave.
Finally, H is
the upper envelope of all these
−
extending segments. Let →
v be
p∗
p00
the common direction shared
p1
p01
by all extending segments, and
p2
p02
p∗ = hu∗ , F1 (u∗ )i the point in
→
−
the graph of F1 such that v is
b.x
B.x
a tangent direction at p∗ . The
graph of H is the concatenation between the portion of
the graph of F1 before p∗ , the extending segment at p∗ ,
and the portion of the graph of h after û∗ . See the right
figure for an example where p00 = hû∗ , h(û∗ )i. (Note
that the slope of p00 p01 (resp. of p01 p02 ) may be different
from that of p∗ p1 (resp. p1 p2 ). But the order between
these slopes are maintained.) Hence |H| is still concave
pwl, and |H| = |F1 | + 1 = |F | + 1.
Putting all cases together, the lemma then follows.
Merging score functions. Lemma 4.1 provides an
algorithm to compute the longest monotone path that
(a) BR + BT ≤ BL + BB + PL + PB + O(1),
(b) PR + PT ≤ PL + PB + O(1).
Proof. First, we extend the analysis of Lemma 4.1 to the
case of analyzing how a pwl score function on an edge
b with several concave pieces propagates to
ab of Arr(D)
a next edge AB. A similar case analysis as before shows
that for nearly all cases, the number of concave pieces
does not contribute to the number of break points. Only
for the case type (C2) an additional break point may be
created between every two consecutive concave pieces
when propagating from one edge to the next. Thus the
total number of new break points is at most the number
of concave pieces plus a constant. Furthermore, in all
cases (including type (C2)) the number of concave pieces
stays the same when propagating the function.
We now describe how to propagate the score
function Sb→eL to edges eT and eR (i.e, computing
Sb→eL →eT and Sb→eL →eR ). By Observation 3.3 we can
split eL such that the upper part e1L ⊆ eL propagates
to eT and the lower part e2L ⊆ eL propagates to eR .
The split point produces one additional break point and
one concave piece. Based on the eight configurations
shown in Figure 1, the function Sb→eL propagates to eR
b (inthrough a fixed set of at most three edges of Arr(D)
cluding eR ) in this cell. For example, if the cell has configuration (f) as in Figure 1, then we propagate Sb→eL
first to the interior edge via a type-(C4) case from Figure 2, and then to eR via another type-(C4) propagation. In general, this may increase the number of break
points by a constant if no case type-(C2) occurs. If a
type-(C2) case occurs the number of break points can
additionally increase by the number of concave pieces
propagated. However, observe that type (C2) appears
at most once within a single cell.
Now consider the propagation of the function from
e1L to eT . First note that eL can correspond to up to
three edges in Arr(G). We need to compute the score
function on each of them separately, and then concatenate them into the score function for Sb→eL →eT . Depending on the type of cell, Sb→e1L might be propagated
to eT through different sets of edges. Since we assume
that the paths are conformal, there are at most three
different sets of edges, each of constant size, through
which eT might be reached. We again split e1L accordingly, introducing at most three additional break points
and concave pieces (the correctness of such splitting is
guaranteed by Observation 3.2). Again, the propagation increases the number of break points by O(1) plus
the number of concave pieces in e1L . Putting the two
parts together, the complexity of break points can increase O(1) + PL from eL to eR and eT .
Analogously, we can propagate Sb→eB to eR and eT
such that the number of break points increases at most
PB + O(1), and the number of concave pieces increases
by a constant. Finally, to compute the score functions of
the top and the right boundary we need to compute the
maximum of the propagated functions from the left and
from the bottom. By Observation 3.2, the score function
for Sb→eR (resp. Sb→eT ) is the concatenation of a piece
of Sb→eL →eR and a piece of Sb→eB →eR (resp. a piece
of Sb→eL →eT and a piece of Sb→eB →eT ). This gives at
most one additional concave piece and one additional
break point. The lemma then follows.
With these bounds the direct construction of the
longest path map without further data structures would
need O(mn(m+n)2 ) time. Next in Section 4.3, we show
how to propagate the score functions efficiently by using
a tree data structure.
4.3 A Data Structure for Score Functions. The
score functions on the edges of Arr(G) are pwl function
with a number of concave pieces. First, we describe
a data structure so that one single concave pwl function can be maintained efficiently. In general, a pwl
function H can be represented as a list of break points
b1 , . . . , bl+1 , associated with a sequence of linear functions Hi : [bi , bi+1 ] → IR. We represent H using the
following augmented balanced binary tree T = T (H) to
enable efficient updates of concave pwl functions.
Specifically, from left to right, the ith leaf of T ,
denoted by li , corresponds to interval [bi , bi+1 ]. Every
leaf node li stores a linear function fli : [bi , bi+1 ] → IR,
called the base function at leaf li . Each internal node
v ∈ T is associated with an interval Iv = [bvl , bvr +1 ]
where vl and vr are the indices of the left-most and rightmost leaves of the subtree Tv rooted at v, respectively.
It also stores a modification record (MD-record) that
specifies how to modify every base function within the
subtree Tv . In general, a linear function h can be
described by a pair of parameter (ρ, ω), such that h(x) =
ρx + ω. An MD-record µ contains two functions hµs , µt i
such that it modifies an input linear function h = ρx+ω
to a new linear function h0 = µs (ρ, ω)x + µt (ρ, ω). Each
function µs (or µt ) is a linear combination of ρ and ω
that has the simple form µs (ρ, ω) = c1 ρ + c2 ω + c3 for
some constants ci s. Hence µs and µt are each described
by three constants. As an example, if we wish to add a
linear function h0 (x) = ax + b to function h = ρx + ω,
we simply set µs (ρ, ω) = ρ + a and µt (ρ, ω) = ω + b.
The composition of two MD-records µ1 = hµ1s , µ1t i
and µ2 = hµ2s , µ2t i can be computed in constant time,
and the result is a new MD-record hµs , µt i = hµ1s , µ1t i ◦
hµ2s , µ2t i. Note that this operation is not commutative.
To obtain Hi , the ith piece of linear function of H,
we first find the path from the root v0 of T to the
leaf li corresponding to the interval [bi , bi+1 ]. Let
Ai = {v0 , . . . , vm = li } be the set of nodes along
this path. Let hm = ρm x + ωm be the base function
stored at li , and µj the MD-record stored at vj , for
j ∈ [0, m − 1]. The linear function Hi : [bi , bi+1 ] → IR
is simply Hi = µ0 ◦ µ1 ◦ · · · ◦ µm−1 (ρm , ωm ). Since
the composition is not commutative, it is important to
note the order we apply µv s. The entire process takes
O(m) = O(log l) time, where l is the complexity of the
pwl function.
Given such an augmented binary tree representation of a pwl function with complexity l, we can insert
or delete k consecutive intervals (together with corresponding linear functions) in O(log l + k) time. The
main difference from standard balanced binary tree operations is to maintain the MD-record properly, especially during rotations. We omit the straightforward,
but tedious details. We can also split the tree in O(log l)
time, e.g. using the split operation of red-black-trees.
Given any interval [bi , bj ], one can also identify
O(log l) canonical and disjoint intervals whose union
forms [bi , bj ], and each such interval corresponds to a
leaf or an internal node of the tree T . This set of
intervals is called the canonical decomposition of [bi , bj ].
Now suppose we wish to modify all functions from
H over an interval [bi , bk ] by an MD-record µ∗ . We first
identify the set of nodes corresponding to the canonical
decomposition of [bi , bk ]. For any interior node v we
visit during the descending from the root to search for
these canonical decomposition nodes, we push the MDrecord µv to its children, and change the MD-record of v
to identity. Let µl and µr be the MD-record associated
with the left and right children of v before this pushing
down operation, respectively. Afterwards, the new MDrecords are µl∗ = µv ◦ µl and µr∗ = µv ◦ µr . As a
result, let u be a node corresponding to an interval in the
canonical decomposition of [bi , bk ]. Let {v0 , . . . , vm =
u} be the set of nodes along the path from the root
v0 to u, and µj the MD-record stored at vj . After the
descending to u, all nodes vj ’s have an identity as their
MD-record, for j ∈ [0, m − 1]. For u, we set its MDrecord µ = µ∗ ◦ µ0 ◦ µ1 ◦ · · · ◦ µm . The entire process
takes O(log l) time.
Similarly, we also store an interval-modification
record (IM-record) with each interior node v, which
is a linear function Iv that will apply to all break
points within the subtree rooted at v. For example,
Iv = c1 x+c2 means that a break point bi will now move
to b0i = c1 bi +c2 . The IM-records can be maintained and
updated, similarly to that of MD-records.
Finally, we augment the data structure so that
at each internal node corresponding to the interval
[bvl , bvr ], we also store the slopes of the two linear
functions following bvl and bvr and the function values
at bvl and bvr . If the input function H is concave, then
given an angle θ, we can perform a standard binary
search to locate the first interval [bi , bi+1 ] so that the
slope of Hi is at most θ in O(log l) time. Furthermore,
by a search on the function values, we can find an
intersection of two functions of complexity l1 and l2 ,
respectively, in O(log l1 + log l2 ) time.
Now, we represent the score function on an edge
as an ordered sequence of concave pwl functions, each
represented using the data structure described above.
It can be verified that the propagation of the score
function within one cell consists a sequence of operations
supported by this tree structure and we have the
following result (proof omitted due to space limitation).
Lemma 4.3. For a cell of Arr(G) the score functions
Sb→eR and Sb→eT can be computed from Sb→eL and
Sb→eB in O((PL + PB ) log(BL + BB )) amortized time
in O(BL + BB ) space.
Theorem 4.1. We can compute the partial Fréchet
similarity under the L1 or L∞ norm of two curves in Rd
of size m and n, respectively, in O(mn(m + n) log(mn))
time and O(mn(m + n)) space.
Proof. First, by Lemma 4.2 (b), it is easy to see that
the complexity of concave pieces within a single cell is
O(mn). We now bound the total number of concave
pieces by a more global argument: each cell contributes
at most a constant number of concave pieces by itself
and propagates them and those of its predecessors
partially to the top and partially to the right. A
concave piece, after it is created, is propagated at most
m + n times because any monotone sequence of cells
has at most this length. Since there are O(mn) number
cells, we have O(mn) number of “created”-type concave
pieces, and O(mn(m + n)) “propagated”-type, and thus
total, concave pieces.
By Lemma 4.2 (a), a cell can create O(1) + X
number of break points, where X is the number of
concave pieces in this cell. Once created, a break
point can then be propagated to at most n + m cells.
Hence there are O(mn(m + n)2 ) total break points.
Furthermore, a single cell has O(mn(m + n)) break
points. This is because other than constant number of
them, any break point here can be charged to a different
concave piece prior to this cell. Putting everything
together, by Lemma 4.3, through out the propagation,
the data structure has size O(mn(m+n)), and the total
time complexity is O(mn(m + n) log(mn)).
5
Conclusion
In this paper, we propose a natural extension of the
Fréchet distance to measure the partial similarity between curves. Specifically, given two polygonal curves
P and Q in IRd of sizes n and m, respectively, the partial Fréchet similarity between them under the L1 or
L∞ norm can be computed in O(mn(m + n) log(mn))
time. This is the first polynomial-time algorithm for
computing continuous partial curve similarity that allows general types of outliers.
The optimal matching under the L1 or the L∞ norm
provide certain approximation for the optimal matching the L2 norm. A natural next question is to compute the partial Fréchet similarity under the L2 norm.
Other important questions include developing efficient
approximation algorithms for the partial Fréchet similarity problem, and for the problem of finding the best
partial matching under translations or rigid motions.
4.4 Putting Everything Together. The algorithm
propagates the score functions on the edges of Arr(G)
from cell to cell. Lemma 4.3 shows that the time needed
Acknowledgments. The authors would like to thank
per cell depending on the complexity of the score funcanonymous reviewers for very helpful comments and
tions on the edges of the cell; while Lemma 4.2 provides
Sariel Har-Peled for useful discussions.
a bound on the complexity of the score functions.
References
[1] P. K. Agarwal, S. Har-Peled, N. Mustafa, and Y. Wang.
Near-linear time approximation algorithms for curve
simplification in two and three dimensions. Algorithmica, 42:203–219, 2005.
[2] H. Alt and M. Buchin. Can we compute the similarity
between surfaces?, 2007. arXiv:cs/0703011v1.
[3] H. Alt, A. Efrat, G. Rote, and C. Wenk. Matching
planar maps. J. Algorithms, 49:262–283, 2003.
[4] H. Alt and M. Godau. Computing the Fréchet distance
between two polygonal curves. Internat. J. Comput.
Geom. Appl., 5:75–91, 1995.
[5] H. Alt and L. J. Guibas. Discrete geometric shapes:
Matching, interpolation, and approximation. In J.-R.
Sack and J. Urrutia, editors, Handbook of Computational Geometry, pages 121–153. Elsevier Science Publishers B. V. North-Holland, Amsterdam, 2000.
[6] H. Alt, C. Knauer, and C. Wenk. Matching polygonal curves with respect to the fréchet distance. In
Proc. 18th Internat. Sympos. Theoret. Asp. Comp. Sci.,
pages 63–74, 2001.
[7] H. Alt, C. Knauer, and C. Wenk. Comparison of
distance measures for planar curves. Algorithmica,
38(1):45–58, 2004.
[8] B. Aronov, S. Har-Peled, C. Knauer, Y. Wang, and
C. Wenk. Fréchet distance for curves, Revisited. In
Proc. 14th Annu. European Sympos. Algorithms, pages
52–63, 2006.
[9] S. Brakatsoulas, D. Pfoser, R. Salas, and C. Wenk.
On map-matching vehicle tracking data. In Proc. 31st
VLDB Conference, pages 853–864, 2005.
[10] K. Buchin, M. Buchin, and J. Gudmundsson. Detecting single file movement. In ”Proc. 16th ACM
SIGSPATIAL Internat. Conf. Advances in Geographic
Information Systems”, 2008. To appear.
[11] K. Buchin, M. Buchin, J. Gudmundsson, M. Löffler,
and J. Luo. Detecting commuting patterns by clustering subtrajectories. In Proc. 19th Internat. Sympos.
Algorithms and Computation, 2008. To appear.
[12] K. Buchin, M. Buchin, C. Knauer, G. Rote, and
C. Wenk. How difficult is it to walk the dog? In Proc.
23rd Europ. Workshop Comput. Geom., pages 170–173,
2007.
[13] K. Buchin, M. Buchin, and C. Wenk. Computing the
Fréchet distance between simple polygons. Comput.
Geom. Theory Appl., 41(1-2):2–20, 2008.
[14] M. Buchin. On the Computability of the Fréchet
Distance Between Triangulated Surfaces. PhD thesis,
Dept. of Comput. Sci., Freie Universität Berlin, 2007.
[15] D. Cardoze and L. Schulman. Pattern matching for
spatial point sets. In Proc. 39th IEEE Sympos. Found.
Comput. Sci., pages 156–165, 1998.
[16] E. W. Chambers, E. C. de Verdière, J. Erickson,
S. Lazard, F. Lazarus, and S. Thite. Walking your
dog in the woods in polynomial time. In Proc. 24th
ACM Sympos. Comput. Geom., pages 101–109, 2008.
[17] M. Clausen and A. Mosig. Approximately matching
polygonal curves with respect to the Fréchet distance.
Comput. Geom. Theory Appl., 30:113–127, 2005.
[18] A. F. Cook and C. Wenk. Geodesic Fréchet distance
inside a simple polygon. In Proc. 25th Internat.
Sympos. Theoret. Asp. Comp. Sci., pages 193–204,
2008.
[19] A. Efrat, Q. Fan, and S. Venkatasubramanian. Curve
matching, time warping, and light fields, new algorithms for computing similarity between curves. J.
Math. Imaging Vis., 27(3):203–216, 2007.
[20] A. Efrat, S. Har-Peled, L. J. Guibas, J. S. Mitchell, and
T. Murali. New similarity measures between polylines
with applications to morphing and polygon sweeping.
Discrete Comput. Geom., 28:535–569, 2002.
[21] P. Indyk. Approximate nearest neighbor algorithms
for Fréchet distance via product metrics. In Proc. 18th
ACM Sympos. Comput. Geom., pages 102–106, 2002.
[22] P. Indyk, R. Motwani, and S. Venkatasubramanian. Geometric matching under noise: Combinatorial bounds and algorithms. In Proc. 10th ACM-SIAM
Sympos. Discrete Algorithms, pages 457–465, 1999.
[23] E. J. Keogh and M. J. Pazzani. Scaling up dynamic
time warping to massive dataset. In Proc. 3rd Euro.
Conf. Princip. Data Mining and Know. Disc., pages
1–11, 1999.
[24] M. Kim, S. Kim, and M. Shin. Optimization of subsequence matching under time warping in time-series
databases. In Proc. ACM symp. Applied comput.,
pages 581–586, New York, NY, USA, 2005.
[25] R. Kolodny, P. Koehl, and M. Levitt. Comprehensive
evaluation of protein structure alignment: Scoring by
geometric measures. J. Mol. Biol., 346:1173–1188,
2005.
[26] S. Kwong, Q. H. He, K. F. Man, K. S. Tang, and C. W.
Chau. Parallel genetic-based hybrid pattern matching
algorithm for isolated word recognition. Int. J. Pattern
Recognition & Artificial Intelligence, 12(5):573–594,
August 1998.
[27] J. S. B. Mitchell. Geometric shortest paths and network optimization. In J.-R. Sack and J. Urrutia,
editors, Handbook of Computational Geometry, chapter 15, pages 633–701. Elsevier, 2000.
[28] M. Parizeau and R. Plamondon. A comparative analysis of regional correlation, dynamic time warping,
and skeletal tree matching for signature verification.
IEEE Trans. Pattern Anal. Mach. Intell., 12(7):710–
717, 1990.
[29] G. Rote. Computing the Fréchet distance between
piecewise smooth curves. Comput. Geom. Theory
Appl., 37(3):162–174, 2007.
[30] Y. Wang. Exact algorithm for partial curve matching
via the fréchet distance. Technical Report OSUCISRC-9/08-TR48, The Ohio State University, 2008.
[31] C. Wenk. Shape Matching in Higher Dimensions.
PhD thesis, Dept. of Comput. Sci., Freie Univ.ersität,
Berlin, 2002.