Full text
1 Optimal Symbol Alignment Distance: A New Distance for Sequences of Symbols Javier Herranz, Jordi Nin, Marc Sol´ e Abstract Comparison functions for sequences (of symbols) are important components of many applications, for example clustering, data cleansing and integration. For years, many efforts have been made to improve the performance of such comparison functions. Improvements have been done either at the cost of reducing the accuracy of the comparison, or by compromising certain basic characteristics of the functions, such as the triangular inequality. In this paper, we propose a new distance for sequences of symbols (or strings) called Optimal Symbol Alignment distance (OSA distance, for short). This distance has a very low cost in practice, which makes it a suitable candidate for computing distances in applications with large amounts of (very long) sequences. After providing a mathematical proof that the OSA distance is a real distance, we present some experiments for different scenarios (DNA sequences, record linkage, ...), showing that the proposed distance outperforms, in terms of execution time and/or accuracy, other well-known comparison functions such as the Edit or Jaro-Winkler distances. Index Terms Sequences of Symbols, String Distances, Triangular Inequality I. INTRODUCTION Sequences of symbols are a well-known data representation type and are widely used in databases for representing many types of non numerical attributes, such as names or addresses. J. Herranz is with the Dept. Matem`atica Aplicada IV, Universitat Polit`ecnica de Catalunya, in Barcelona (Spain) J. Nin is with CNRS; LAAS; 7 avenue du Colonel Roche, 31077 Toulouse Cedex 4 (France). M. Sol´e is with the Dept. Arquitectura de Computadors, Universitat Polit`ecnica de Catalunya, in Barcelona (Spain) E-mail addresses: [email protected], [email protected], [email protected] March 31, 2010 DRAFT Digital Object Indentifier 10.1109/TKDE.2010.190 1041-4347/10/$26.00 © 2010 IEEE IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
2 Moreover, they are gaining more and more attention in many other communities because they can represent data in a large variety of domains, such as gene information [1], vehicular tracking [2] or sequential patterns [3]. For this reason, there is a lot of work in computing similarities among sequences of symbols [4], [5], [6], [7], [8], [9], [10], [11]. However, the similarity measures presented in most of those works either do not fulfill the mandatory conditions to be a real distance (most of the times, because the triangular inequality does not hold) or do not contain a proof for that. Formally, a distance function dmust satisfy the following properties: 1) Symmetry: d(A, B)=d(B,A)for all sequences A, B 2) Positivity: d(A, B)≥0for all sequences A, B 3) Reflexivity: d(A, A)=0for all sequence A 4) Triangular Inequality: d(A, B)≤d(A, C)+d(B,C)for all sequences A, B, C To the best of our knowledge, there are only two sequence measures that fulfill these conditions: the Hamming distance [6] and the Levenshtein (Edit) distance [8]. The remaining measures are similarity functions instead of real distances because they do not comply with the triangular inequality (or this is not proved). For this reason the application of such measures to the scenarios where having a metric space is a must, such as metric spaces [12], clustering [13] or k-nearest neighbors algorithms [14], becomes unfeasible from a theoretical point of view. The Hamming and Edit distances present also some problems. For instance, the Hamming distance can only be applied to sequences of the same length, while the Edit distance has a large, both practical and theoretical, complexity (O(n2)). For these reasons many similarity measures have been developed, albeit sacrificing some of the mandatory properties of a distance. For example, the Jaro-Winkler distance [7] is very efficient in terms of practical computational cost when the compared strings are not too large. Therefore, it saves execution time (when compared to Edit distance) in applications where there are many comparisons to be done. In this paper, we present a new string comparison function with a very low practical cost (as the Jaro-Winkler distance). This new distance, that we call Optimal Symbol Alignment distance (OSA, for short), is a real distance (as the Edit distance), because it fulfills all the properties defined before. In some sense, the OSA distance enjoys the best of the two worlds: it can be used in scenarios where triangularity is a must, and it also saves execution time in applications with a large number of comparisons. For this reason, we believe that the new distance may be March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
3 of great interest in a wide range of practical situations. We will describe some experiments to show the applicability of the OSA distance to different scenarios: computing distances between long DNA sequences, and performing record linkage in both medium and large databases. The experiments show that the OSA distance always outperforms the Edit and Jaro-Winkler distances in terms of execution time, sometimes by several orders of magnitude. Moreover, in terms of quality, the results obtained with the OSA distance are very similar (if not better) than those obtained with the Edit distance, except for a specific (hard) scenario of record linkage without filtering. The rest of this paper is organized as follows. Firstly, in Section II we introduce some basic concepts about the Edit and Jaro-Winkler distances. Then, in Section III we provide the definition of the OSA distance, as well as a mathematical proof that it satisfies the triangular inequality. Implementation details for an efficient computation of the OSA distance are given in Section IV, including two new algorithms for finding the optimal alignment of a symbol (in our particular scenario). Next, in Section V we explain some experiments that we have run to show the applicability of the OSA distance and to compare it with the Edit and Jaro-Winkler distances. Finally, we present some conclusions and possible lines of future work in Section VI. II. PRELIMINARIES In this section, we recall some basic notions about two classical distances: the Edit and Jaro- Winkler ones. A. Edit Distance The Edit distance [8], [11], [15] measures the difference between two sequences, given by the minimum number of edit operations needed to transform one sequence into the other. An edit operation can be either an insertion, deletion or substitution of a single symbol, although many variations exist in which the set of allowed operations is larger or more restricted. In some way, Edit distance assumes that the differences between two sequences are due to typos or spelling errors. The Edit distance has found a large variety of applications in many scenarios and has achieved very good results [16]. However, the Edit distance has a large complexity: its computation using classical algorithms [17] based on dynamic programming has a complexity equal to O(n2), March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
4 where nis the size of the shortest string. Other algorithms to compute the Edit distance exist [18], [19], having a lower complexity of O(dn), for example, where dis the real Edit distance. Note that, when two completely different strings have to be compared, the complexity of these variants is the same as that of the classical algorithm. B. Jaro-Winkler Distance Due to the high computational cost of the Edit distance, other sequence comparison functions are preferred in some situations requiring intensive distance computations. An example is the Jaro-Winkler distance [7]. The computation of this distance comprises three basic steps: (i) compute the string lengths, (ii) find the common characters in the two strings, and (iii) count the number of transpositions. A common character is a character placed closely in both strings, where closely means that the difference between both positions is less than half of the shortest string length. A transposition occurs when a common character in one string is out of order with respect to the corresponding character in the other string. Although often referred as a distance, the Jaro-Winkler is actually not a distance in the mathematical sense of the term, because it does not fulfill the triangular inequality. Therefore, it cannot be applied to any problem where triangularity is a must, for example in clustering or metric spaces. However, since the Jaro- Winkler distance is very efficient in terms of computational cost, it is preferred to the Edit distance in some scenarios. III. OPTIMAL SYMBOL ALIGNMENT (OSA) DISTANCE The intuition behind the new Optimal Symbol Alignment (OSA) distance is that strings are close if they have many common symbols, and in addition their common symbols are placed in similar positions, in the strings being compared. Given a finite alphabet of symbols X, let A=(a1,...,a nA)and B=(b1,...,b nB)be two sequences of symbols, where ai,b j∈X, for i=1,...,n A,j=1,...,n B. For any sequence of symbols A,wedefine as XA⊆Xthe subset of symbols that appear in A;thatis,XA={x∈X s.t. ∃i∈{1,2,...,n A}with ai=x}. For a symbol x∈XA, we also define the subset of positions Ax={i∈{1,...,n A}s.t. ai=x}. We define the OSA distance d(A, B)between the sequences Aand Bas d(A, B)= x∈XA∪XB d(x, A, B), March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
5 where the value d(x, A, B)is defined as d(x, A, B)=⎧ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎩ |Ax|if x∈XA−XB |Bx|if x∈XB−XA f(x, A, B)if x∈XA∩XB Finally, we have to define the value of f(x, A, B), which is the contribution of the symbol xto the distance d(A, B), when this symbol xis included in both sequences Aand B. Let us assume without loss of generality that |Ax|≤|Bx|. The idea is to select the subset of |Ax|positions j, from the set Bx, which are globally closest to the set of |Ax|positions in Ax. Namely, if i1<i 2< ... < i |Ax|are the positions in Ax, then we select |Ax|positions j1<j 2< ... < j |Ax|in Bxminimizing the global distance |i1−j1|+...+|i|Ax|−j|Ax||.We use notation jh=pj(ih,A,B), for h=1,...,|Ax|, to denote the position in Bxthat optimally matches position ih∈Ax. We say that jhis the projection of position ihfrom sequence Ato sequence B. For completeness, we also use the symmetric notation ih=pj(jh,B,A). Each of these common symbols aih=bjh=x, for h=1,...,|Ax|, will contribute with |ih−jh| nAB to the value f(x, A, B), where nAB =max{nA,n B}. In this way, we ensure that these contributions are bounded by 1. The remaining |Bx|−|Ax|symbols will be considered as noncommon symbols, so each of them will contribute with a 1 to the global distance d(A, B). Taking all these facts into account, we finally have f(x, A, B)=(|Bx|−|Ax|)+ 1 nAB ih∈Ax |ih−pj(ih,A,B)|. Depending on the differences between the two sequences to be compared (more or less repeated symbols, more or less transpositions, etc.) the OSA distance dOSA(A, B)will be more or less similar to the Edit distance dEdit(A, B). But in any case, they will not be very far, because it is easy to prove that dEdit(A,B) 2≤dOSA(A, B)≤2·dEdit(A, B), for any two sequences A, B. A. Proving the Triangular Inequality It is straightforward to check that the function d(A, B)defined in the previous section satisfies the properties of symmetry, positivity and reflexivity. Let us show that it also satisfies the triangular inequality property. Let A, B, C be three arbitrary sequences of symbols: A=(a1,...,a nA), B=(b1,...,b nB)and C=(c1,...,c nC).Wewanttoprovethatd(A, B)≤d(A, C)+d(B,C). March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
6 Let us first consider the particular case where each symbol x∈Xcan appear at most once in each sequence (i.e. there are no repetitions of symbols in any single sequence). Proposition 1: If |Ax|≤1,|Bx|≤1and |Cx|≤1, for every symbol x∈X, then d(A, B)≤ d(A, C)+d(B,C). Proof: For each symbol x∈XA∪XB, we have one of the three following cases: 1) x∈XA−XB, then the contribution of xto d(A, B)is exactly 1. We have either x∈XC, which implies the contribution of xto d(B,C)is exactly 1, or x/∈XC, which implies the contribution of xto d(A, C)is exactly 1. In both cases, the contribution of xto d(A, C)+d(B,C)is greater or equal than the contribution of xto d(A, B). 2) x∈XB−XA, symmetric case. 3) x∈XA∩XB. In this case, we have that the contribution of xto d(A, B)is d(x, A, B)= |i−j| nAB ≤1, where Ax={i}and Bx={j}.Ifx/∈XC, then the contribution of xto d(A, C)+d(B,C)is 2. If x∈XC,sayCx={k},wehavex∈XA∩XB∩XC,andwe can write f(x, A, B)=|i−j| nAB =|i−k+k−j| nAB ≤|i−k| nAB +|k−j| nAB . Now we can consider two different cases. The first one is when nC≤nAB. In this case, we have nAC ≤nAB and nBC ≤nAB, and so the above value f(x, A, B)is less than or equal to ≤|i−k| nAC +|k−j| nBC =f(x, A, C)+f(x, B, C). Now for the second case, where nC=nAB +, for some integer >0, there are symbols in XCthat are not in XA∪XB.NowwehavenAC =nBC =nAB +. Note that these symbols will not contribute to the value d(A, B), but will contribute with 2to the value d(A, C)+d(B,C). Let us go back to our situation where x∈XA∩XB∩XC,wehave f(x, A, B)≤|i−k| nAB +|k−j| nAB =|i−k| nAC −+|k−j| nBC −. Now we can use the fact that a b−=a b+a b(b−)and so the last inequality becomes f(x, A, B)≤|i−k| nAC +|i−k|· nAC(nAC −)+|k−j| nBC +|k−j|· nBC(nBC −)≤ March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
7 ≤|i−k| nAC +|k−j| nBC + nAC −+ nBC − =f(x, A, C)+f(x, B, C)+ nAC −+ nBC −. Here we have used that |i−k|≤nAC and |k−j|≤nBC. If we consider all the symbols x∈XA∩XB∩XC, together, we have x∈XA∩XB∩XC f(x, A, B)≤ x∈XA∩XB∩XC f(x, A, C)+ x∈XA∩XB∩XC f(x, B, C)+ +|XA∩XB∩XC|· nAC −+ nBC − But we can now use the fact that +|XA∩XB∩XC|≤nC=nAC =nBC, which implies that the last part of the expression above is less than or equal to 2. Recall that the symbols which are in XC−(XA∪XB)contribute with 2to the value d(A, C)+d(B,C). Summing up, if we consider the symbols x∈XA∩XB∩XC, their contribution to d(A, B) is less than or equal to the contribution of these symbols to d(A, C)+d(B,C)plus the contribution of the symbols in XC−(XA∪XB)to d(A, C)+d(B,C). Putting all the pieces together, we finally have that d(A, B)≤d(A, C)+d(B,C)always holds, as desired. Now we can prove that the triangular inequality holds for any triple of sequences, even if they have repeated symbols. Theorem 1: Let A, B, C be three arbitrary sequences of symbols in a finite alphabet X. Then d(A, B)≤d(A, C)+d(B,C). Proof: The idea is to construct, from the initial sequences A=(a1,...,a nA),B= (b1,...,b nB)and C=(c1,...,c nC), new sequences A=(a 1,...,a nA),B=(b 1,...,b nB) and C=(c 1,...,c nC)such that A,B,Cdo not have repeated symbols, and then to apply Proposition 1 to A,B,C. Specifically, for each symbol x∈XC, let ck1,...,c k|Cx|be the list of |Cx|letters in Cwhich are equal to x, such that k1<k 2< ... < k |Cx|. We replace ckh=xwith c kh=x|h, for h=1,...,|Cx|.Now,ifx∈XA, we consider ih=pj(kh,C,A)∈Ax, for h=1,...,|Cx|, March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
8 and we replace aih=xwith a ih=x|h, as well. Note that, when |Cx|>|Ax|, there are some positions h∈{1,...,|Cx|} for which ihis not defined. On the other hand, when |Cx|<|Ax|, there are some xsymbols in Athat have not been modified. If this is the case, we replace these symbols aih=xwith pairwise different symbols a ih=x|h, for h=|Cx|+1,...,|Ax|. Exactly the same process is applied to the symbols in Bwhich are equal to x. Finally, if there is a symbol x∈XAsuch that x/∈XC, then we replace aih=xwith a ih=x|h, for h=1,...,|Ax|. The same is done for symbols x∈XB−XC. At the end of this process, we have new sequences A=(a 1,...,a nA),B=(b 1,...,b nB) and C=(c 1,...,c nC)such that none of them have repeated symbols. We can therefore apply Proposition 1, to deduce d(A,B)≤d(A,C)+d(B,C). Because of the way in which we have constructed A,B,C,wehaved(A,C)=d(A, C) and d(B,C)=d(B,C). Furthermore, we obviously have d(A, B)≤d(A,B), because maybe the new names assigned to letters in Aand Bdo not correspond with the optimal matching between these two sequences. Summing up, we have d(A, B)≤d(A,B)≤d(A,C)+d(B,C)=d(A, C)+d(B,C), as desired. 1) A Simple Example: Let us take the three sequences A=sender B=reminder C=selected We first construct C’ = s1 e1 l1 e2 c1 t1 e3 d1. To construct A, we take into account the symbols which are common to A and C, which are s,e,d. Only symbol edeserves some attention, because it is repeated in both A and C. The optimal matching between A and C corresponds to new sequence A=s1 e1 n1 d1 e2 r1. This assignment leads to d(A, C)=d(A,C). We do the same for sequence B, obtaining B=r1 e1 m1 i1 n1 d1 e3 r2, which leads to d(B,C)=d(B,C). Obviously, we have d(A, B)≤d(A,B), because the optimal matching between A and B would correspond to A =s1 e1 n1 d1 e2 r2 and B =r1 e1 m1 i1 n1 d1 e2 r2. March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
9 For the exact computation of d(A, B),wehavenAB =nB=8. There are 3 non-common symbols (the sin ‘sender’, and the mand the iin ‘reminder’). They contribute with 3 to the final distance. We then have f(e, A, B)=2/8,f(n, A, B)=2/8,f(d, A, B)=2/8,f(r, A, B)= 1+2/8. Summing up, the distance is d(A, B)=5. On the other hand, one could analogously compute d(A, C) = 6+6/8and d(B,C)=10+2/8. These three distances satisfy the three triangular inequalities. IV. IMPLEMENTATION In this section we show how the OSA distance can be efficiently computed. First of all we need to determine which symbols are common or non-common to each sequence. This can be easily achieved using a vector of bits, one for each possible symbol of alphabet X. Initially the vector is full of zeros and, for each x∈A, its corresponding position in the vector is set to one. Now every symbol of Bis tested against the vector. If the symbol was present in A, we increase the variable common that indicates the number of symbols in A∩B.Ifthe symbol was not present, then we increase a variable non-commonB that represents the number of symbols in B−A. The symmetric variable non-commonA is obtained as nA−common after sequence Bhas been processed. This allows us to compute the d(x, A, B)contributions, when x/∈XA∩XB,inO(nA+nB) time and O(|X|)space. If |X|is very large and |XA∪XB|is comparatively small, then the bit vector can be substituted by a hash table. Finally, we have to explain how to compute the f(x, A, B)value that corresponds to d(x, A, B) for all x∈XA∩XB. This task is more complex, since it involves the computation of the optimal assignment of symbol xpositions, such that their global distance is minimum. To solve this latter problem, we must store the positions of each common symbol. We adopt an even simpler global solution: we keep a vector of positions for each symbol (see Figure 1), not only the common ones. This allows us to reuse the auxiliary structure in subsequent comparisons (see Section IV-D). Using this structure, the non-common symbols are trivially found as before, since the position vector of a given symbol will be non-empty in one of the sequences and empty in the other. Moreover the structure allows solving the optimal alignment problem efficiently, as we explain in Section IV-A. March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
16 the columns from the lower bound of the row to the upper bound determined by min(|Bx|− |Ax|+p, max(qp−1 r+1,qp s)). Since the last cell to be computed in the row is already known, the last if command is useless and can be suppressed. This alternative version of the algorithm computes always less cells than Algorithm 1, using only two additional vectors to store the lower bounds and the qp svalues. However, when compared to Algorithm 1, the performance of the alternative version is better only in some particular scenarios. In general, for strings in which repetitions are not very numerous, the logarithmic factor of the binary search is not so advantageous when compared to the linear scan. In such cases the regularity of memory access of the linear scan can give better performance than the random memory access pattern of the binary search approach, specially if we consider that there are also some additional operations to be performed, like the detection of blocks and the update of lower bounds. On the other hand this alternative version is very suited for scenarios in which there are lots of symbol repetitions and the number of elements that share optimal position is low (i.e. the size of the blocks is small). In Section V-B we will see that this is indeed the case for long DNA sequences. In next section, we will refer to this alternative algorithm as OSA2, whereas we will denote Algorithm 1 as OSA1. We stress that both algorithms output the same value for the OSA distance; therefore, there are no quality differences between using Algorithm OSA1or OSA2. The only measurable difference between them is their execution time. V. EXPERIMENTS AND APPLICABILITY In this section, we describe the experiments that we have carried out to test the performance (running time and quality results) of OSA distance. The general conclusion that we draw from these experiments is that OSA distance is a perfect candidate to be used in situations requiring intensive comparisons of sequences of symbols. First we describe the datasets that we have considered for our experiments. Then we explain a first experiment dealing with very long DNA sequences. After that, we detail some experiments for the record linkage problem. Finally, we explain other situations where the OSA distance could be used. March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
17 A. Database Generation and Computational Environment We have basically run two kinds of experiments: computation of distances between long DNA sequences, and record linkage methods. All the experiments have been performed in an Intel Core2 64 bits CPU (2.13GHz) with 2Gb of RAM memory. We have used C++ compiled with gcc 4.1.2 to implement all the aforementioned distances and algorithms, as well as, the record linkage software needed for performing the experiments described later on. For the experiment related to DNA sequences, we compute the (Edit, OSA, Jaro-Winkler) distance between the complete genome of the Saccharomyces cerevisiae yeast (the mithocondrial genome was taken as one sequence, as well as each one of the yeast chromosomes, for a total of 17 sequences), and the mithocondrial genomes of 129 species [20]. The total number of bases in the Saccharomyces cerevisiae genome is over 12 million, the longest sequence containing about 1.5 million bases. In the other database there are 3M bases, the longest sequence being 0.2 million bases long. For the experiments related to record linkage, we have considered databases with two sizes: 25,000 entries (medium size) and 1 million entries (large size). In order to create a realistic record linkage scenario, we have used names and surnames extracted from a frequency dictionary containing 1,564 names and 13,068 surnames obtained from the Catalan Official Statistics Institute (IDESCAT) [21]. We have generated one database (Dm) containing 25,000 different full names, and another database (Dl) containing 1 million full names. The maximum length of the generated records is 44 symbols. For each of these two original databases, we have generated three duplicated databases, each one corresponding to a different scenario (easy, normal and hard) of insertion of errors. The first one simulates the scenario where names are manually added in the database; in this case, errors are produced by typos or misspellings. The second one simulates the OCR (optical character recognition) scenario where the amount of mistakes is usually larger. Finally, the latter simulates a hard scenario where strings have a high complexity, as for instance, in the Dutch census. The duplicated databases are generated by perturbing each entry of the original database, according to different distributions of the mistakes. For the former case (manual scenario), we have taken the number of errors following a uniform distribution between 1% and 5% of the length of each full name. For the second case (OCR scenario), we follow a uniform distribution March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
18 between 1% and 15% of the length of each full name. Finally, for the latter case (Dutch scenario), we follow a uniform distribution between 1% and 40% of the length of each full name. The considered errors are the following ones: insertions, deletions, updates and swaps, all of them with the same probability of occurrence. The election of these distributions is based on the study developed in [22]. In such study, the author shows that manual typed texts have few mistakes due to typing errors (1-3.2%) and spelling (1.5-2.5%) errors, i.e. around 5% in total. Whereas, text collections digitalized via OCR contain a percentage of errors around 15%. However, as it is also described in this study, in certain scenarios, like typing Dutch surnames (by Dutch), the error rate reaches 38%; this latter case corresponds to our hard scenario. Summing up the generation of databases for our record linkage experiments, we have two original databases Dm and Dl, then three duplicated versions Dm1,Dm 2,Dm 3of Dm, each one with 25,000 entries, and finally three duplicated versions Dl1,Dl 2,Dl 3of Dl, each one with 1 million entries. The two kinds of experiments, with DNA sequences on the one hand and sequences of name and surname on the other hand, provide results for two different situations: long sequences with a short alphabet of 4 symbols (in the DNA case) and short sentences with a larger alphabet of 33 symbols (in the record linkage case). B. Long DNA Sequences Our first experiment has been thought just to compare the running time of the three considered distances in scenarios with very long sequences of symbols. Specifically, we have computed the distance between the complete genome of the Saccharomyces cerevisiae yeast and the mithocondrial genomes of 129 other species. This experiment involves therefore sequences which are millions of symbols long. Table I shows the time that was necessary to compute each of the three distances. The times for Edit and Jaro-Winkler distances are very high. This is not surprising at all, taking into account that the cost of computing the Edit distance is quadratic in the number of symbols, and that the Jaro-Winkler distance was designed to be more efficient for not too long sequences of symbols. Regarding the two implementations of the OSA distance, the results of this experiment confirm that the alternative implementation OSA2is faster than OSA1when the number of symbol March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
19 Distance Time (seconds) Edit 230724.0 (2.67 days) Jaro-Winkler 31513.8 (8.75 hours) OSA192.0 OSA212.5 TABLE I RUNNING TIME TO COMPUTE DNA DISTANCES. repetitions in a sequence is large. We believe that the two proposed implementations of the OSA distance are of independent interest. Note that we have not considered in this experiment any formal quality measure for the behavior of the distances. This will be done in the next section, devoted to record linkage. However, just to confirm our intuition that OSA distance and Edit distance behave quite similarly, we have graphically represented the relation between OSA distance and Edit distance of all pairs of DNA sequences that have been compared in this experiment, in Figure 2. Namely, for each pair s1,s 2of DNA sequences that have been compared, the point (dEdit(s1,s 2),d OSA(s1,s 2)) is added to the graph. C. Record Linkage Record Linkage is a technique widely used for data cleaning [23] and integration of distributed and non-homogeneous databases [24]. Typically, such databases contain information (records) about common individuals that, frequently, do not match due to errors in the data. These errors can be accidentally produced (e.g. typos or misspelling errors) or intentionally provoked (e.g. data anonymization). The goal of record linkage is therefore to compare two databases X,Y and find pairs of records (one in X, one in Y) which correspond to the same individual. A very common approach to this problem is distance-based record linkage: for each record ain one of the databases, one searches the record(s) in the other database that is (are) at minimum distance to a, for some distance defined on the domain of the records. More formally, for all a∈X, the subset March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
20 0 200000 400000 600000 800000 1e+06 1.2e+06 1.4e+06 1.6e+06 0 200000 400000 600000 800000 1e+06 1.2e+06 1.4e+06 1.6e+06 OSA distance Edit distance OSA vs. Edit for DNA Fig. 2. Correlation between Edit distance and OSA distance in the DNA sequences database. Ya={b∈Ys.t. d(a, b)≤d(a, b),∀b∈B}is found. Here d(a, b)is a distance between a record of the database Xand a record of the database Y. In our first experiments, we start with an original dataset X=Dm, Dl, then we consider as the second database Yone of the perturbed versions of X. We denote as ψthe perturbation function that has been used to generate Y, and we denote as a=ψ(a)the elements in Y, for all a∈X. We apply some record linkage algorithm to the pair of databases (X,Y ),by considering as the distance d(a, b)either the Edit distance, or the Jaro-Winkler distance, or the OSA distance. Apart from computing the global running time of this record linkage process, the idea is to measure its quality. This is done by computing the fraction of records a∈Xsuch that the valid perturbed record a∈Y(that we control, because we have generated it) belongs to the subset Yaof records at minimum distance to a. This percentage is denoted as the recall of the record linkage process, which measures the fraction between the number of true positives and the total number of real positives. In our case, recall =|{a∈Xs.t. a∈Ya}| |X| The cardinality of the subset Yais also a quality measure of the record linkage process: assuming that a∈Ya, the smaller Yais, the more successful and efficient the record linkage March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
21 process is. This quality measure is denoted as the precision of the record linkage process; it measures the fraction between the number of true positives and the total number of labeled positives. In our case, precision =|{a∈Xs.t. a∈Ya}| a∈X |Ya| Finally, a measure that combines precision and recall is the F-measure, which is the harmonic mean of precision and recall: F-measure =2·precision ·recall precision +recall In the experiments described in the next sections, we have computed the total running time, the recall, precision and F-measure of each process. We have implemented three different versions of the Edit distance: the classical one with a complexity equal to O(n2), an alternative version that stores only two rows at a time of the dynamic programming table, and the variant presented in [19], with a complexity equal to O(dn), where dis the number of edits for converting one string into the other. The time value presented in the tables is the smallest one. For the Jaro-Winkler distance we have used the implementation provided by the authors, publicly available in [25]. For the OSA distance we have implemented both the alignment algorithm OSA1presented in Section IV-A and its alternative version OSA2of Section IV-E. In all cases the implementations were modified to be as efficient as possible for the record linkage process. That is, memory was allocated only at the beginning; and as many of the auxiliary structures created in previous comparisons as possible were reused. 1) Experiments with Medium Databases: First of all we consider X=Dm as the first dataset, and Y=Dm1,Dm 2,Dm 3as the second database. Since the sizes of these datasets (25,000 records) are medium, we can consider a naive implementation of record linkage (nested loop join) where the element b=arg minb∈Yd(a, b)is found by computing d(a, b)for all b∈Y. This is repeated for all the elements a∈X. Note that this means (25,000)2= 625 millions distance computations. Tables II,III,IV show the results obtained for this record linkage experiment involving mediumsized databases. We can draw the following conclusions from the results in the tables. •As expected, the OSA distance is always the fastest distance, three times faster than the Edit distance and two times faster than the Jaro-Winkler one. Although OSA2is slower than OSA1, it still beats the two other distances. March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
22 Distance Time (s) Recall Precision F-measure Edit 1711.11 0.99996 0.9994 0.99968 Jaro-Winkler 1239.88 0.97412 0.973536 0.973828 OSA1530.14 1 1 1 OSA2774.63 1 1 1 TABLE II RESULTS FOR THE MANUAL SCENARIO,X=Dm AND Y=Dm1. Distance Time (s) Recall Precision F-measure Edit 1712.49 0.99924 0.994704 0.996967 Jaro-Winkler 1248.77 0.82936 0.826023 0.827688 OSA1530.05 0.99452 0.994281 0.9944 OSA2796.46 0.99452 0.994281 0.9944 TABLE III RESULTS FOR THE OCR SCENARIO,X=Dm AND Y=Dm2. •Regarding the quality results, the OSA distance obtains the best results in the manual scenario (Dm1). The results achieved by OSA distance are very similar to the ones obtained by Edit distance in the OCR scenario (Dm2). Note that these two are the most common scenarios in record linkage, where such techniques are used to fix the problems of handmade or OCR database entries. Only in the most difficult scenario (the rare and extreme Dutch one, corresponding to database Dm3) OSA distance obtains really worse results than Edit distance. We would like to emphasize that the quality values obtained by the OSA distance are always better than the ones obtained by Jaro-Winkler distance, which is commonly used in record linkages scenarios. •Summing up, in very hard scenarios where duplicates are very distant from originals, Edit distance is the best choice. For other (maybe more realistic) scenarios, the OSA distance achieves similar or better quality results than Edit distance, but using OSA is three times March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
23 Distance Time (s) Recall Precision F-measure Edit 1715.22 0.91616 0.722205 0.807702 Jaro-Winkler 1261.39 0.33864 0.334969 0.336794 OSA1533.08 0.547 0.538259 0.542594 OSA2772.66 0.547 0.538259 0.542594 TABLE IV RESULTS FOR THE DUTCH SCENARIO,X=Dm AND Y=Dm3. faster than using Edit. In some cases, Edit distance leads to better recall, whereas OSA distance leads to better precision and F-measure. This happens because it is more likely that more than one record in Yachieves the minimum Edit-distance to an original record a, whereas repetitions of OSA distances are more unlikely. Therefore, the cardinal of the set Yathat contains the perturbed records that achieve the minimum distance to the original record ais usually bigger in the Edit distance case than in the OSA distance case. 2) Experiments with Large Databases: Now we consider the large databases: X=Dl as the first dataset, and Y=Dl1,Dl 2,Dl 3as the second database. This means that the two databases contain 1 million records each, and so the naive nested loop join approach would be completely unfeasible in this case. Also, in order to make this problem even more difficult, we consider one unique database Z=X∪Ywhere Y=Dl1,Dl 2,Dl 3. Now, the problem we want to solve is a self join problem instead of a nested one. Usually, this is the kind of problems that cleansing applications face in real scenarios: to find duplicates in a single very large database [26], [27]. Different techniques for saving distance computations in record linkage have been presented in the literature. The main idea is to apply some filtering or partitioning criterion in such a way that very different strings do not need to be compared. Classical methods include blocking and sliding window techniques [28], [29]. The former defines a blocking key and only the records (or strings) sharing such key are compared. The latter sorts the strings using a sorting criterion and then only the strings placed inside a window of a predefined size are compared. The window is normally centered on the record to be linked. These two techniques are usually repeated several times by changing the blocking or sorting criteria. March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
24 Recently, more sophisticated filtering and partitioning methods have been proposed, which use information on the prefixes, lengths, q-grams, etc. of the compared strings. For instance, in [30] authors map the strings into an Euclidean space in order to later perform all the distance computations in this new space; this strategy avoids the costly calculation of many Edit distances. A different approach is proposed in [31], where the matching condition is relaxed to reduce the number of comparisons to be done. A very recent filtering technique, called ed-join, has been presented in [32]. Ed-join uses the q-grams information to discard strings that are a priori too far to form a correct linkage with the considered record. We stress that these methods are designed to solve a different record linkage problem that the one we consider here: similarity joins with respect to a given threshold k. That is, the goal is to find all the pairs of records whose distance is less than k. The above-cited filtering methods, which are specific for the Edit distance, solve this problem without any loss of recall: all the pairs at Edit distance less than kare found. However, in the record linkage problem that we consider here, where the goal is to find the perturbed record that corresponds to a given original record, even these methods have a loss of recall, because maybe the closest record (with respect to Edit) is not the correct answer. Note that recall has two different meanings, in these two record linkage problems. In the above-mentioned record linkage protocols, the total execution time can be divided into two parts: (1) the time required to set up and apply the filtering conditions (q-grams representation, string sorting, etc.), which leads to a set of candidates Zafor each record a∈Z to be linked; and (2) the cost of computing the distances d(a, b), for the candidates b∈Za,in order to obtain the record(s) which is/are closest to each a. Therefore, in principle there is a trade-off between these two running times: if the process spends more time in filtering distant records, then less distances d(a, b)will be computed. This clearly shows that significant differences between the execution times of two different distances (such as Edit and OSA) can have more or less impact on filtering-based record linkage protocols, depending on the time employed in each of the two parts of the linkage process. For example, if the employed filtering technique is very accurate, then most of the global running time of the record linkage process will be devoted to filtering. In this case, there will be no significant difference between using Edit or OSA when computing actual distances (although employing OSA will be always faster). However, if a more naive, simpler and faster filtering technique such as sliding window is employed, then a lot of distance computations will be necessary in March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
25 the second phase of the record linkage process. In this case, there will be significant differences when using Edit or OSA distance. We describe now a set of self-join record linkage experiments that we have executed to discuss this issue. For this new set of experiments, we have discarded the Jaro-Winkler distance because the results obtained in the previous experiments (in an easier scenario) are clearly worse than the ones obtained by Edit and OSA distances. For the OSA distance, we have considered only the first algorithm OSA1because the alternative one OSA2is slower for short strings. On the one hand, we have implemented the classical sliding window algorithm, with both Edit and OSA distances for the second phase, and we have executed such algorithm on the databases Z=X∪Ywhere Y=Dl1,Dl 2,Dl 3. The window size whas been chosen ad-hoc in such a way that the record linkage process has a similar or smaller running time than record linkage with edjoin filtering. We have applied four sorting criteria: lexicographical order for the names and for the reversed names, and lexicographical order for the surnames and for the reversed surnames. A record is compared to all the records that are inside some of the four resulting sliding windows. An execution of this record linkage protocol will be denoted as SlidingWindow(w)+Editor OSA, in Tables V,VI,VII. On the other hand, we have also executed the ed-join record linkage algorithm from [32] 1, using Edit distance for the second phase. The ed-join algorithm has two different parameters. The first one, q, refers to the size of the q-grams considered for the filtering; this parameter usually ranges from 2 to 5. The second parameter, t, refers to the threshold for the distance between two non-filtered records: the set of candidates Zawill contain all the records at distance less or equal than tfrom the corresponding record a. Depending on the values of qand t, the ed-join algorithm discards a large number of records that can have an edit distance lower than t(so they should be checked afterwards), because some of the implemented filters require that the strings have a size larger than q·(t+1)to correctly operate; in these cases, the authors of [32] recommend to repeat the ed-join filtering for these records with a smaller value of q,toachievea better recall. For this reason, an execution of this ed-join record linkage protocol will be denoted in Tables V,VI,VII as Ed-Join(q,t) if only a value of qis considered, or as Ed-Join((q1,q 2),t) if two values of qare considered. 1the original implementation can be downloaded from the web site: http://www.cse.unsw.edu.au/∼weiw/project/simjoin.html March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.
32 Jordi Nin holds a Ph.D. (2008) in Computer Science by the Autonomous University of Barcelona (UAB). He works as a post-doctoral researcher at the Laboratoire d’Analyse et d’Architecture des Syst`emes (LAAS-CNRS) in Toulouse, France. His fields of interests are privacy technologies, machine learning and soft computing tools. He has been involved in several research projects funded by the Catalan and Spanish governments and the European Community. His research has been published in specialized journals and major conferences (around 50 papers). Marc Sol´ eholds a Ph.D. (2009) in Computer Science by the Technical University of Catalonia (UPC), where he is also an Assistant Professor in the Computer Science Faculty of Barcelona. His Ph.D. thesis was focused on automated formal verification of timed concurrent systems. His research interests include formal verification, process mining, data anonymization and UAS. He belongs to the ICARUS research group. March 31, 2010 DRAFT IEEE TRANSACTIONS ON KNOWLEDGE AND DATA ENGINEERING This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication.