ArrayMath (Apache OpenNLP Tools 2.5.9 API)
Description: declaration: package: opennlp.tools.ml, class: ArrayMath

# Class ArrayMath

java.lang.Object
opennlp.tools.ml.ArrayMath

public class ArrayMath extends Object
Utility class for simple vector arithmetic.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ArrayMath()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static int`
  `argmax(double[] x)`
  Finds the index of the maximum element in a vector `x`
  `static double`
  `innerProduct(double[] vecA, double[] vecB)`
  `static double`
  `invL2norm(double[] v)`
  Computes the Inverse L2-norm for a vector `v`.
  `static double`
  `l1norm(double[] v)`
  Computes the L1-norm for a vector `v`.
  `static double`
  `l2norm(double[] v)`
  Computes the L2-norm for a vector `v`.
  `static double`
  `logSumOfExps(double[] x)`
  Computes `\log(\sum_{i=1}^n e^{x_i})` using a maximum-element trick to avoid arithmetic overflow.
  `static double`
  `max(double[] x)`
  Finds the maximum element in a vector `x`.
  `static void`
  `sumFeatures(Context[] context, float[] values, double[] prior)`
  `static double[]`
  `toDoubleArray(List<Double> list)`
  Convert a list of `Double` objects into an array of primitive doubles.
  `static int[]`
  `toIntArray(List<Integer> list)`
  Convert a list of `Integer` objects into an array of primitive integers.

  ### Methods inherited from class Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ArrayMath

    public ArrayMath()

- ## Method Details

  - ### innerProduct

    public static double innerProduct(double[] vecA, double[] vecB)

  - ### l1norm

    public static double l1norm(double[] v)
    Computes the L1-norm for a vector `v`.
    Parameters:
      `v` - The vector of `double` values.
    Returns:
      The computed L1-norm.

  - ### l2norm

    public static double l2norm(double[] v)
    Computes the L2-norm for a vector `v`.
    Parameters:
      `v` - The vector of `double` values.
    Returns:
      The computed L2-norm.

  - ### invL2norm

    public static double invL2norm(double[] v)
    Computes the Inverse L2-norm for a vector `v`.
    Parameters:
      `v` - The vector of `double` values.
    Returns:
      The computed Inverse L2-norm.

  - ### logSumOfExps

    public 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 `double` values.
    Returns:
      The log-sum of exponentials of vector elements.

  - ### max

    public static double max(double[] x)
    Finds the maximum element in a vector `x`.
    Parameters:
      `x` - The vector of `double` values.
    Returns:
      The maximum element in `x`.

  - ### argmax

    public static int argmax(double[] x)
    Finds the index of the maximum element in a vector `x`
    Parameters:
      `x` - The vector of `double` values.
    Returns:
      The index of the maximum element. Index of the first maximum element is returned if multiple maximums are found.

  - ### sumFeatures

    public static void sumFeatures(Context[] context, float[] values, double[] prior)

  - ### toDoubleArray

    public static double[] toDoubleArray(List<Double> list)
    Convert a list of `Double` objects into an array of primitive doubles.
    Parameters:
      `list` - The input vector of `values`.
    Returns:
      The `double[]`.

  - ### toIntArray

    public static int[] toIntArray(List<Integer> list)
    Convert a list of `Integer` objects into an array of primitive integers.
    Parameters:
      `list` - The input vector of `values`.
    Returns:
      The `int[]`.