de.lmu.ifi.dbs.elki.distance.distancefunction.external
Class FileBasedDoubleDistanceFunction

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractDBIDDistanceFunction<DoubleDistance>
      extended by de.lmu.ifi.dbs.elki.distance.distancefunction.external.FileBasedDoubleDistanceFunction
All Implemented Interfaces:
DBIDDistanceFunction<DoubleDistance>, DistanceFunction<DBID,DoubleDistance>, InspectionUtilFrequentlyScanned, Parameterizable

@Title(value="File based double distance for database objects.")
@Description(value="Loads double distance values from an external text file.")
public class FileBasedDoubleDistanceFunction
extends AbstractDBIDDistanceFunction<DoubleDistance>

Provides a DistanceFunction that is based on double distances given by a distance matrix of an external file.


Nested Class Summary
static class FileBasedDoubleDistanceFunction.Parameterizer
          Parameterization class.
 
Field Summary
private  Map<DBIDPair,DoubleDistance> cache
          The distance cache
static OptionID MATRIX_ID
          Parameter that specifies the name of the distance matrix file.
static OptionID PARSER_ID
          Optional parameter to specify the parsers to provide a database, must extend DistanceParser.
 
Constructor Summary
FileBasedDoubleDistanceFunction(DistanceParser<DoubleDistance> parser, File matrixfile)
          Constructor.
 
Method Summary
 DoubleDistance distance(DBID id1, DBID id2)
          Returns the distance between the two objects specified by their objects ids.
 boolean equals(Object obj)
           
 DoubleDistance getDistanceFactory()
          Method to get the distance functions factory.
 DBIDs getIDs()
          Return a collection of all IDs in the cache.
private  void loadCache(DistanceParser<DoubleDistance> parser, File matrixfile)
           
 
Methods inherited from class de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractDBIDDistanceFunction
getInputTypeRestriction, instantiate, isMetric, isSymmetric
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATRIX_ID

public static final OptionID MATRIX_ID
Parameter that specifies the name of the distance matrix file.

Key: -distance.matrix


PARSER_ID

public static final OptionID PARSER_ID
Optional parameter to specify the parsers to provide a database, must extend DistanceParser. If this parameter is not set, NumberDistanceParser is used as parser for all input files.

Key: -distance.parser


cache

private Map<DBIDPair,DoubleDistance> cache
The distance cache

Constructor Detail

FileBasedDoubleDistanceFunction

public FileBasedDoubleDistanceFunction(DistanceParser<DoubleDistance> parser,
                                       File matrixfile)
Constructor.

Parameters:
parser - Parser
matrixfile - input file
Method Detail

distance

public DoubleDistance distance(DBID id1,
                               DBID id2)
Returns the distance between the two objects specified by their objects ids. If a cache is used, the distance value is looked up in the cache. If the distance does not yet exists in cache, it will be computed an put to cache. If no cache is used, the distance is computed.

Specified by:
distance in interface DBIDDistanceFunction<DoubleDistance>
Specified by:
distance in class AbstractDBIDDistanceFunction<DoubleDistance>
Parameters:
id1 - first object id
id2 - second object id
Returns:
the distance between the two objects specified by their objects ids

loadCache

private void loadCache(DistanceParser<DoubleDistance> parser,
                       File matrixfile)
                throws IOException
Throws:
IOException

getIDs

public DBIDs getIDs()
Return a collection of all IDs in the cache.

Returns:
Collection of all IDs in the cache.

getDistanceFactory

public DoubleDistance getDistanceFactory()
Description copied from interface: DistanceFunction
Method to get the distance functions factory.

Specified by:
getDistanceFactory in interface DistanceFunction<DBID,DoubleDistance>
Specified by:
getDistanceFactory in class AbstractDBIDDistanceFunction<DoubleDistance>
Returns:
Factory for distance objects

equals

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

Release 0.4.0 (2011-09-20_1324)