Class MathUtils

java.lang.Object
edu.cmu.tetrad.util.MathUtils

public class MathUtils extends Object
Some extra mathematical functions not contained in org.apache.commons.math3.util.FastMath.
Version:
$Id: $Id
Author:
josephramsey
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    arctanh(double x)
    Computes the inverse hyperbolic tangent (arctanh) of the given input.
    static int
    choose(int a, int b)
    choose.
    static long
    factorial(int n)
    Calculates the factorial of a non-negative integer n.
    static List<Integer>
    getInts(int[] indices)
    Converts a list of indices into a list of Integers representing a cluster.
    static Double
    Applies the Leaky Rectified Linear Unit (Leaky ReLU) activation function to the given input.
    static double
    logChoose(int a, int b)
    logChoose.
    static double
    logFactorial(int n)
    logFactorial.
    static double
    logistic(double x)
    logistic.
    static Double
    Applies the Rectified Linear Unit (ReLU) activation function to the given input.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 int
      b - a int
      Returns:
      a int
    • logChoose

      public static double logChoose(int a, int b)

      logChoose.

      Parameters:
      a - a int
      b - a int
      Returns:
      a double
    • relu

      public static Double relu(Double x)
      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

      public static Double leakyRelu(Double x)
      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

      public static List<Integer> getInts(int[] indices)
      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.