public final class ExactMatchDistance extends Object
ExactMatch distance (or Hamming Distance) of a pair of non-binary strings (or more generally sequences) is the number of sequence (or string) positions where the two sequences differ. This class supports comparison of Java String objects, as well as comparisons of arrays of any of Java's eight primitive types, and arrays of any object type. It is the count of the number of positions for which the two sequences contain different elements.
Most other implementations of Hamming distance require the two strings to be of the same length. Ours does not. If the two sequences (i.e., arrays or Strings) are of different lengths, then the difference in length affects distance. E.g., although "abbd" is a distance of 1 from "abcd" since they differ in one position, "abbd" is a distance of 4 from "abcdefg" (the one difference, plus the three extra characters).
Runtime: O(n), where n is the length of the shorter of the two sequences.
If your sequences are guaranteed not to have duplicates, and to contain the same set of elements, then consider instead using the
ExactMatchDistance class, which assumes permutations of the integers from 0 to N-1.
Exact match distance was introduced specifically for permutations in:
S. Ronald, "More distance functions for order-based encodings," in Proc. IEEE CEC. IEEE Press, 1998, pp. 558–563.
| Constructor and Description |
|---|
ExactMatchDistance()
Constructs the distance measurer as specified in the class documentation.
|
| Modifier and Type | Method and Description |
|---|---|
int |
distance(boolean[] s1,
boolean[] s2)
Measures the distance between two arrays.
|
int |
distance(byte[] s1,
byte[] s2)
Measures the distance between two arrays.
|
int |
distance(char[] s1,
char[] s2)
Measures the distance between two arrays.
|
int |
distance(double[] s1,
double[] s2)
Measures the distance between two arrays.
|
int |
distance(float[] s1,
float[] s2)
Measures the distance between two arrays.
|
int |
distance(int[] s1,
int[] s2)
Measures the distance between two arrays.
|
<T> int |
distance(List<T> s1,
List<T> s2)
Measures the distance between two lists of objects.
|
int |
distance(long[] s1,
long[] s2)
Measures the distance between two arrays.
|
int |
distance(Object[] s1,
Object[] s2)
Measures the distance between two arrays of objects.
|
int |
distance(short[] s1,
short[] s2)
Measures the distance between two arrays.
|
int |
distance(String s1,
String s2)
Measures the distance between two Strings.
|
double |
distancef(boolean[] s1,
boolean[] s2)
Measures the distance between two arrays.
|
double |
distancef(byte[] s1,
byte[] s2)
Measures the distance between two arrays.
|
double |
distancef(char[] s1,
char[] s2)
Measures the distance between two arrays.
|
double |
distancef(double[] s1,
double[] s2)
Measures the distance between two arrays.
|
double |
distancef(float[] s1,
float[] s2)
Measures the distance between two arrays.
|
double |
distancef(int[] s1,
int[] s2)
Measures the distance between two arrays.
|
<T> double |
distancef(List<T> s1,
List<T> s2)
Measures the distance between two lists of objects.
|
double |
distancef(long[] s1,
long[] s2)
Measures the distance between two arrays.
|
double |
distancef(Object[] s1,
Object[] s2)
Measures the distance between two arrays of objects.
|
double |
distancef(short[] s1,
short[] s2)
Measures the distance between two arrays.
|
double |
distancef(String s1,
String s2)
Measures the distance between two Strings.
|
public ExactMatchDistance()
public int distance(int[] s1,
int[] s2)
s1 - First array.s2 - Second array.public int distance(long[] s1,
long[] s2)
s1 - First array.s2 - Second array.public int distance(short[] s1,
short[] s2)
s1 - First array.s2 - Second array.public int distance(byte[] s1,
byte[] s2)
s1 - First array.s2 - Second array.public int distance(char[] s1,
char[] s2)
s1 - First array.s2 - Second array.public int distance(boolean[] s1,
boolean[] s2)
s1 - First array.s2 - Second array.public int distance(double[] s1,
double[] s2)
s1 - First array.s2 - Second array.public int distance(float[] s1,
float[] s2)
s1 - First array.s2 - Second array.public int distance(String s1, String s2)
s1 - First String.s2 - Second String.public int distance(Object[] s1, Object[] s2)
s1 - First array.s2 - Second array.public <T> int distance(List<T> s1, List<T> s2)
T - Type of List elements.s1 - First list.s2 - Second list.public final double distancef(long[] s1,
long[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(int[] s1,
int[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(short[] s1,
short[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(byte[] s1,
byte[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(char[] s1,
char[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(double[] s1,
double[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(float[] s1,
float[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(boolean[] s1,
boolean[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final double distancef(String s1, String s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First String.s2 - Second String.public final double distancef(Object[] s1, Object[] s2)
distancef in interface SequenceDistanceMeasurerDoubles1 - First array.s2 - Second array.public final <T> double distancef(List<T> s1, List<T> s2)
distancef in interface SequenceDistanceMeasurerDoubleT - Type of List elements.s1 - First list.s2 - Second list.Copyright © 2005-2020 Vincent A. Cicirello. All rights reserved.