Documentation of 'jsat.math.MathTricks' Java class
MathTricks
jsat.math

Class MathTricks



  • public class MathTricks
    extends java.lang.Object
    This class provides utilities for performing specific arithmetic patterns in numerically stable / efficient ways.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static double hornerPoly(double[] coef, double x)
      This evaluates a polynomial using Horner's method.
      static double hornerPolyR(double[] coef, double x)
      This evaluates a polynomial using Horner's method.
      static double logSumExp(double[] vals, double maxValue)
      Provides a numerically table way to perform the log of a sum of exponentiations.
      static double logSumExp(Vec vals, double maxValue)
      Provides a numerically table way to perform the log of a sum of exponentiations.
      static double max(double... vals) 
      static double min(double... vals) 
      static void softmax(double[] x, boolean implicitExtra)
      Applies the softmax function to the given array of values, normalizing them so that each value is equal to

      exp(xj) / Σ∀ i exp(xi)
      static void softmax(Vec x, boolean implicitExtra)
      Applies the softmax function to the given array of values, normalizing them so that each value is equal to

      exp(xj) / Σ∀ i exp(xi)
      Note: If the input is sparse, this will end up destroying sparsity
      • Methods inherited from class java.lang.Object

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

      • max

        public static double max(double... vals)
        Parameters:
        vals - an array of values to get the maximum of
        Returns:
        the maximum of all given values
      • min

        public static double min(double... vals)
        Parameters:
        vals - an array of values to get the maximum of
        Returns:
        the maximum of all given values
      • logSumExp

        public static double logSumExp(Vec vals,
                                       double maxValue)
        Provides a numerically table way to perform the log of a sum of exponentiations. The computed result is
        log( ∀ val ∈ vals exp(val) )
        Parameters:
        vals - the array of values to exponentiate and add
        maxValue - the maximum value in the array
        Returns:
        the log of the sum of the exponentiated values
      • logSumExp

        public static double logSumExp(double[] vals,
                                       double maxValue)
        Provides a numerically table way to perform the log of a sum of exponentiations. The computed result is
        log( ∀ val ∈ vals exp(val) )
        Parameters:
        vals - the array of values to exponentiate and add
        maxValue - the maximum value in the array
        Returns:
        the log of the sum of the exponentiated values
      • softmax

        public static void softmax(double[] x,
                                   boolean implicitExtra)
        Applies the softmax function to the given array of values, normalizing them so that each value is equal to

        exp(xj) / Σ∀ i exp(xi)
        Parameters:
        x - the array of values
        implicitExtra - true if the softmax will assume there is an extra implicit value not included in the array with a value of 0.0
      • softmax

        public static void softmax(Vec x,
                                   boolean implicitExtra)
        Applies the softmax function to the given array of values, normalizing them so that each value is equal to

        exp(xj) / Σ∀ i exp(xi)
        Note: If the input is sparse, this will end up destroying sparsity
        Parameters:
        x - the array of values
        implicitExtra - true if the softmax will assume there is an extra implicit value not included in the array with a value of 0.0
      • hornerPolyR

        public static double hornerPolyR(double[] coef,
                                         double x)
        This evaluates a polynomial using Horner's method. It is assumed that the polynomial is stored in reverse order in the array coef, ie: from cn at index 0, and then decreasing.
        Parameters:
        coef - the polynomial with coefficients in reverse order
        x - the value to evaluate the polynomial at
        Returns:
        the value of the polynomial at x
      • hornerPoly

        public static double hornerPoly(double[] coef,
                                        double x)
        This evaluates a polynomial using Horner's method. It is assumed that the polynomial is stored in order in the array coef, ie: from c0 at index 0, and then increasing with the index.
        Parameters:
        coef - the polynomial with coefficients in reverse order
        x - the value to evaluate the polynomial at
        Returns:
        the value of the polynomial at x

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.