Module ojalgo

Enum DistanceMeasure

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<DistanceMeasure>

    public enum DistanceMeasure
    extends java.lang.Enum<DistanceMeasure>
    Enumeration of common distance and dissimilarity measures for coordinate feature vectors.

    A distance assigns a non-negative number to each pair of points; smaller means more alike. Measures that satisfy the metric axioms (non-negativity; identity of indiscernibles; symmetry; triangle inequality) are metrics; others listed here may be semimetrics but remain useful in practice.

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      ANGULAR
      Angular distance arccos((a·b)/(||a||·||b||)).
      CANBERRA
      Canberra distance: Σ_i |a_i − b_i| / (|a_i| + |b_i|), with 0/0 taken as 0 per term.
      CHEBYSHEV
      Chebyshev (L-infinity) norm – maximum absolute coordinate difference.
      CORRELATION
      Correlation distance defined as 1 − ρ, where ρ is the Pearson correlation between coordinate vectors (after centering).
      COSINE
      Cosine distance defined as 1 − (a·b)/(||a||·||b||).
      EUCLIDEAN
      Euclidean (L2) norm of the coordinate differences; a metric.
      HAMMING
      Hamming distance counts coordinate mismatches; arrays of different length incur the absolute length difference as additional mismatches.
      HELLINGER
      Hellinger distance for non-negative vectors: H = (1/√2) · ||√a − √b||₂.
      JACCARD
      Jaccard distance on the sets of non-zero coordinate indices: 1 − |A ∩ B|/|A ∪ B|.
      MANHATTAN
      Manhattan (L1) norm – sum of absolute coordinate differences; a metric.
      SQUARED_EUCLIDEAN
      Sum of squared coordinate differences.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private DistanceMeasure()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static DistanceMeasure valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static DistanceMeasure[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • ANGULAR

        public static final DistanceMeasure ANGULAR
        Angular distance arccos((a·b)/(||a||·||b||)). A metric on the unit sphere; values in [0, π].
      • CANBERRA

        public static final DistanceMeasure CANBERRA
        Canberra distance: Σ_i |a_i − b_i| / (|a_i| + |b_i|), with 0/0 taken as 0 per term. Emphasises small values; range [0, ∞). A metric under the conventional definition.
      • CHEBYSHEV

        public static final DistanceMeasure CHEBYSHEV
        Chebyshev (L-infinity) norm – maximum absolute coordinate difference.
      • CORRELATION

        public static final DistanceMeasure CORRELATION
        Correlation distance defined as 1 − ρ, where ρ is the Pearson correlation between coordinate vectors (after centering). Invariant to affine scaling per vector. Not a metric in general.
      • COSINE

        public static final DistanceMeasure COSINE
        Cosine distance defined as 1 − (a·b)/(||a||·||b||). Range [0, 2]. Not a metric.
      • EUCLIDEAN

        public static final DistanceMeasure EUCLIDEAN
        Euclidean (L2) norm of the coordinate differences; a metric.
      • HAMMING

        public static final DistanceMeasure HAMMING
        Hamming distance counts coordinate mismatches; arrays of different length incur the absolute length difference as additional mismatches. Range [0, ∞). A metric in its standard domain.
      • HELLINGER

        public static final DistanceMeasure HELLINGER
        Hellinger distance for non-negative vectors: H = (1/√2) · ||√a − √b||₂. For probability vectors it lies in [0, 1] and satisfies the metric axioms.
      • JACCARD

        public static final DistanceMeasure JACCARD
        Jaccard distance on the sets of non-zero coordinate indices: 1 − |A ∩ B|/|A ∪ B|. Range [0, 1]; a metric on sets (binary incidence).
      • MANHATTAN

        public static final DistanceMeasure MANHATTAN
        Manhattan (L1) norm – sum of absolute coordinate differences; a metric.
      • SQUARED_EUCLIDEAN

        public static final DistanceMeasure SQUARED_EUCLIDEAN
        Sum of squared coordinate differences. Common in clustering (e.g. k‑means) because it preserves order with respect to Euclidean and is cheaper to compute, but it is not a metric (triangle inequality fails).
    • Constructor Detail

      • DistanceMeasure

        private DistanceMeasure()
    • Method Detail

      • values

        public static DistanceMeasure[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (DistanceMeasure c : DistanceMeasure.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static DistanceMeasure valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null