Package edu.cmu.tetrad.util
Class MathUtils
java.lang.Object
edu.cmu.tetrad.util.MathUtils
Some extra mathematical functions not contained in org.apache.commons.math3.util.FastMath.
- Version:
- $Id: $Id
- Author:
- josephramsey
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublearctanh(double x) Computes the inverse hyperbolic tangent (arctanh) of the given input.static intchoose(int a, int b) choose.static longfactorial(int n) Calculates the factorial of a non-negative integer n.getInts(int[] indices) Converts a list of indices into a list of Integers representing a cluster.static DoubleApplies the Leaky Rectified Linear Unit (Leaky ReLU) activation function to the given input.static doublelogChoose(int a, int b) logChoose.static doublelogFactorial(int n) logFactorial.static doublelogistic(double x) logistic.static DoubleApplies the Rectified Linear Unit (ReLU) activation function to the given input.
-
Method Details
-
logistic
public static double logistic(double x) logistic.
- Parameters:
x- a double value.- Returns:
- the logistic function of x = 1 / (1 + exp(-x)).
-
factorial
public static long factorial(int n) Calculates the factorial of a non-negative integer n. The factorial of n (denoted as n!) is the product of all positive integers less than or equal to n. By definition, the factorial of 0 is 1.- Parameters:
n- the non-negative integer for which the factorial is to be calculated- Returns:
- the factorial of the given integer n as a long value
- Throws:
IllegalArgumentException- if n is negative
-
logFactorial
public static double logFactorial(int n) logFactorial.
- Parameters:
n- a int- Returns:
- a double
-
choose
public static int choose(int a, int b) choose.
- Parameters:
a- a intb- a int- Returns:
- a int
-
logChoose
public static double logChoose(int a, int b) logChoose.
- Parameters:
a- a intb- a int- Returns:
- a double
-
relu
Applies the Rectified Linear Unit (ReLU) activation function to the given input. ReLU is defined as max(0, x).- Parameters:
x- the input value to which the ReLU function is applied- Returns:
- the result of applying the ReLU function, which is the input if it is positive, or 0 otherwise
-
leakyRelu
Applies the Leaky Rectified Linear Unit (Leaky ReLU) activation function to the given input. Leaky ReLU is defined as max(0.1 * x, x). It allows for a small, non-zero gradient when the unit is not active.- Parameters:
x- the input value to which the Leaky ReLU function is applied- Returns:
- the result of applying the Leaky ReLU function, which is x if x is positive, or 0.1 * x otherwise
-
arctanh
public static double arctanh(double x) Computes the inverse hyperbolic tangent (arctanh) of the given input. The input value must be strictly between -1 and 1.- Parameters:
x- the input value for which to calculate the arctanh. Must be between -1 and 1 (exclusive).- Returns:
- the arctanh of the specified input.
- Throws:
IllegalArgumentException- if the input is not strictly within the range (-1, 1).
-
getInts
Converts a list of indices into a list of Integers representing a cluster.- Parameters:
indices- The indices of the variables.- Returns:
- The extracted index list.
-