Package org.apache.spark.ml.impl
Class Utils
Object
org.apache.spark.ml.impl.Utils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
EPSILON()
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) Whenx
is positive and large, computingmath.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).
-
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) Whenx
is positive and large, computingmath.log(1 + math.exp(x))
will lead to arithmetic overflow. This will happen whenx > 709.78
which is not a very large number. It can be addressed by rewriting the formula intox + math.log1p(math.exp(-x))
whenx
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)
-