at.tuwien.ifs.somtoolbox.data
Class RandomAccessFileSOMLibInputData

java.lang.Object
  extended by at.tuwien.ifs.somtoolbox.data.AbstractSOMLibSparseInputData
      extended by at.tuwien.ifs.somtoolbox.data.RandomAccessFileSOMLibInputData
All Implemented Interfaces:
InputData

public class RandomAccessFileSOMLibInputData
extends AbstractSOMLibSparseInputData

Reads SOMLib input from a random access file.

Version:
$Id: RandomAccessFileSOMLibInputData.java 3883 2010-11-02 17:13:23Z frank $
Author:
Rudolf Mayer
See Also:
RandomAccessFile

Field Summary
private static int BYTES_CHAR
           
private static int BYTES_DOUBLE
           
private static int BYTES_INT
           
(package private)  int headerOffset
           
private  RandomAccessFile inputFile
           
 
Fields inherited from class at.tuwien.ifs.somtoolbox.data.AbstractSOMLibSparseInputData
classInfo, content_subtype, content_type, dataNames, dim, ERROR_MESSAGE_FILE_FORMAT_CORRUPT, featureMatrixCols, featureMatrixRows, isNormalized, meanVector, mqe0, nameCache, numVectors, rand, source, templateVector
 
Fields inherited from interface at.tuwien.ifs.somtoolbox.data.InputData
inputFileNameSuffix, MISSING_VALUE
 
Constructor Summary
RandomAccessFileSOMLibInputData(boolean norm, Random rand, TemplateVector tv, SOMLibClassInformation clsInfo, String fileName)
           
RandomAccessFileSOMLibInputData(String fileName)
           
 
Method Summary
private static void compare(String ascii, String binary)
          Compare the ascii & binary version of some SOMLib input data.
static String getFileNameSuffix()
           
static String getFormatName()
           
 InputDatum getInputDatum(int d)
          Get an input datum with a specified index.
 double[] getInputVector(int d)
          Get the vector for the input datum of the specified index
private  int getOffset(int i)
           
private  int getOffset(int i, int j)
           
 double getValue(int x, int y)
          Returns the value of the y-th feature of input vector x.
static void main(String[] args)
          Main method for testing purposes, either writes & reads a random access file, or compares a random access file with an ascii version of the same input data.
 double mqe0(DistanceMetric metric)
          Calculates the mean quantisation error of the top-level unit.
private  cern.colt.matrix.impl.SparseDoubleMatrix1D readVectorFromFile(int d)
           
 InputData subset(String[] names)
          Gets a subset of this input data set.
private static void test(String fileName)
          Create & read a random access file SOMLib input data.
static void write(InputData data, String outputFile)
           
private static void writeContent(RandomAccessFile randomAccessFile, double[][] data)
           
static boolean writeHeader(RandomAccessFile randomAccessFile, int numVectors, int dim)
           
static void writeVectorLabels(RandomAccessFile randomAccessFile, String[] labels)
           
 
Methods inherited from class at.tuwien.ifs.somtoolbox.data.AbstractSOMLibSparseInputData
classInformation, create, dim, equals, getByNameDistanceSorted, getContentSubType, getContentType, getData, getData, getDataIntervals, getDataSource, getDistanceMatrix, getDistances, getFeatureDensities, getFeatureMatrixColumns, getFeatureMatrixRows, getInputDatum, getInputDatum, getInputDatumIndex, getLabel, getLabels, getMeanVector, getMeanVector, getNearestN, getNearestN, getNearestNUnsorted, getRandomInputDatum, initDistanceMatrix, isNormalizedToUnitLength, numVectors, setClassInfo, setTemplateVector, templateVector, transformValues
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTES_CHAR

private static final int BYTES_CHAR
See Also:
Constant Field Values

BYTES_INT

private static final int BYTES_INT
See Also:
Constant Field Values

BYTES_DOUBLE

private static final int BYTES_DOUBLE
See Also:
Constant Field Values

inputFile

private RandomAccessFile inputFile

headerOffset

int headerOffset
Constructor Detail

RandomAccessFileSOMLibInputData

public RandomAccessFileSOMLibInputData(String fileName)
                                throws IOException
Throws:
IOException

RandomAccessFileSOMLibInputData

public RandomAccessFileSOMLibInputData(boolean norm,
                                       Random rand,
                                       TemplateVector tv,
                                       SOMLibClassInformation clsInfo,
                                       String fileName)
                                throws IOException
Throws:
IOException
Method Detail

getInputDatum

public InputDatum getInputDatum(int d)
Description copied from interface: InputData
Get an input datum with a specified index.

Parameters:
d - the index of the input datum.
Returns:
the input datum.

readVectorFromFile

private cern.colt.matrix.impl.SparseDoubleMatrix1D readVectorFromFile(int d)
                                                               throws IOException
Throws:
IOException

getInputVector

public double[] getInputVector(int d)
Description copied from interface: InputData
Get the vector for the input datum of the specified index


getOffset

private int getOffset(int i)

getOffset

private int getOffset(int i,
                      int j)

mqe0

public double mqe0(DistanceMetric metric)
Description copied from interface: InputData
Calculates the mean quantisation error of the top-level unit.

Parameters:
metric - the metric to use for distance calculation.
Returns:
the mqe0.

subset

public InputData subset(String[] names)
Description copied from interface: InputData
Gets a subset of this input data set. The input data in the subset are identified by the specified labels.

Parameters:
names - the label names of the desired subset data.
Returns:
a subset of the data.

getValue

public double getValue(int x,
                       int y)
Description copied from interface: InputData
Returns the value of the y-th feature of input vector x.


write

public static void write(InputData data,
                         String outputFile)
                  throws IOException
Throws:
IOException

writeHeader

public static boolean writeHeader(RandomAccessFile randomAccessFile,
                                  int numVectors,
                                  int dim)
                           throws IOException
Throws:
IOException

writeContent

private static void writeContent(RandomAccessFile randomAccessFile,
                                 double[][] data)
                          throws IOException
Throws:
IOException

writeVectorLabels

public static void writeVectorLabels(RandomAccessFile randomAccessFile,
                                     String[] labels)
                              throws IOException
Throws:
IOException

main

public static void main(String[] args)
                 throws IOException
Main method for testing purposes, either writes & reads a random access file, or compares a random access file with an ascii version of the same input data.

Throws:
IOException

compare

private static void compare(String ascii,
                            String binary)
                     throws IOException
Compare the ascii & binary version of some SOMLib input data.

Throws:
IOException

test

private static void test(String fileName)
                  throws FileNotFoundException,
                         IOException
Create & read a random access file SOMLib input data.

Throws:
FileNotFoundException
IOException

getFormatName

public static String getFormatName()

getFileNameSuffix

public static String getFileNameSuffix()