Class MathTools


  • public class MathTools
    extends Object
    MathTools contains a set of commonly used mathematical functions, that are not provided by the Java libraries.
    • Field Detail

      • EPSILON_ERROR

        public static final double EPSILON_ERROR
        Difference up to which two values are considered as equal.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MathTools

        public MathTools()
    • Method Detail

      • gcd

        public static double gcd​(List<Double> numbers)
        Computes the greatest common divisor (GDC) of a set of numbers.
        Parameters:
        numbers - List of numbers for which the GDC shall be computed.
        Returns:
        Returns the greatest common divisor of all numbers
      • gcd

        public static double gcd​(double x,
                                 double y)
        Computes something similar to the greatest common divisor (GCD) of two numbers. Note that the GCD for two doubles is calculates, which is different to the standard definition of GCD.
        Parameters:
        x - first number
        y - second number
        Returns:
        Returns the GDC of y and x.
      • transformComplexToDouble

        public static List<Double> transformComplexToDouble​(List<org.apache.commons.math.complex.Complex> values)
        Transforms a list of complex values to a list of double values by throwing away the imaginary part.
        Parameters:
        values - List of complex values to transform.
        Returns:
        The real part of the value list as doubles.
      • transformDoubleToComplex

        public static List<org.apache.commons.math.complex.Complex> transformDoubleToComplex​(List<Double> values)
        Transforms a list of double values to a list of complex values. The real parts are set to the values in the list, the imaginary part is set to zero.
        Parameters:
        values - List of double values to transform.
        Returns:
        A list of complex values equivalent to the doubles.
      • equalsDouble

        public static boolean equalsDouble​(double d1,
                                           double d2)
        Compares two doubles.
        Parameters:
        d1 -
        d2 -
        Returns:
        True, if the difference between both values is lower than EPSILON_ERROR; false otherwise.
      • equalsComplex

        public static boolean equalsComplex​(org.apache.commons.math.complex.Complex z1,
                                            org.apache.commons.math.complex.Complex z2)
      • sumOfCountinuousSamples

        public static double sumOfCountinuousSamples​(List<IContinuousSample> list)
        Compute the sum of probabilities associated with a set of IContinuousSamples.
        Parameters:
        list -
        Returns:
        the computed value.
      • sumOfSamples

        public static double sumOfSamples​(List<ISample> list)
        Compute the sum of probabilities associated with a set of ISamples.
        Parameters:
        list -
        Returns:
        the computed value.
      • sumOfDoubles

        public static double sumOfDoubles​(List<Double> list)
        Compute the sum of a set Doubles.
        Parameters:
        list -
        Returns:
        the computed value.
      • computeCumulativeProbabilities

        public static List<Double> computeCumulativeProbabilities​(List<Double> probabilityList)
        Returns the cumulative probabilities of the list of input probabilities. The size of the result list might be smaller than the size of the input list, since the function terminates when it reaches 1.0.
        Parameters:
        probabilityList -
        Returns:
      • asString

        public static String asString​(double val)
      • over

        public static BigDecimal over​(int n,
                                      int k)
      • over

        public static BigDecimal over​(int n,
                                      int[] nList)
      • computeJointProbability

        public static BigDecimal computeJointProbability​(BigDecimal[] probList,
                                                         int[] nList)
      • factorial

        public static BigDecimal factorial​(long n)
      • isNumeric

        public static boolean isNumeric​(Object value)
      • transformSampleToComplex

        public static List<org.apache.commons.math.complex.Complex> transformSampleToComplex​(List<ISample> samples)
      • convertToDouble

        public static double convertToDouble​(Object value)
      • round

        public static double round​(double value,
                                   double precision)
      • lessOrEqual

        public static boolean lessOrEqual​(double d1,
                                          double d2)
      • less

        public static boolean less​(double d1,
                                   double d2)
      • nextPowerOfTwo

        public static int nextPowerOfTwo​(int value)
        Returns the next power of two which is larger or equal to the passed value.

        As an example, passing the value 7 will return 2^3 = 8.

        Parameters:
        value - a value greater than 0
        Returns: