Documentation of 'smile.math.distance.EditDistance' Java class
EditDistance
smile.math.distance

Class EditDistance

  • All Implemented Interfaces:
    java.io.Serializable, Distance<java.lang.String>, Metric<java.lang.String>


    public class EditDistance
    extends java.lang.Object
    implements Metric<java.lang.String>, java.io.Serializable
    The Edit distance between two strings is a metric for measuring the amount of difference between two sequences. The Levenshtein distance between two strings is given by the minimum number of operations needed to transform one string into the other, where an operation is an insertion, deletion, or substitution of a single character. A generalization of the Levenshtein distance (Damerau-Levenshtein distance) allows the transposition of two characters as an operation.

    Given two strings x and y of length m and n (suppose n ≥ m), this implementation takes O(ne) time and O(mn) space by an extended Ukkonen's algorithm in case of unit cost, where e is the edit distance between x and y. Thus this algorithm is output sensitive. The smaller the distance, the faster it runs.

    For weighted cost, this implements the regular dynamic programming algorithm, which takes O(mn) time and O(m) space.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor and Description
      EditDistance(double[][] weight)
      Constructor.
      EditDistance(double[][] weight, double radius)
      Constructor.
      EditDistance(int maxStringLength)
      Constructor.
      EditDistance(int maxStringLength, boolean damerau)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      double d(char[] x, char[] y)
      Edit distance between two strings.
      double d(java.lang.String x, java.lang.String y)
      Edit distance between two strings.
      static int damerau(char[] x, char[] y)
      Damerau-Levenshtein distance between two strings allows insertion, deletion, substitution, or transposition of characters.
      static int damerau(java.lang.String x, java.lang.String y)
      Damerau-Levenshtein distance between two strings allows insertion, deletion, substitution, or transposition of characters.
      static int levenshtein(char[] x, char[] y)
      Levenshtein distance between two strings allows insertion, deletion, or substitution of characters.
      static int levenshtein(java.lang.String x, java.lang.String y)
      Levenshtein distance between two strings allows insertion, deletion, or substitution of characters.
      java.lang.String toString() 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • EditDistance

        public EditDistance(double[][] weight)
        Constructor. Weighted Levenshtein distance without path constraints. Only insertion, deletion, and substitution operations are supported.
      • EditDistance

        public EditDistance(double[][] weight,
                            double radius)
        Constructor. Weighted Levenshtein distance with Sakoe-Chiba band, which improve computational cost. Only insertion, deletion, and substitution operations are supported.
        Parameters:
        radius - the window width of Sakoe-Chiba band in terms of percentage of sequence length.
      • EditDistance

        public EditDistance(int maxStringLength)
        Constructor. Unit cost edit distance.
        Parameters:
        maxStringLength - the maximum length of strings that will be feed to this algorithm.
      • EditDistance

        public EditDistance(int maxStringLength,
                            boolean damerau)
        Constructor. Damerau-Levenshtein distance.
        Parameters:
        maxStringLength - the maximum length of strings that will be feed to this algorithm.
        damerau - if true, calculate Damerau-Levenshtein distance instead of plain Levenshtein distance.
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • d

        public double d(java.lang.String x,
                        java.lang.String y)
        Edit distance between two strings. O(mn) time and O(n) space for weighted edit distance. O(ne) time and O(mn) space for unit cost edit distance. For weighted edit distance, this method is multi-thread safe. However, it is NOT multi-thread safe for unit cost edit distance.
        Specified by:
        d in interface Distance<java.lang.String>
      • d

        public double d(char[] x,
                        char[] y)
        Edit distance between two strings. O(mn) time and O(n) space for weighted edit distance. O(ne) time and O(mn) space for unit cost edit distance. For weighted edit distance, this method is multi-thread safe. However, it is NOT multi-thread safe for unit cost edit distance.
      • levenshtein

        public static int levenshtein(java.lang.String x,
                                      java.lang.String y)
        Levenshtein distance between two strings allows insertion, deletion, or substitution of characters. O(mn) time and O(n) space. Multi-thread safe.
      • levenshtein

        public static int levenshtein(char[] x,
                                      char[] y)
        Levenshtein distance between two strings allows insertion, deletion, or substitution of characters. O(mn) time and O(n) space. Multi-thread safe.
      • damerau

        public static int damerau(java.lang.String x,
                                  java.lang.String y)
        Damerau-Levenshtein distance between two strings allows insertion, deletion, substitution, or transposition of characters. O(mn) time and O(n) space. Multi-thread safe.
      • damerau

        public static int damerau(char[] x,
                                  char[] y)
        Damerau-Levenshtein distance between two strings allows insertion, deletion, substitution, or transposition of characters. O(mn) time and O(n) space. Multi-thread safe.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.