com.sjm.machlearn.util
Class Util

java.lang.Object
  |
  +--com.sjm.machlearn.util.Util

public class Util
extends java.lang.Object

Class UTIL Contains some basic utilities that will be used by other classes.

Version:
0.01a April 2003
Author:
Sean McIlwain
See Also:
Author Homepage

Constructor Summary
Util()
           
 
Method Summary
static int argmax(double[] a)
           
static int argmax(int[] a)
           
static int argmin(double[] a)
           
static double average(double[] values)
          average() : averages the double values in the * array *
static boolean copyTextFile(java.lang.String dest, java.lang.String src)
           
static boolean createDir(java.lang.String directory)
           
static boolean deleteFile(java.lang.String file)
           
static boolean isLowMem()
           
static double log(double value, double base)
           
static double max(double[] a)
           
static double max(double a, double b)
           
static int max(int[] a)
           
static int max(int a, int b)
          max() : return the max of two integers.
static double min(double[] a)
           
static double min(double a, double b)
           
static int min(int a, int b)
           
static java.lang.String padzeroleft(int value, int digits)
           
static java.lang.String printArray(boolean[] a)
           
static java.lang.String printArray(double[] a)
           
static java.lang.String printArray(int[] a)
           
static boolean randomBoolean()
          randomBoolean() returns a true or false value drawn pseudo-randomly.
static boolean randomBoolean(double prob)
          randomBoolean() * returns a true or false value determined by the * probability of a true value.
static int randomInteger(double[] probs)
           
static int randomInteger(int min, int max)
           
static int randomIntegerE(double[] probs)
          randomIntegerE() : picks a random integer between array index 0 to the array length-1.
static int[] randomIntList(int min, int max)
           
static void randomizeDbl(double[] w, double min, double max)
           
static java.lang.String spliceString(java.lang.String[] sarray, java.lang.String separator)
          spliceString() : returns a string that is a splice of the strings in sarray separated by a separator.
static java.lang.String stripPadding(java.lang.String line)
           
static double sum(double[] values)
          sum() : sums the values in the array *
static int sum(int[] values)
          sum() : sums the values in the array *
static void swap(boolean[] values, int i, int j)
          swap() : swaps two boolean values in an array *
static void swap(double[] values, int i, int j)
          swap() : swaps two double values in an array *
static void swap(int[] array, int i, int j)
           
static void writeText(java.lang.String filename, java.lang.String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

randomizeDbl

public static void randomizeDbl(double[] w,
                                double min,
                                double max)

randomIntList

public static int[] randomIntList(int min,
                                  int max)

swap

public static void swap(double[] values,
                        int i,
                        int j)
swap() : swaps two double values in an array *
Parameters:
values - array to do the swapping *
i - 1st index for swap *
j - 2nd index for swap *

swap

public static void swap(boolean[] values,
                        int i,
                        int j)
swap() : swaps two boolean values in an array *
Parameters:
values - array to do the swapping *
i - 1st index for swap *
j - 2nd index for swap *

sum

public static int sum(int[] values)
sum() : sums the values in the array *
Parameters:
values - array to be summed *
Returns:
sum of all the values *

sum

public static double sum(double[] values)
sum() : sums the values in the array *
Parameters:
values - array to be summed *
Returns:
sum of all the values *

average

public static double average(double[] values)
average() : averages the double values in the * array *
Parameters:
values - double array of values to average *
Returns:
average of the values in the array *

log

public static double log(double value,
                         double base)

randomBoolean

public static boolean randomBoolean()
randomBoolean() returns a true or false value drawn pseudo-randomly.

randomBoolean

public static boolean randomBoolean(double prob)
randomBoolean() * returns a true or false value determined by the * probability of a true value. *
Parameters:
prob - probability of a true value 0-1.0 *
Returns:
true or false based upon the given prob *

max

public static int max(int a,
                      int b)
max() : return the max of two integers. *
Parameters:
a - 1st number *
b - 2nd number *
Returns:
the greater of the two numbers. *

max

public static double max(double a,
                         double b)

min

public static int min(int a,
                      int b)

min

public static double min(double a,
                         double b)

min

public static double min(double[] a)

max

public static double max(double[] a)

max

public static int max(int[] a)

argmax

public static int argmax(int[] a)

argmax

public static int argmax(double[] a)

argmin

public static int argmin(double[] a)

printArray

public static java.lang.String printArray(int[] a)

printArray

public static java.lang.String printArray(double[] a)

printArray

public static java.lang.String printArray(boolean[] a)

randomInteger

public static int randomInteger(int min,
                                int max)

randomIntegerE

public static int randomIntegerE(double[] probs)
randomIntegerE() : picks a random integer between array index 0 to the array length-1. The array passed in is the probability (or score) of that index occuring in the random draw. The array is first normalized using the exponential function, afterwhich a draw is made to choose the index.

randomInteger

public static int randomInteger(double[] probs)

writeText

public static void writeText(java.lang.String filename,
                             java.lang.String text)
                      throws java.io.IOException

padzeroleft

public static java.lang.String padzeroleft(int value,
                                           int digits)

swap

public static void swap(int[] array,
                        int i,
                        int j)

copyTextFile

public static boolean copyTextFile(java.lang.String dest,
                                   java.lang.String src)

createDir

public static boolean createDir(java.lang.String directory)

deleteFile

public static boolean deleteFile(java.lang.String file)

spliceString

public static java.lang.String spliceString(java.lang.String[] sarray,
                                            java.lang.String separator)
spliceString() : returns a string that is a splice of the strings in sarray separated by a separator.

stripPadding

public static java.lang.String stripPadding(java.lang.String line)

isLowMem

public static boolean isLowMem()