Package elki.distance.external
Class FileBasedSparseDoubleDistance
- java.lang.Object
-
- elki.distance.AbstractDatabaseDistance<DBID>
-
- elki.distance.AbstractDBIDRangeDistance
-
- elki.distance.external.FileBasedSparseDoubleDistance
-
- All Implemented Interfaces:
DBIDDistance
,DBIDRangeDistance
,Distance<DBID>
public class FileBasedSparseDoubleDistance extends AbstractDBIDRangeDistance
Distance function that is based on double distances given by a distance matrix of an external ASCII file.Note: parsing an ASCII file is rather expensive.
See
AsciiDistanceParser
for the default input format.TODO: use a
double[]
instead of the hash map?- Since:
- 0.1
- Author:
- Elke Achtert, Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FileBasedSparseDoubleDistance.Par
Parameterization class.-
Nested classes/interfaces inherited from class elki.distance.AbstractDatabaseDistance
AbstractDatabaseDistance.Instance<O>
-
-
Field Summary
Fields Modifier and Type Field Description private it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap
cache
The distance cacheprotected double
defaultDistance
Distance to return when not defined otherwise.private static Logging
LOG
Class logger.private java.net.URI
matrixfile
Input file of distance matrixprivate int
max
Minimum and maximum IDs seen.private int
min
Minimum and maximum IDs seen.private DistanceParser
parser
Distance parser
-
Constructor Summary
Constructors Constructor Description FileBasedSparseDoubleDistance(DistanceParser parser, java.net.URI matrixfile, double defaultDistance)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkRange(DBIDRange range)
Validate the range of DBIDs to use.double
distance(int i1, int i2)
Compute the distance for two integer offsets.boolean
equals(java.lang.Object obj)
<O extends DBID>
DistanceQuery<O>instantiate(Relation<O> relation)
Instantiate with a database to get the actual distance query.protected void
loadCache(int size, java.io.InputStream in)
Fill cache from an input stream.protected static long
makeKey(int i1, int i2)
Combine two integer ids into a long value.-
Methods inherited from class elki.distance.AbstractDBIDRangeDistance
distance, getInputTypeRestriction
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface elki.distance.Distance
isMetric, isSquared, isSymmetric
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
Class logger.
-
cache
private it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap cache
The distance cache
-
parser
private DistanceParser parser
Distance parser
-
matrixfile
private java.net.URI matrixfile
Input file of distance matrix
-
min
private int min
Minimum and maximum IDs seen.
-
max
private int max
Minimum and maximum IDs seen.
-
defaultDistance
protected double defaultDistance
Distance to return when not defined otherwise.
-
-
Constructor Detail
-
FileBasedSparseDoubleDistance
public FileBasedSparseDoubleDistance(DistanceParser parser, java.net.URI matrixfile, double defaultDistance)
Constructor.- Parameters:
parser
- Parsermatrixfile
- input filedefaultDistance
- Default distance (when undefined)
-
-
Method Detail
-
instantiate
public <O extends DBID> DistanceQuery<O> instantiate(Relation<O> relation)
Description copied from interface:Distance
Instantiate with a database to get the actual distance query.- Specified by:
instantiate
in interfaceDistance<DBID>
- Overrides:
instantiate
in classAbstractDBIDRangeDistance
- Parameters:
relation
- The representation to use- Returns:
- Actual distance query.
-
distance
public double distance(int i1, int i2)
Description copied from interface:DBIDRangeDistance
Compute the distance for two integer offsets.- Parameters:
i1
- First offseti2
- Second offset- Returns:
- Distance
-
loadCache
protected void loadCache(int size, java.io.InputStream in)
Fill cache from an input stream.- Parameters:
size
- Expected sizein
- Input stream
-
makeKey
protected static final long makeKey(int i1, int i2)
Combine two integer ids into a long value.- Parameters:
i1
- First idi2
- Second id- Returns:
- Combined value
-
checkRange
public void checkRange(DBIDRange range)
Description copied from interface:DBIDRangeDistance
Validate the range of DBIDs to use. This will log a warning if an obvious mismatch was found.- Parameters:
range
- DBID range
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-