Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.distance.distancefunction.external
Class FileBasedFloatDistanceFunction<V extends DatabaseObject>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.logging.AbstractLoggable
      extended by de.lmu.ifi.dbs.elki.distance.AbstractMeasurementFunction<O,D>
          extended by de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractDistanceFunction<V,FloatDistance>
              extended by de.lmu.ifi.dbs.elki.distance.distancefunction.external.FileBasedFloatDistanceFunction<V>
Type Parameters:
V - object type
All Implemented Interfaces:
DistanceFunction<V,FloatDistance>, MeasurementFunction<V,FloatDistance>, Parameterizable

@Title(value="File based float distance for database objects.")
@Description(value="Loads float distance values from an external text file.")
public class FileBasedFloatDistanceFunction<V extends DatabaseObject>
extends AbstractDistanceFunction<V,FloatDistance>
implements Parameterizable

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

Author:
Elke Achtert

Field Summary
private  Map<Pair<Integer,Integer>,FloatDistance> cache
           
static OptionID MATRIX_ID
          OptionID for MATRIX_PARAM
private  FileParameter MATRIX_PARAM
          Parameter that specifies the name of the directory to be re-parsed.
private  DistanceParser<V,FloatDistance> parser
           
static OptionID PARSER_ID
          OptionID for PARSER_PARAM
private  ObjectParameter<DistanceParser<V,FloatDistance>> PARSER_PARAM
          Optional parameter to specify the parsers to provide a database, must extend DistanceParser.
 
Fields inherited from class de.lmu.ifi.dbs.elki.distance.AbstractMeasurementFunction
distanceFactory
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug, logger
 
Constructor Summary
FileBasedFloatDistanceFunction(Parameterization config)
          Constructor, adhering to Parameterizable
 
Method Summary
 FloatDistance distance(Integer id1, Integer id2)
          Returns the distance between the two objects specified by their objects ids.
 FloatDistance distance(Integer id1, V o2)
          Returns the distance between the two specified objects.
 FloatDistance distance(V o1, V o2)
          Computes the distance between two given DatabaseObjects according to this distance function.
private  void loadCache(File matrixfile)
           
 
Methods inherited from class de.lmu.ifi.dbs.elki.distance.AbstractMeasurementFunction
getDatabase, getDistanceFactory, infiniteDistance, nullDistance, setDatabase, undefinedDistance, valueOf
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, progress, verbose, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.distance.MeasurementFunction
getDistanceFactory, infiniteDistance, nullDistance, setDatabase, undefinedDistance, valueOf
 

Field Detail

MATRIX_ID

public static final OptionID MATRIX_ID
OptionID for MATRIX_PARAM


MATRIX_PARAM

private final FileParameter MATRIX_PARAM
Parameter that specifies the name of the directory to be re-parsed.

Key: -distance.matrix


PARSER_ID

public static final OptionID PARSER_ID
OptionID for PARSER_PARAM


PARSER_PARAM

private final ObjectParameter<DistanceParser<V extends DatabaseObject,FloatDistance>> PARSER_PARAM
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


parser

private DistanceParser<V extends DatabaseObject,FloatDistance> parser

cache

private Map<Pair<Integer,Integer>,FloatDistance> cache
Constructor Detail

FileBasedFloatDistanceFunction

public FileBasedFloatDistanceFunction(Parameterization config)
Constructor, adhering to Parameterizable

Parameters:
config - Parameterization
Method Detail

distance

public FloatDistance distance(V o1,
                              V o2)
Computes the distance between two given DatabaseObjects according to this distance function.

Specified by:
distance in interface DistanceFunction<V extends DatabaseObject,FloatDistance>
Parameters:
o1 - first DatabaseObject
o2 - second DatabaseObject
Returns:
the distance between two given DatabaseObject according to this distance function

distance

public FloatDistance distance(Integer id1,
                              V o2)
Returns the distance between the two specified objects.

Specified by:
distance in interface DistanceFunction<V extends DatabaseObject,FloatDistance>
Overrides:
distance in class AbstractDistanceFunction<V extends DatabaseObject,FloatDistance>
Parameters:
id1 - first object id
o2 - second DatabaseObject
Returns:
the distance between the two objects specified by their objects ids

distance

public FloatDistance distance(Integer id1,
                              Integer 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 DistanceFunction<V extends DatabaseObject,FloatDistance>
Overrides:
distance in class AbstractDistanceFunction<V extends DatabaseObject,FloatDistance>
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(File matrixfile)
                throws IOException
Throws:
IOException

Release 0.3 (2010-03-31_1612)