Package opennlp.tools.ml
Class ArrayMath
java.lang.Object
opennlp.tools.ml.ArrayMath
Utility class for simple vector arithmetic.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic intargmax(double[] x) Finds the index of the maximum element in a vectorxstatic doubleinnerProduct(double[] vecA, double[] vecB) static doubleinvL2norm(double[] v) Computes the Inverse L2-norm for a vectorv.static doublel1norm(double[] v) Computes the L1-norm for a vectorv.static doublel2norm(double[] v) Computes the L2-norm for a vectorv.static doublelogSumOfExps(double[] x) Computes\log(\sum_{i=1}^n e^{x_i})using a maximum-element trick to avoid arithmetic overflow.static doublemax(double[] x) Finds the maximum element in a vectorx.static voidsumFeatures(Context[] context, float[] values, double[] prior) static double[]toDoubleArray(List<Double> list) Convert a list ofDoubleobjects into an array of primitive doubles.static int[]toIntArray(List<Integer> list) Convert a list ofIntegerobjects into an array of primitive integers.
- 
Constructor Details- 
ArrayMathpublic ArrayMath()
 
- 
- 
Method Details- 
innerProductpublic static double innerProduct(double[] vecA, double[] vecB) 
- 
l1normpublic static double l1norm(double[] v) Computes the L1-norm for a vectorv.- Parameters:
- v- The vector of- doublevalues.
- Returns:
- The computed L1-norm.
 
- 
l2normpublic static double l2norm(double[] v) Computes the L2-norm for a vectorv.- Parameters:
- v- The vector of- doublevalues.
- Returns:
- The computed L2-norm.
 
- 
invL2normpublic static double invL2norm(double[] v) Computes the Inverse L2-norm for a vectorv.- Parameters:
- v- The vector of- doublevalues.
- Returns:
- The computed Inverse L2-norm.
 
- 
logSumOfExpspublic static double logSumOfExps(double[] x) Computes\log(\sum_{i=1}^n e^{x_i})using a maximum-element trick to avoid arithmetic overflow.- Parameters:
- x- The vector of- doublevalues.
- Returns:
- The log-sum of exponentials of vector elements.
 
- 
maxpublic static double max(double[] x) Finds the maximum element in a vectorx.- Parameters:
- x- The vector of- doublevalues.
- Returns:
- The maximum element in x.
 
- 
argmaxpublic static int argmax(double[] x) Finds the index of the maximum element in a vectorx- Parameters:
- x- The vector of- doublevalues.
- Returns:
- The index of the maximum element. Index of the first maximum element is returned if multiple maximums are found.
 
- 
sumFeatures
- 
toDoubleArrayConvert a list ofDoubleobjects into an array of primitive doubles.- Parameters:
- list- The input vector of- values.
- Returns:
- The double[].
 
- 
toIntArrayConvert a list ofIntegerobjects into an array of primitive integers.- Parameters:
- list- The input vector of- values.
- Returns:
- The int[].
 
 
-