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.utilities.optionhandling.AbstractParameterizable
          extended by de.lmu.ifi.dbs.elki.distance.AbstractMeasurementFunction<O,D>
              extended by de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractDistanceFunction<O,FloatDistance>
                  extended by de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractFloatDistanceFunction<V>
                      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

public class FileBasedFloatDistanceFunction<V extends DatabaseObject>
extends AbstractFloatDistanceFunction<V>

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  ClassParameter<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
INFINITY_PATTERN
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
optionHandler
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug, logger
 
Constructor Summary
FileBasedFloatDistanceFunction()
          Constructor
 
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)
           
 List<String> setParameters(List<String> args)
          Grabs all specified options from the option handler.
 String shortDescription()
          Returns a description of the class and the required parameters.
 
Methods inherited from class de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractFloatDistanceFunction
infiniteDistance, nullDistance, undefinedDistance, valueOf
 
Methods inherited from class de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractDistanceFunction
isInfiniteDistance, isNullDistance, isUndefinedDistance
 
Methods inherited from class de.lmu.ifi.dbs.elki.distance.AbstractMeasurementFunction
getDatabase, matches, requiredInputPattern, setDatabase, setRequiredInputPattern
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
addOption, addParameterizable, addParameterizable, checkGlobalParameterConstraints, collectOptions, getAttributeSettings, getParameters, rememberParametersExcept, removeOption, removeParameterizable
 
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
requiredInputPattern, setDatabase
 
Methods inherited from interface de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameterizable
checkGlobalParameterConstraints, collectOptions, getParameters
 

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 ClassParameter<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()
Constructor

Method Detail

distance

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

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

shortDescription

public String shortDescription()
Returns a description of the class and the required parameters. This description should be suitable for a usage description.

Specified by:
shortDescription in interface Parameterizable
Overrides:
shortDescription in class AbstractMeasurementFunction<V extends DatabaseObject,FloatDistance>
Returns:
String a description of the class and the required parameters

setParameters

public List<String> setParameters(List<String> args)
                           throws ParameterException
Description copied from class: AbstractParameterizable
Grabs all specified options from the option handler. Any extending class should call this method first and return the returned array without further changes, but after setting further required parameters. An example for overwriting this method taking advantage from the previously (in superclasses) defined options would be:

 {
   List remainingParameters = super.setParameters(args);
   // set parameters for your class
   // for example like this:
   if(isSet(MY_PARAM_VALUE_PARAM))
   {
      myParamValue = getParameterValue(MY_PARAM_VALUE_PARAM);
   }
   .
   .
   .
   return remainingParameters;
   // or in case of attributes requesting parameters themselves
   // return parameterizableAttribbute.setParameters(remainingParameters);
 }
 

Specified by:
setParameters in interface Parameterizable
Overrides:
setParameters in class AbstractParameterizable
Parameters:
args - parameters to set the attributes accordingly to
Returns:
a list containing the unused parameters
Throws:
ParameterException - in case of wrong parameter-setting

loadCache

private void loadCache(File matrixfile)
                throws IOException
Throws:
IOException

Release 0.2.1 (2009-07-13_1605)