Package ubic.basecode.math
Class Distance
java.lang.Object
ubic.basecode.math.Distance
Alternative distance and similarity metrics for vectors.
- Author:
- Paul Pavlidis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
correlationOfStandardized
(double[] xe, double[] ye) Highly optimized implementation of the Pearson correlation.static double
Like correlationofNormedFast, but takes DoubleArrayLists as inputs, handles missing values correctly, and does more error checking.static double
Calculate the Euclidean distance between two vectors.static double
Calculate the Manhattan distance between two vectors.static double
Convenience function to compute the rank correlation when we just want to know if the values are "in order".static double
Spearman Rank Correlation.
-
Constructor Details
-
Distance
public Distance()
-
-
Method Details
-
correlationOfStandardized
public static double correlationOfStandardized(double[] xe, double[] ye) Highly optimized implementation of the Pearson correlation. The inputs must be standardized - mean zero, variance one, without any missing values.- Parameters:
xe
- A standardized vectorye
- A standardized vector- Returns:
- Pearson correlation coefficient.
-
correlationOfStandardized
Like correlationofNormedFast, but takes DoubleArrayLists as inputs, handles missing values correctly, and does more error checking. Assumes the data has been converted to z scores already.- Parameters:
x
- A standardized vectory
- A standardized vector- Returns:
- The Pearson correlation between x and y.
-
euclDistance
Calculate the Euclidean distance between two vectors.- Parameters:
x
- DoubleArrayListy
- DoubleArrayList- Returns:
- Euclidean distance between x and y
-
manhattanDistance
Calculate the Manhattan distance between two vectors.- Parameters:
x
- DoubleArrayListy
- DoubleArrayList- Returns:
- Manhattan distance between x and y
-
spearmanRankCorrelation
Convenience function to compute the rank correlation when we just want to know if the values are "in order". Values in perfect ascending order are a correlation of 1, descending is -1.- Parameters:
x
-- Returns:
-
spearmanRankCorrelation
Spearman Rank Correlation. This does the rank transformation of the data. Only mutually non-NaN values are used.- Parameters:
x
- DoubleArrayListy
- DoubleArrayList- Returns:
- Spearman's rank correlation between x and y or NaN if it could not be computed.
-