Class Utils

Object
org.apache.spark.ml.impl.Utils

public class Utils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
     
    static int
    indexUpperTriangular(int n, int i, int j)
    Indexing in an array representing the upper triangular part of a matrix into an n * n array representing the full symmetric matrix (column major).
    static double
    log1pExp(double x)
    When x is positive and large, computing math.log(1 + math.exp(x)) will lead to arithmetic overflow.
    static void
    softmax(double[] array)
    Perform in-place softmax conversion.
    static void
    softmax(double[] input, int n, int offset, int step, double[] output)
    Perform softmax conversion.
    static double[]
    unpackUpperTriangular(int n, double[] triangularValues)
    Convert an n * (n + 1) / 2 dimension array representing the upper triangular part of a matrix into an n * n array representing the full symmetric matrix (column major).

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • EPSILON

      public static double EPSILON()
    • unpackUpperTriangular

      public static double[] unpackUpperTriangular(int n, double[] triangularValues)
      Convert an n * (n + 1) / 2 dimension array representing the upper triangular part of a matrix into an n * n array representing the full symmetric matrix (column major).

      Parameters:
      n - The order of the n by n matrix.
      triangularValues - The upper triangular part of the matrix packed in an array (column major).
      Returns:
      A dense matrix which represents the symmetric matrix in column major.
    • indexUpperTriangular

      public static int indexUpperTriangular(int n, int i, int j)
      Indexing in an array representing the upper triangular part of a matrix into an n * n array representing the full symmetric matrix (column major). val symmetricValues = unpackUpperTriangularMatrix(n, triangularValues) val matrix = new DenseMatrix(n, n, symmetricValues) val index = indexUpperTriangularMatrix(n, i, j) then: symmetricValues(index) == matrix(i, j)

      Parameters:
      n - The order of the n by n matrix.
      i - (undocumented)
      j - (undocumented)
      Returns:
      (undocumented)
    • log1pExp

      public static double log1pExp(double x)
      When x is positive and large, computing math.log(1 + math.exp(x)) will lead to arithmetic overflow. This will happen when x > 709.78 which is not a very large number. It can be addressed by rewriting the formula into x + math.log1p(math.exp(-x)) when x is positive.
      Parameters:
      x - a floating-point value as input.
      Returns:
      the result of math.log(1 + math.exp(x)).
    • softmax

      public static void softmax(double[] array)
      Perform in-place softmax conversion.
      Parameters:
      array - (undocumented)
    • softmax

      public static void softmax(double[] input, int n, int offset, int step, double[] output)
      Perform softmax conversion.
      Parameters:
      input - (undocumented)
      n - (undocumented)
      offset - (undocumented)
      step - (undocumented)
      output - (undocumented)