lnsc
Class Tools

java.lang.Object
  |
  +--lnsc.Tools

public final class Tools
extends java.lang.Object

Set tool functions.

Since:
1.0

Method Summary
static java.io.Serializable copyObject(java.io.Serializable obj)
          Copies an object by writing it to a temp file and reading it afterwards.
static FunctionalUnit[] createUnitArray(int newCount, FunctionalUnit newUnit)
          Takes a unit and a count and creates and array of that unit and count (by copy to the provided units).
 int[][][] GIFEncoder(java.awt.Image image)
          Takes an images and returns and r,g,b arrays of values between 0 and 256.
static DataSet importDataSet(java.lang.String fileName, int inputCount, int outputCount, int patternCount)
          Imports a data set from a file.
static DataSet loadDataSet(java.io.File file)
          Loads a data set (saved using saveDataSet(java.lang.String, lnsc.DataSet)) from a file.
static DataSet loadDataSet(java.lang.String fileName)
          Loads a data set (saved using saveDataSet(java.lang.String, lnsc.DataSet)) from a file.
static DataSetCollection makeCrossValidationSets(DataSet data, int foldCount)
          Takes a set of data an generate k train sets and test sets by splitting the data into k folds and using each fold as a test set for the train set made of the other k-1 folds.
static double[][] makeGrid(int size)
          Generates a set of coordinates that form a grid in the [-1,1]x[-1,1] space (including the boundary).
static void saveDataSet(java.io.File file, DataSet dataSet)
          Saves a data set to a file.
static void saveDataSet(java.lang.String fileName, DataSet dataSet)
          Saves a data set to a file.
static java.lang.String tabText(java.lang.String text, int tabCount)
          Tabulates text.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyObject

public static java.io.Serializable copyObject(java.io.Serializable obj)
Copies an object by writing it to a temp file and reading it afterwards. This function requires serializability of the object.

Parameters:
obj - A serializable object.
Returns:
A deep copy of the object.

createUnitArray

public static FunctionalUnit[] createUnitArray(int newCount,
                                               FunctionalUnit newUnit)
Takes a unit and a count and creates and array of that unit and count (by copy to the provided units).

Parameters:
newCount - Number of units in the array
newUnit - Units to initialise the array with.
Returns:
An array of newCount newUnits.

GIFEncoder

public int[][][] GIFEncoder(java.awt.Image image)
                     throws java.awt.AWTException,
                            java.lang.InterruptedException
Takes an images and returns and r,g,b arrays of values between 0 and 256. It supports only 256 color Gif.

Parameters:
image - The image to transform.
Returns:
double[3][width][height] An array where the first index indicates red (0), green (1), or blue (2) component, and the two others the x,y positon of the pixel. Values range [0,256).
java.awt.AWTException
java.lang.InterruptedException

importDataSet

public static DataSet importDataSet(java.lang.String fileName,
                                    int inputCount,
                                    int outputCount,
                                    int patternCount)
                             throws java.io.IOException
Imports a data set from a file.

Parameters:
fileName - The name of the file.
inputCount - Number of input values per row.
outputCount - Number of output values per row.
patternCount - Total number of pattern pairs to expect.
Returns:
A valid DataNames.TRAIN_SET. The file must contain 1 pattern per row, the first few elements being the input values and the last few the output values.
java.io.IOException

loadDataSet

public static DataSet loadDataSet(java.io.File file)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
Loads a data set (saved using saveDataSet(java.lang.String, lnsc.DataSet)) from a file.

Parameters:
file - The file descriptor.
Returns:
The data set read.
java.io.IOException
java.lang.ClassNotFoundException

loadDataSet

public static DataSet loadDataSet(java.lang.String fileName)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
Loads a data set (saved using saveDataSet(java.lang.String, lnsc.DataSet)) from a file.

Parameters:
fileName - The name of the file.
Returns:
The data set read.
java.io.IOException
java.lang.ClassNotFoundException

makeCrossValidationSets

public static final DataSetCollection makeCrossValidationSets(DataSet data,
                                                              int foldCount)
Takes a set of data an generate k train sets and test sets by splitting the data into k folds and using each fold as a test set for the train set made of the other k-1 folds.

Parameters:
data - A valid DataNames.TRAIN_SET.
foldCount - Number of folds into which the data must be split.
Returns:
A data set collection containing k pairs of DataNames.TRAIN_SET and DataNames.TEST_SET.

makeGrid

public static final double[][] makeGrid(int size)
Generates a set of coordinates that form a grid in the [-1,1]x[-1,1] space (including the boundary).

Parameters:
size - Number of grid element along both dimensions.
Returns:
A set of size*size bi-dimensional vectors equally spaced in the range [-1,1]x[-1,1].

saveDataSet

public static void saveDataSet(java.io.File file,
                               DataSet dataSet)
                        throws java.io.IOException
Saves a data set to a file.

Parameters:
file - The file descriptor.
dataSet - The data set to save.
java.io.IOException

saveDataSet

public static void saveDataSet(java.lang.String fileName,
                               DataSet dataSet)
                        throws java.io.IOException
Saves a data set to a file.

Parameters:
fileName - The name of the file.
dataSet - The data set to save.
java.io.IOException

tabText

public static java.lang.String tabText(java.lang.String text,
                                       int tabCount)
Tabulates text. Given a string with new line character, a tab character is inserted at the beginning of every line.

Parameters:
text - Text to be tabulated.
tabCount - Number of tab to add.
Returns:
The tabulated text.