- Research Article
- 10.1109/access.2025.3639297
Computing Hamming Distance and Levenshtein Distance Using ReLU Neural Networks
- Jan 01, 2025
- IEEE Access
- Masahiro Ohtomo + 2 more +2
Measuring the similarity or difference of two strings is a fundamental task in computer science and engineering. Among the various measures, Hamming distance and Levenshtein distance have been widely utilized. In this paper, we present neural networks for computing these distances, employing the Rectified Linear Unit function as the activation function. We show that the number of units in the networks is <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">O(n)</i> for the Hamming distance between two strings of length <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">n</i>, and <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">O(mn)</i> for the Levenshtein distance between two strings of lengths <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">m</i> and <italic xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">n</i>. These complexities align with those of traditional algorithms. While the depth of the latter network is large (O(m+n)), we show that the depth can be significantly reduced at the expense of employing a larger number of units. Furthermore, we show that the networks can be modified for learning a string from a set of strings along with their respective distances to the target string. We performed computational experiments to evaluate the potential usufulness of our proposed networks. The results suggest that these networks can efficiently compute distances in a time proportional to the network size, and can proficiently learn a string when utilizing the Hamming distance.
Read more