public class MathUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static double |
EPSILON
An attempt to fix the value of epsilon used across different applications.
|
Constructor and Description |
---|
MathUtilities() |
Modifier and Type | Method and Description |
---|---|
static double |
beta(double x,
double w)
Get the Beta(x,w)
|
static int |
binomialCoeffs(int n,
int k) |
static boolean |
epsilonEquals(double d1,
double d2)
Check equality of two doubles upto
EPSILON |
static double |
erf(double x) |
static double |
erfc(double x) |
static double |
incompleteGammaP(double a,
double x)
Get the incomplete gamma function P(a,x).
|
static double |
incompleteGammaQ(double a,
double x) |
static double |
lnFactorial(int x)
Get the log of the factorial of a number.
|
static double |
lnGamma(double xx)
Computes log(gamma(xx)).
|
static double |
logAdd(Collection<Double> doubles)
Add a collection of numbers in log space
|
static double |
logAdd(double[] doubles)
Add an array of numbers in log space
|
static double |
logAdd(double x1,
double x2)
Add two numbers in log space.
|
static <T extends Comparable<T>> |
max(Collection<T> list)
Find the argmax and max in a list of elements that can are ordered.
|
static Pair<Integer,Double> |
max(double[] array)
Find the argmax and max in a double array.
|
static Pair<Integer,Integer> |
max(int[] array)
Find the argmax and max in an int array.
|
static <T,S extends Comparable<S>> |
max(Map<T,S> map)
Find the argmax and max in a map from items to values.
|
static <T extends Comparable<T>> |
max(T[] array)
Find the argmax and max in a array of elements that can are ordered.
|
static <T extends Comparable<T>> |
min(Collection<T> list)
Find the argmin and min in a list of elements that can are ordered.
|
static Pair<Integer,Double> |
min(double[] array)
Find the argmin and min in a double array.
|
static Pair<Integer,Integer> |
min(int[] array)
Find the argmin and min in a int array.
|
static <T,S extends Comparable<S>> |
min(Map<T,S> map)
Find the argmin and min in a map from items to values.
|
static <T extends Comparable<T>> |
min(T[] array)
Find the argmin and min in a array of elements that can are ordered.
|
static double[] |
multiply(double[] d,
double m)
Multiply all elements of a double array with a scalar.
|
static double[] |
multiply(double[] d1,
double[] d2)
Elementwise multiplication of two double arrays.
|
static List<Double> |
multiply(List<Double> l,
double m)
Multiply a list of doubles with a scalar
|
static List<Double> |
multiply(List<Double> d1,
List<Double> d2)
Elementwise multiplication of two lists of doubles.
|
static double[] |
softmax(double[] input)
Efficient computation of softmax.
|
static double[] |
softmax(double[] input,
double[] multiplier) |
static List<Double> |
softmax(List<Double> input)
Efficient computation of softmax.
|
static List<Double> |
softmax(List<Double> input,
List<Double> multiplier) |
public static final double EPSILON
public static Pair<Integer,Double> max(double[] array)
public static Pair<Integer,Integer> max(int[] array)
public static <T extends Comparable<T>> Pair<Integer,T> max(Collection<T> list)
public static <T extends Comparable<T>> Pair<Integer,T> max(T[] array)
public static <T,S extends Comparable<S>> Pair<T,S> max(Map<T,S> map)
T
- represents itemsS
- represents values, should be Comparable
public static Pair<Integer,Double> min(double[] array)
public static Pair<Integer,Integer> min(int[] array)
public static <T extends Comparable<T>> Pair<Integer,T> min(Collection<T> list)
public static <T,S extends Comparable<S>> Pair<T,S> min(Map<T,S> map)
T
- represents itemsS
- represents values, should be Comparable
public static <T extends Comparable<T>> Pair<Integer,T> min(T[] array)
public static List<Double> multiply(List<Double> l, double m)
public static List<Double> multiply(List<Double> d1, List<Double> d2)
public static double[] multiply(double[] d1, double[] d2)
public static double[] multiply(double[] d, double m)
public static double[] softmax(double[] input)
public static double[] softmax(double[] input, double[] multiplier)
public static List<Double> softmax(List<Double> input)
public static boolean epsilonEquals(double d1, double d2)
EPSILON
public static double logAdd(double x1, double x2)
Suppose y1 and y2 are two positive reals and let x1 = log(y1) and x2 = log(y2). This function (and the other versions of logAdd) computes log(exp(x1) + exp(x2)) = log(y1 + y2) without underflow or overflow errors. This can be used, for example, to maintain log probabilities without worrying about the probabilities getting too small.
public static double logAdd(double[] doubles)
public static double logAdd(Collection<Double> doubles)
public static double lnGamma(double xx)
public static double lnFactorial(int x)
public static int binomialCoeffs(int n, int k)
public static double beta(double x, double w)
public static double incompleteGammaP(double a, double x)
Wikipedia calls this function the lower incomplete gamma function where the integral is from 0 to x.
public static double incompleteGammaQ(double a, double x)
public static double erf(double x)
public static double erfc(double x)
Copyright © 2017. All rights reserved.