public class MathTricks extends Object
Modifier and Type | Field and Description |
---|---|
static Function |
absFunc
Convenience object for taking the
abs of the
first index |
static Function |
expFunc
Convenience object for taking the
exp of the
first index |
static Function |
invsFunc
Convenience object for taking the inverse (x-1) of the first
index.
|
static Function |
logFunc
Convenience object for taking the
log of the
first index |
static Function |
sqrdFunc
Convenience object for taking the squared value
of the first index
|
static Function |
sqrtFunc
Convenience object for taking the
square root
of the first index |
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 |
public static final Function sqrtFunc
square root
of the first indexpublic static final Function sqrdFunc
public static final Function invsFunc
public static final Function logFunc
log
of the
first indexpublic static final Function expFunc
exp
of the
first indexpublic static double max(double... vals)
vals
- an array of values to get the maximum ofpublic static double min(double... vals)
vals
- an array of values to get the maximum ofpublic static double logSumExp(Vec vals, double maxValue)
vals
- the array of values to exponentiate and addmaxValue
- the maximum value in the arraypublic static double logSumExp(double[] vals, double maxValue)
vals
- the array of values to exponentiate and addmaxValue
- the maximum value in the arraypublic static void softmax(double[] x, boolean implicitExtra)
x
- the array of valuesimplicitExtra
- true
if the softmax will assume there is
an extra implicit value not included in the array with a value of 0.0public static void softmax(Vec x, boolean implicitExtra)
x
- the array of valuesimplicitExtra
- true
if the softmax will assume there is
an extra implicit value not included in the array with a value of 0.0public static double hornerPolyR(double[] coef, double x)
coef
, ie: from
cn at index 0, and then decreasing.coef
- the polynomial with coefficients in reverse orderx
- the value to evaluate the polynomial atx
public static double hornerPoly(double[] coef, double x)
coef
, ie: from
c0 at index 0, and then increasing with the index.coef
- the polynomial with coefficients in reverse orderx
- the value to evaluate the polynomial atx
Copyright © 2017. All rights reserved.