jsat.math
Class MathTricks
- java.lang.Object
-
- jsat.math.MathTricks
-
public class MathTricks extends java.lang.ObjectThis 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 doublehornerPoly(double[] coef, double x)This evaluates a polynomial using Horner's method.static doublehornerPolyR(double[] coef, double x)This evaluates a polynomial using Horner's method.static doublelogSumExp(double[] vals, double maxValue)Provides a numerically table way to perform the log of a sum of exponentiations.static doublelogSumExp(Vec vals, double maxValue)Provides a numerically table way to perform the log of a sum of exponentiations.static doublemax(double... vals)static doublemin(double... vals)static voidsoftmax(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 voidsoftmax(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
-
-
-
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 addmaxValue- 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 addmaxValue- 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 valuesimplicitExtra-trueif 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 valuesimplicitExtra-trueif 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 arraycoef, ie: from cn at index 0, and then decreasing.- Parameters:
coef- the polynomial with coefficients in reverse orderx- 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 arraycoef, ie: from c0 at index 0, and then increasing with the index.- Parameters:
coef- the polynomial with coefficients in reverse orderx- the value to evaluate the polynomial at- Returns:
- the value of the polynomial at
x
-
-
DataMelt 3.0 © DataMelt by jWork.ORG