Class NearnessMeasure

  • All Implemented Interfaces:
    Serializable

    public abstract class NearnessMeasure
    extends Object
    implements Serializable
    Determines how to measure how near an example and query record are to each other.
    See Also:
    Serialized Form
    • Constructor Detail

      • NearnessMeasure

        public NearnessMeasure()
    • Method Detail

      • newMeasurer

        public abstract NearnessMeasure.Measurer newMeasurer()
        Creates a new measurer for use.
        Returns:
        a new measure calculator
      • nearnessToDistance

        public abstract double nearnessToDistance​(double n)
        Converts a "nearness" value to a "real" distance. This allows avoidance of expensive computations in determining how near two points are to one another.

        For example, in Euclidean distance, a square root is required to obtain the actual distance. However, the squared distance provides exactly the same ordering as the true distance, so can be used as the "nearness". If the true distance is required, it can be derived on an as needed basis.

        Parameters:
        n - the "nearness" value returned by a measurer
        Returns:
        the actual distance between the points
      • cosine

        public static NearnessMeasure cosine()
        Measures nearness using cosine similarity.

        Results in the range [0,-1] have no clear interpretation of "nearness". In this implementation, 0 is arbitrarily considered "nearer" than -1. Due to this ambiguity, this measure is best used when the values of features are non-negative, ensuring results in the range [1,0] for which the interpretation of "nearer" is clear.

        Returns:
        a measurement based on cosine similarity
      • euclidean

        public static NearnessMeasure euclidean()
        Measures nearness using Euclidean distance.
        Returns:
        a measurement based on Euclidean distance