Class Distance

java.lang.Object
ubic.basecode.math.Distance

public class Distance extends Object
Alternative distance and similarity metrics for vectors.
Author:
Paul Pavlidis
  • 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 vector
      ye - A standardized vector
      Returns:
      Pearson correlation coefficient.
    • correlationOfStandardized

      public static double correlationOfStandardized(DoubleArrayList x, DoubleArrayList y)
      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 vector
      y - A standardized vector
      Returns:
      The Pearson correlation between x and y.
    • euclDistance

      public static double euclDistance(DoubleArrayList x, DoubleArrayList y)
      Calculate the Euclidean distance between two vectors.
      Parameters:
      x - DoubleArrayList
      y - DoubleArrayList
      Returns:
      Euclidean distance between x and y
    • manhattanDistance

      public static double manhattanDistance(DoubleArrayList x, DoubleArrayList y)
      Calculate the Manhattan distance between two vectors.
      Parameters:
      x - DoubleArrayList
      y - DoubleArrayList
      Returns:
      Manhattan distance between x and y
    • spearmanRankCorrelation

      public static double spearmanRankCorrelation(DoubleArrayList x)
      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

      public static double spearmanRankCorrelation(DoubleArrayList x, DoubleArrayList y)
      Spearman Rank Correlation. This does the rank transformation of the data. Only mutually non-NaN values are used.
      Parameters:
      x - DoubleArrayList
      y - DoubleArrayList
      Returns:
      Spearman's rank correlation between x and y or NaN if it could not be computed.