Package pal.math

Class MathUtils


  • public class MathUtils
    extends java.lang.Object
    Handy utility functions which have some Mathematical relavance.
    Version:
    $Id: MathUtils.java,v 1.10 2004/08/05 03:00:22 matt Exp $
    Author:
    Matthew Goode, Alexei Drummond
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static MersenneTwisterFast random
      A random number generator that is initialized with the clock when this class is loaded into the JVM.
    • Constructor Summary

      Constructors 
      Constructor Description
      MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double ensureBounded​(double x, double lower, double upper)
      Ensure a value of x is actaully bounded between two values.
      static double getLoggedDifferenceFromLogged​(double lnOfX, double lnOfY)
      Calculate the logged difference in two values = x - y, where the log of x and y are given.
      static double getMaximum​(double[] array)  
      static double getMaximum​(double[] array, int start, int end)  
      static double getMinimum​(double[] array)  
      static double getMinimum​(double[] array, int start, int end)  
      static double[] getNormalized​(double[] array)  
      static double[] getRandomArguments​(MultivariateFunction mf)  
      static double getTotal​(double[] array)  
      static double getTotal​(double[] array, int start, int end)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • random

        public static MersenneTwisterFast random
        A random number generator that is initialized with the clock when this class is loaded into the JVM. Use this for all random numbers.
    • Constructor Detail

      • MathUtils

        public MathUtils()
    • Method Detail

      • getLoggedDifferenceFromLogged

        public static final double getLoggedDifferenceFromLogged​(double lnOfX,
                                                                 double lnOfY)
        Calculate the logged difference in two values = x - y, where the log of x and y are given. That is, given ln(x), and ln(y) calculate ln(x-y)
        Parameters:
        lnOfX - the natural log of X
        lnOfY - the natural log of Y
        Returns:
        X - Y (logged)
      • ensureBounded

        public static final double ensureBounded​(double x,
                                                 double lower,
                                                 double upper)
        Ensure a value of x is actaully bounded between two values. Useful when using numerical analysis tools that may, over the limits of the expressed accuracy, return values outside the specified range
        Parameters:
        x - the value of interest
        lower - the lower bound
        upper - the upper bound
        Returns:
        x if between the bounds, or lower bound if lower than lower bound, or upper bound if higher than upper
      • getNormalized

        public static final double[] getNormalized​(double[] array)
        Returns:
        a new double array where all the values sum to 1. Relative ratios are preserved.
      • getTotal

        public static final double getTotal​(double[] array,
                                            int start,
                                            int end)
        Parameters:
        end - the index of the element after the last one to be included
        Returns:
        the total of a the values in a range of an array
      • getMinimum

        public static final double getMinimum​(double[] array,
                                              int start,
                                              int end)
        Parameters:
        array -
        start -
        end - the index of the element after the last one to be included
        Returns:
        the minimum of a the values in a range of an array
      • getMinimum

        public static final double getMinimum​(double[] array)
        Parameters:
        array - The array of values to examine
        Returns:
        the minimum of a the values in an array
      • getMaximum

        public static final double getMaximum​(double[] array)
        Parameters:
        array - The array of values to examine
        Returns:
        the maximum of a the values in an array
      • getMaximum

        public static final double getMaximum​(double[] array,
                                              int start,
                                              int end)
        Parameters:
        array -
        start -
        end - the index of the element after the last one to be included
        Returns:
        the maximum of a the values in a range of an array
      • getTotal

        public static final double getTotal​(double[] array)
        Returns:
        the total of the values in an array
      • getRandomArguments

        public static final double[] getRandomArguments​(MultivariateFunction mf)
        Returns:
        a set of valid, but randomly generated, arguments for a particular MultivariateFunction