at.tuwien.ifs.somtoolbox.data.distance
Class InputVectorDistanceMatrix

java.lang.Object
  extended by at.tuwien.ifs.somtoolbox.data.distance.InputVectorDistanceMatrix
Direct Known Subclasses:
AbstractMemoryInputVectorDistanceMatrix, RandomAccessFileInputVectorDistanceMatrix

public abstract class InputVectorDistanceMatrix
extends Object

Base for classes providing a distance matrix of the input vectors, with generic methods and fields.
A distance matrix is of size n*n, where n is the number of input vectors. The matrix is symmetric, i.e. the upper-right and lower-left halves contain the same values. The diagonal contains the distances of one element to itself, and is thus always 0.

Version:
$Id: InputVectorDistanceMatrix.java 3711 2010-07-23 09:37:24Z mayer $
Author:
Rudolf Mayer

Field Summary
protected  ArrayList<String> inputLabels
           
protected  DistanceMetric metric
           
protected  int numVectors
           
 
Constructor Summary
InputVectorDistanceMatrix()
           
 
Method Summary
 int columns()
           
 boolean equals(Object obj)
           
protected  int flatArraySize()
           
abstract  double getDistance(int x, int y)
          Return the distance between input vectors x and y.
 double[] getDistances(int x)
          Return the distances to all vectors from input x.
 double[] getDistancesFlat()
          Gets all the distances in a single flat array avoiding duplicates from the pairwise distances, thus of the size of numVectors * (numVectors - * 1) / 2.
This is a default implementation always constructing the array on the fly using the getDistance(int, int) method.
 cern.colt.matrix.impl.DenseDoubleMatrix1D getDistancesFlatAsMatrix()
           
 ArrayList<String> getInputLabels()
           
 DistanceMetric getMetric()
           
 int[] getNNearest(int x, int num)
          Return the n nearest vectors of input x.
static InputVectorDistanceMatrix initFromFile(String fileName)
          Factory method that reads and creates an InputVectorDistanceMatrix from the given file.
 int numVectors()
           
 int rows()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numVectors

protected int numVectors

metric

protected DistanceMetric metric

inputLabels

protected ArrayList<String> inputLabels
Constructor Detail

InputVectorDistanceMatrix

public InputVectorDistanceMatrix()
Method Detail

getMetric

public DistanceMetric getMetric()

getInputLabels

public ArrayList<String> getInputLabels()

getDistance

public abstract double getDistance(int x,
                                   int y)
Return the distance between input vectors x and y.


getNNearest

public int[] getNNearest(int x,
                         int num)
Return the n nearest vectors of input x. Basic implementation of the method, sub-classes might provide an optimised implementation.


getDistances

public double[] getDistances(int x)
Return the distances to all vectors from input x. This is a basic using getDistance(int, int), sub-classes might provide an optimised implementation.


numVectors

public int numVectors()

getDistancesFlat

public double[] getDistancesFlat()
Gets all the distances in a single flat array avoiding duplicates from the pairwise distances, thus of the size of numVectors * (numVectors - * 1) / 2.
This is a default implementation always constructing the array on the fly using the getDistance(int, int) method. Specific subclasses might provide better performing implementations, as e.g. LeightWeightMemoryInputVectorDistanceMatrix.


getDistancesFlatAsMatrix

public cern.colt.matrix.impl.DenseDoubleMatrix1D getDistancesFlatAsMatrix()

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

initFromFile

public static InputVectorDistanceMatrix initFromFile(String fileName)
                                              throws IOException,
                                                     SOMToolboxException
Factory method that reads and creates an InputVectorDistanceMatrix from the given file. Depending on the filename, returns either a RandomAccessFileInputVectorDistanceMatrix (if the filename ends with '.bin') or a LeightWeightMemoryInputVectorDistanceMatrix (all other cases).
TODO: maybe more intelligent checking for file type, possibly trying to read it as binary, and checking the first bytes for a file type or so.

Throws:
IOException
SOMToolboxException

flatArraySize

protected int flatArraySize()

rows

public int rows()

columns

public int columns()