bodhidharma.utilities
Class Statistics

java.lang.Object
  extended by bodhidharma.utilities.Statistics

public class Statistics
extends java.lang.Object

A holder class for static methods relating to statistical and mathematical analysis.

Author:
Cory McKay

Constructor Summary
Statistics()
           
 
Method Summary
static double calculateEuclideanDistance(double[] x, double[] y)
          Returns the Euclidian distance between x and y.
static int generateRandomNumber(int max)
          Returns a random integer from 0 to max - 1, based on the uniform distribution.
static double getArraySum(double[] to_sum)
          Returns the sum of the contents of all of the entries of the given array.
static double getAverage(double[] data)
          Returns the average of a set of doubles.
static double getAverage(int[] data)
          Returns the average of a set of ints.
static int getIndexOfLargest(double[] values)
          Returns the index of the entry of an array of doubles with the largest value.
static int getIndexOfLargest(float[] values)
          Returns the index of the entry of an array of floats with the largest value.
static int getIndexOfLargest(int[] values)
          Returns the index of the entry of an array of itegers with the largest value.
static int getIndexOfSmallest(double[] values)
          Returns the index of the entry of an array of doubles with the smallest value.
static int[] getRandomOrdering(int number_entries)
          Returns an array number_entries arrays.
static double getStandardDeviation(double[] data)
          Returns the standard deviation of a set of doubles.
static double getStandardDeviation(int[] data)
          Returns the standard deviation of a set of ints.
static boolean isFactorOrMultiple(int x, int y, int[] z)
          Returns whether or not x is either a factor or a multiple of y.
static double[] normalize(double[] to_normalize)
          Return a normalized copy of the the given array.
static double[][] normalize(double[][] to_normalize)
          Return a normalized copy of the the given array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Statistics

public Statistics()
Method Detail

getAverage

public static double getAverage(double[] data)
Returns the average of a set of doubles. Returns 0 if the length of the data is 0.

Parameters:
data - the which is to be averaged.
Returns:
the mean of the given data.

getAverage

public static double getAverage(int[] data)
Returns the average of a set of ints. Returns 0 if the length of the data is 0.

Parameters:
data - the which is to be averaged.
Returns:
the mean of the given data.

getStandardDeviation

public static double getStandardDeviation(double[] data)
Returns the standard deviation of a set of doubles. Returns 0 if there is only one piece of data.

Parameters:
data - for which the standard deviation is to be found.
Returns:
the standard deviation of the given data.

getStandardDeviation

public static double getStandardDeviation(int[] data)
Returns the standard deviation of a set of ints. Returns 0 if there is only one piece of data.

Parameters:
data - for which the standard deviation is to be found.
Returns:
the standard deviation of the given data.

isFactorOrMultiple

public static boolean isFactorOrMultiple(int x,
                                         int y,
                                         int[] z)
Returns whether or not x is either a factor or a multiple of y. z denotes the possible multipliers to check for. True is returned if x is either a factor of a multiple of y (and vice versa, of course), and false otherwise.


getIndexOfLargest

public static int getIndexOfLargest(double[] values)
Returns the index of the entry of an array of doubles with the largest value. The first occurence is returned in the case of a tie.


getIndexOfSmallest

public static int getIndexOfSmallest(double[] values)
Returns the index of the entry of an array of doubles with the smallest value. The first occurence is returned in the case of a tie.


getIndexOfLargest

public static int getIndexOfLargest(float[] values)
Returns the index of the entry of an array of floats with the largest value. The first occurence is returned in the case of a tie.


getIndexOfLargest

public static int getIndexOfLargest(int[] values)
Returns the index of the entry of an array of itegers with the largest value. The first occurence is returned in the case of a tie.


calculateEuclideanDistance

public static double calculateEuclideanDistance(double[] x,
                                                double[] y)
                                         throws java.lang.Exception
Returns the Euclidian distance between x and y. Throws an exception if x an y have different sizes.

Throws:
java.lang.Exception

generateRandomNumber

public static int generateRandomNumber(int max)
Returns a random integer from 0 to max - 1, based on the uniform distribution.


getRandomOrdering

public static int[] getRandomOrdering(int number_entries)
Returns an array number_entries arrays. Each entry has a value between 0 and number_entries

getArraySum

public static double getArraySum(double[] to_sum)
Returns the sum of the contents of all of the entries of the given array.


normalize

public static double[] normalize(double[] to_normalize)
Return a normalized copy of the the given array. The original array is not altered.


normalize

public static double[][] normalize(double[][] to_normalize)
Return a normalized copy of the the given array. Normalization is performed by row (i.e. the sum of each row (first indice) is one after normalization). Each row is independant. The original array is not altered.