Class Maths


  • public class Maths
    extends Object
    This class contains useful math methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      Maths()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double arrayAverage​(double[] array)
      Calculates the average of an double array
      static double arrayAverage​(int[] array)
      Calculates the average of an int array
      static double arrayStandardDeviation​(double[] array)
      Calculates the standard deviation of an double array
      static double arrayStandardDeviation​(int[] array)
      Calculate the standard deviation of an int array
      static double dotProduct​(double[] a, double[] b)
      Dot product between two vectors
      static double[] linespace​(double start, double stop, int num)
      Returns num evenly spaced samples.
      static double[] linespace​(double start, double stop, int num, boolean endpoint)
      Returns num evenly spaced samples.
      static double[] linespace​(double stop, int num)
      Returns num evenly spaced samples.
      static double log​(double x, double b)
      Returns the log in an specific base
      static double logistic​(double x)
      Returns the logistic function g(x)
      static double[] logspace​(double start, double stop, int num)
      Return numbers spaced evenly on a log scale.
      static double[] logspace​(double start, double stop, int num, boolean endpoint)
      Return numbers spaced evenly on a log scale.
      static double[] logspace​(double start, double stop, int num, boolean endpoint, double base)
      Return numbers spaced evenly on a log scale.
      static double[] logspace​(double start, double stop, int num, double base)
      Return numbers spaced evenly on a log scale.
      static int[] range​(int stop)
      Returns an array of int values.
      static int[] range​(int start, int stop)
      Returns an array of int values.
      static int[] range​(int start, int stop, int step)
      Returns an array of int values.
      static int[] range​(int start, int stop, int step, boolean endpoint)
      Returns an array of int values.
    • Constructor Detail

      • Maths

        public Maths()
    • Method Detail

      • arrayAverage

        public static double arrayAverage​(double[] array)
        Calculates the average of an double array
        Parameters:
        array - Array of double from which to calculate the mean
        Returns:
        Array mean
      • arrayStandardDeviation

        public static double arrayStandardDeviation​(double[] array)
        Calculates the standard deviation of an double array
        Parameters:
        array - Array of double from which to calculate the standard deviation
        Returns:
        Standard deviation of the array
      • arrayAverage

        public static double arrayAverage​(int[] array)
        Calculates the average of an int array
        Parameters:
        array - Array of int from which to calculate the mean
        Returns:
        Array mean
      • arrayStandardDeviation

        public static double arrayStandardDeviation​(int[] array)
        Calculate the standard deviation of an int array
        Parameters:
        array - Array of int from which to calculate the standard deviation
        Returns:
        Standard deviation of the array
      • dotProduct

        public static double dotProduct​(double[] a,
                                        double[] b)
        Dot product between two vectors
        Parameters:
        a - Vector A
        b - Vector B
        Returns:
        dot_product(A, B)
      • log

        public static double log​(double x,
                                 double b)
        Returns the log in an specific base
        Parameters:
        x - Value
        b - Base
        Returns:
        log of x in base b
      • logistic

        public static double logistic​(double x)
        Returns the logistic function g(x)
        Parameters:
        x - The given parameter x of the function g(x)
        Returns:
        Value of the logistic function g(x)
      • range

        public static int[] range​(int start,
                                  int stop,
                                  int step,
                                  boolean endpoint)
        Returns an array of int values.
        Parameters:
        start - An integer value specifying at which position to start. Default 0.
        stop - An integer value specifying at which position to stop.
        step - An integer value specifying the incrementation. Default 1.
        endpoint - If true, include the stop value. Otherwise, it is not included. Default true.
        Returns:
        Values of the range.
      • range

        public static int[] range​(int start,
                                  int stop,
                                  int step)
        Returns an array of int values.
        Parameters:
        start - An integer value specifying at which position to start. Default 0.
        stop - An integer value specifying at which position to stop.
        step - An integer value specifying the incrementation. Default 1.
        Returns:
        Values of the range.
      • range

        public static int[] range​(int start,
                                  int stop)
        Returns an array of int values.
        Parameters:
        start - An integer value specifying at which position to start. Default 0.
        stop - An integer value specifying at which position to stop.
        Returns:
        Values of the range.
      • range

        public static int[] range​(int stop)
        Returns an array of int values.
        Parameters:
        stop - An integer value specifying at which position to stop.
        Returns:
        Values of the range.
      • linespace

        public static double[] linespace​(double start,
                                         double stop,
                                         int num,
                                         boolean endpoint)
        Returns num evenly spaced samples.
        Parameters:
        start - The starting value. Default 0.0.
        stop - The stop value.
        num - Number of samples to generate.
        endpoint - If true, stop is the last sample. Otherwise, it is not included. Default true.
        Returns:
        Double array with num evenly spaced samples.
      • linespace

        public static double[] linespace​(double start,
                                         double stop,
                                         int num)
        Returns num evenly spaced samples.
        Parameters:
        start - The starting value. Default 0.0.
        stop - The stop value.
        num - Number of samples to generate.
        Returns:
        Double array with num evenly spaced samples.
      • linespace

        public static double[] linespace​(double stop,
                                         int num)
        Returns num evenly spaced samples.
        Parameters:
        stop - The stop value.
        num - Number of samples to generate.
        Returns:
        Double array with num evenly spaced samples.
      • logspace

        public static double[] logspace​(double start,
                                        double stop,
                                        int num,
                                        boolean endpoint,
                                        double base)
        Return numbers spaced evenly on a log scale. The sequence starts at Math.pow(base, start).
        Parameters:
        start - Math.pow(base, start) is the starting value of the sequence.
        stop - Math.pow(base, stop) is the last value of the sequence if endpoint is true.
        num - Number of samples to generate.
        endpoint - If true, stop is the last sample. Otherwise, it is not included. Default true.
        base - The base of the log space. Default 10.
        Returns:
        Double array with num evenly spaced samples on a log scale.
      • logspace

        public static double[] logspace​(double start,
                                        double stop,
                                        int num,
                                        boolean endpoint)
        Return numbers spaced evenly on a log scale. The sequence starts at Math.pow(base, start).
        Parameters:
        start - Math.pow(base, start) is the starting value of the sequence.
        stop - Math.pow(base, stop) is the last value of the sequence if endpoint is true.
        num - Number of samples to generate.
        endpoint - If true, stop is the last sample. Otherwise, it is not included. Default true.
        Returns:
        Double array with num evenly spaced samples on a log scale.
      • logspace

        public static double[] logspace​(double start,
                                        double stop,
                                        int num,
                                        double base)
        Return numbers spaced evenly on a log scale. The sequence starts at Math.pow(base, start).
        Parameters:
        start - Math.pow(base, start) is the starting value of the sequence.
        stop - Math.pow(base, stop) is the last value of the sequence if endpoint is true.
        num - Number of samples to generate.
        base - The base of the log space. Default 10.
        Returns:
        Double array with num evenly spaced samples on a log scale.
      • logspace

        public static double[] logspace​(double start,
                                        double stop,
                                        int num)
        Return numbers spaced evenly on a log scale. The sequence starts at Math.pow(base, start).
        Parameters:
        start - Math.pow(base, start) is the starting value of the sequence.
        stop - Math.pow(base, stop) is the last value of the sequence if endpoint is true.
        num - Number of samples to generate.
        Returns:
        Double array with num evenly spaced samples on a log scale.