java.lang.Object
com.pervasive.datarush.analytics.knn.NearnessMeasure
- All Implemented Interfaces:
Serializable
Determines how to measure how near an example and query record are
to each other.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA calculator of "nearness". -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic NearnessMeasurecosine()Measures nearness using cosine similarity.static NearnessMeasureMeasures nearness using Euclidean distance.abstract doublenearnessToDistance(double n) Converts a "nearness" value to a "real" distance.abstract NearnessMeasure.MeasurerCreates a new measurer for use.
-
Constructor Details
-
NearnessMeasure
public NearnessMeasure()
-
-
Method Details
-
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
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
Measures nearness using Euclidean distance.- Returns:
- a measurement based on Euclidean distance
-