Class ArrayMath

  • Direct Known Subclasses:
    ArrayMath

    public class ArrayMath
    extends java.lang.Object
    Utility class for simple vector arithmetic.
    • Constructor Summary

      Constructors 
      Constructor Description
      ArrayMath()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int argmax​(double[] x)
      Find index of maximum element in the vector x
      static double innerProduct​(double[] vecA, double[] vecB)  
      static double invL2norm​(double[] v)
      Inverse L2-norm
      static double l1norm​(double[] v)
      L1-norm
      static double l2norm​(double[] v)
      L2-norm
      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)  
      static void sumFeatures​(Context[] context, float[] values, double[] prior)  
      static double[] toDoubleArray​(java.util.List<java.lang.Double> list)
      Convert a list of Double objects into an array of primitive doubles
      static int[] toIntArray​(java.util.List<java.lang.Integer> list)
      Convert a list of Integer objects into an array of primitive integers
      • Methods inherited from class java.lang.Object

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

      • ArrayMath

        public ArrayMath()
    • Method Detail

      • innerProduct

        public static double innerProduct​(double[] vecA,
                                          double[] vecB)
      • l1norm

        public static double l1norm​(double[] v)
        L1-norm
      • l2norm

        public static double l2norm​(double[] v)
        L2-norm
      • invL2norm

        public static double invL2norm​(double[] v)
        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 - input vector
        Returns:
        log-sum of exponentials of vector elements
      • max

        public static double max​(double[] x)
      • argmax

        public static int argmax​(double[] x)
        Find index of maximum element in the vector x
        Parameters:
        x - input vector
        Returns:
        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​(java.util.List<java.lang.Double> list)
        Convert a list of Double objects into an array of primitive doubles
      • toIntArray

        public static int[] toIntArray​(java.util.List<java.lang.Integer> list)
        Convert a list of Integer objects into an array of primitive integers