gpalta.core
Class Common

java.lang.Object
  extended by gpalta.core.Common

public abstract class Common
extends java.lang.Object

Useful utilities for all clases


Field Summary
static java.util.Random globalRandom
          A random number generator for use by other classes
 
Constructor Summary
Common()
           
 
Method Summary
static double[] copy(double[] x)
          Obtain a copy of an array
static double[][] copy(double[][] m)
          Obtain an independent copy of the given matrix
static int[] copy(int[] x)
          Obtain a copy of an array
static int[][] copy(int[][] m)
          Obtain an independent copy of the given matrix
static double dist(double[] x1, double[] x2, int n)
          N Distance between two vectors
static double dist2(double[] x1, double[] x2)
          Euclidean distance between two vectors
static double dotProduct(double[] x1, double[] x2)
          Dot product between two vectors
static int[] randPerm(int n)
          Efficient permutation algorithm, O(n)
static double[][] readFromFile(java.lang.String fileName, java.lang.String separator)
          Read a matrix from file
static void sigmoid(double[] x)
          Calculate the sigmoid (logistic function) for an entire array (inplace, i.e. modifying its contents)
static double sum(double[] x)
          Sum of the values of a vector
static double[][] transpose(double[][] m)
          Transpose a matrix
static void transpose(double[][] mT, double[][] m)
           
static double variance(double[] x)
          Variance of a vector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalRandom

public static java.util.Random globalRandom
A random number generator for use by other classes

Constructor Detail

Common

public Common()
Method Detail

randPerm

public static int[] randPerm(int n)
Efficient permutation algorithm, O(n)

Parameters:
n - The size of the permutation
Returns:
A permutation of size n. That is, an int array consisting of all integer numbers between 0 and n (non-inclusive) in random order

sigmoid

public static void sigmoid(double[] x)
Calculate the sigmoid (logistic function) for an entire array (inplace, i.e. modifying its contents)

Parameters:
x - the array

readFromFile

public static double[][] readFromFile(java.lang.String fileName,
                                      java.lang.String separator)
                               throws java.io.IOException
Read a matrix from file

Parameters:
fileName - The file to read
separator - Carachter that separates each value
Returns:
a matrix with the file contents
Throws:
java.io.IOException - If any errors occur when reading the file

transpose

public static double[][] transpose(double[][] m)
Transpose a matrix

Parameters:
m - The matrix to transpose
Returns:
The transposed matrix

transpose

public static void transpose(double[][] mT,
                             double[][] m)

sum

public static double sum(double[] x)
Sum of the values of a vector

Parameters:
x - The vector
Returns:
The sum of all the values

copy

public static double[][] copy(double[][] m)
Obtain an independent copy of the given matrix

Parameters:
m - The matrix to copy
Returns:
a new matrix, with the same values as the original

copy

public static int[][] copy(int[][] m)
Obtain an independent copy of the given matrix

Parameters:
m - The matrix to copy
Returns:
a new matrix, with the same values as the original

copy

public static double[] copy(double[] x)
Obtain a copy of an array

Parameters:
x - The array to copy
Returns:
a new array, with the same values as the original

copy

public static int[] copy(int[] x)
Obtain a copy of an array

Parameters:
x - The array to copy
Returns:
a new array, with the same values as the original

dist

public static double dist(double[] x1,
                          double[] x2,
                          int n)
N Distance between two vectors

Parameters:
x1 - one vector
x2 - the other
n -
Returns:
(sum |x1[i] - x2[i]|n) 1/n

dist2

public static double dist2(double[] x1,
                           double[] x2)
Euclidean distance between two vectors

Parameters:
x1 - one vector
x2 - the other vector
Returns:
the euclidean distance between them

dotProduct

public static double dotProduct(double[] x1,
                                double[] x2)
Dot product between two vectors

Parameters:
x1 - one vector
x2 - the other vector
Returns:
the euclidean distance between them

variance

public static double variance(double[] x)
Variance of a vector

Parameters:
x - The vector
Returns:
The sum of all the values