Class PrecomputedDistanceMatrix<O>
- java.lang.Object
-
- elki.index.distancematrix.PrecomputedDistanceMatrix<O>
-
- Type Parameters:
O- Object type
- All Implemented Interfaces:
DistanceIndex<O>,DistancePriorityIndex<O>,Index,KNNIndex<O>,RangeIndex<O>
public class PrecomputedDistanceMatrix<O> extends java.lang.Object implements DistanceIndex<O>, RangeIndex<O>, KNNIndex<O>, DistancePriorityIndex<O>
Distance matrix, for precomputing similarity for a small data set.This class uses a linear memory layout (not a ragged array), and assumes symmetry as well as strictness. This way, it only stores the upper triangle matrix with double precision. It has to store (n-1) * (n-2) distance values in memory, requiring 8 * (n-1) * (n-2) bytes. Since Java has a size limit of arrays of 31 bits (signed integer), we can store at most \(2^{16}\) objects (precisely, 65536 objects) in a single array, which needs about 16 GB of RAM.
- Since:
- 0.7.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPrecomputedDistanceMatrix.Factory<O>Factory for the index.classPrecomputedDistanceMatrix.PrecomputedDistancePrioritySearcherRange query using the distance matrix.classPrecomputedDistanceMatrix.PrecomputedDistanceQueryDistance query using the precomputed matrix.classPrecomputedDistanceMatrix.PrecomputedKNNQuerykNN query using the distance matrix.classPrecomputedDistanceMatrix.PrecomputedRangeQueryRange query using the distance matrix.
-
Field Summary
Fields Modifier and Type Field Description protected Distance<? super O>distanceNested distance function.private DBIDRangeidsDBID range.private static LoggingLOGClass logger.private double[]matrixDistance matrix.protected java.lang.ref.WeakReference<Relation<O>>refrelationData relation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DistanceQuery<O>getDistanceQuery(Distance<? super O> distanceFunction)Get a KNN query object for the given distance query and k.private intgetOffset(int x, int y)Array offset computation.voidinitialize()Initialize the index.KNNSearcher<DBIDRef>kNNByDBID(DistanceQuery<O> distanceQuery, int maxk, int flags)Get a KNN query object for the given distance query and k.KNNSearcher<O>kNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)Get a KNN query object for the given distance query and k.voidlogStatistics()Send statistics to the logger, if enabled.PrioritySearcher<DBIDRef>priorityByDBID(DistanceQuery<O> distanceQuery, double maxrange, int flags)Get a priority search object.PrioritySearcher<O>priorityByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)Get a priority search object.RangeSearcher<DBIDRef>rangeByDBID(DistanceQuery<O> distanceQuery, double maxrange, int flags)Get a range query object for the given distance query and k.RangeSearcher<O>rangeByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)Get a range query object for the given distance query and k.protected static inttriangleSize(int x)Compute the size of a complete x by x triangle (minus diagonal)
-
-
-
Method Detail
-
initialize
public void initialize()
Description copied from interface:IndexInitialize the index. For static indexes, this is the moment the index is bulk loaded.- Specified by:
initializein interfaceIndex
-
triangleSize
protected static int triangleSize(int x)
Compute the size of a complete x by x triangle (minus diagonal)- Parameters:
x- Offset- Returns:
- Size of complete triangle
-
getOffset
private int getOffset(int x, int y)Array offset computation.- Parameters:
x- X parametery- Y parameter- Returns:
- Array offset
-
logStatistics
public void logStatistics()
Description copied from interface:IndexSend statistics to the logger, if enabled.Note: you must have set the logging level appropriately before initializing the index! Otherwise, the index might not have collected the desired statistics.
- Specified by:
logStatisticsin interfaceIndex
-
getDistanceQuery
public DistanceQuery<O> getDistanceQuery(Distance<? super O> distanceFunction)
Description copied from interface:DistanceIndexGet a KNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
getDistanceQueryin interfaceDistanceIndex<O>- Parameters:
distanceFunction- Distance function to use.- Returns:
- KNN Query object or
null
-
kNNByObject
public KNNSearcher<O> kNNByObject(DistanceQuery<O> distanceQuery, int maxk, int flags)
Description copied from interface:KNNIndexGet a KNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
kNNByObjectin interfaceDistancePriorityIndex<O>- Specified by:
kNNByObjectin interfaceKNNIndex<O>- Parameters:
distanceQuery- Distance querymaxk- Maximum value of kflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
kNNByDBID
public KNNSearcher<DBIDRef> kNNByDBID(DistanceQuery<O> distanceQuery, int maxk, int flags)
Description copied from interface:KNNIndexGet a KNN query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
-
rangeByObject
public RangeSearcher<O> rangeByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)
Description copied from interface:RangeIndexGet a range query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rangeByObjectin interfaceDistancePriorityIndex<O>- Specified by:
rangeByObjectin interfaceRangeIndex<O>- Parameters:
distanceQuery- Distance querymaxrange- Maximum rangeflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
rangeByDBID
public RangeSearcher<DBIDRef> rangeByDBID(DistanceQuery<O> distanceQuery, double maxrange, int flags)
Description copied from interface:RangeIndexGet a range query object for the given distance query and k.This function MAY return null, when the given distance is not supported!
- Specified by:
rangeByDBIDin interfaceRangeIndex<O>- Parameters:
distanceQuery- Distance querymaxrange- Maximum rangeflags- Hints for the optimizer- Returns:
- KNN Query object or
null
-
priorityByObject
public PrioritySearcher<O> priorityByObject(DistanceQuery<O> distanceQuery, double maxrange, int flags)
Description copied from interface:DistancePriorityIndexGet a priority search object.- Specified by:
priorityByObjectin interfaceDistancePriorityIndex<O>- Parameters:
distanceQuery- Distance querymaxrange- Maximum search range (may beDouble.POSITIVE_INFINITYflags- Optimizer hints- Returns:
- Priority searcher
-
priorityByDBID
public PrioritySearcher<DBIDRef> priorityByDBID(DistanceQuery<O> distanceQuery, double maxrange, int flags)
Description copied from interface:DistancePriorityIndexGet a priority search object.- Specified by:
priorityByDBIDin interfaceDistancePriorityIndex<O>- Parameters:
distanceQuery- Distance querymaxrange- Maximum search range (may beDouble.POSITIVE_INFINITYflags- Optimizer hints- Returns:
- Priority searcher
-
-