O
- Object typepublic class PrecomputedDistanceMatrix<O> extends java.lang.Object implements DistanceIndex<O>, RangeIndex<O>, KNNIndex<O>
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.
Modifier and Type | Class and Description |
---|---|
static class |
PrecomputedDistanceMatrix.Factory<O>
Factory for the index.
|
private class |
PrecomputedDistanceMatrix.PrecomputedDistanceQuery
Distance query using the precomputed matrix.
|
private class |
PrecomputedDistanceMatrix.PrecomputedKNNQuery
kNN query using the distance matrix.
|
private class |
PrecomputedDistanceMatrix.PrecomputedRangeQuery
Range query using the distance matrix.
|
Modifier and Type | Field and Description |
---|---|
protected DistanceFunction<? super O> |
distanceFunction
Nested distance function.
|
protected DistanceQuery<O> |
distanceQuery
Nested distance query.
|
private DBIDRange |
ids
DBID range.
|
private static Logging |
LOG
Class logger.
|
private double[] |
matrix
Distance matrix.
|
protected Relation<O> |
relation
Data relation.
|
private int |
size
Size of DBID range.
|
Constructor and Description |
---|
PrecomputedDistanceMatrix(Relation<O> relation,
DBIDRange range,
DistanceFunction<? super O> distanceFunction)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
DistanceQuery<O> |
getDistanceQuery(DistanceFunction<? super O> distanceFunction,
java.lang.Object... hints)
Get a KNN query object for the given distance query and k.
|
KNNQuery<O> |
getKNNQuery(DistanceQuery<O> distanceQuery,
java.lang.Object... hints)
Get a KNN query object for the given distance query and k.
|
java.lang.String |
getLongName()
A "pretty" name for the result, for use in titles, captions and menus.
|
private int |
getOffset(int x,
int y)
Array offset computation.
|
RangeQuery<O> |
getRangeQuery(DistanceQuery<O> distanceQuery,
java.lang.Object... hints)
Get a range query object for the given distance query and k.
|
java.lang.String |
getShortName()
A short name for the result, useful for file names.
|
void |
initialize()
Initialize the index.
|
void |
logStatistics()
Send statistics to the logger, if enabled.
|
protected static int |
triangleSize(int x)
Compute the size of a complete x by x triangle (minus diagonal)
|
private static final Logging LOG
protected final DistanceFunction<? super O> distanceFunction
protected DistanceQuery<O> distanceQuery
private double[] matrix
private DBIDRange ids
private int size
public PrecomputedDistanceMatrix(Relation<O> relation, DBIDRange range, DistanceFunction<? super O> distanceFunction)
relation
- Data relationrange
- DBID rangedistanceFunction
- Distance functionpublic void initialize()
Index
initialize
in interface Index
protected static int triangleSize(int x)
x
- Offsetprivate int getOffset(int x, int y)
x
- X parametery
- Y parameterpublic void logStatistics()
Index
logStatistics
in interface Index
public java.lang.String getLongName()
Result
getLongName
in interface Result
public java.lang.String getShortName()
Result
getShortName
in interface Result
public DistanceQuery<O> getDistanceQuery(DistanceFunction<? super O> distanceFunction, java.lang.Object... hints)
DistanceIndex
getDistanceQuery
in interface DistanceIndex<O>
distanceFunction
- Distance function to use.hints
- Hints for the optimizernull
public KNNQuery<O> getKNNQuery(DistanceQuery<O> distanceQuery, java.lang.Object... hints)
KNNIndex
getKNNQuery
in interface KNNIndex<O>
distanceQuery
- Distance queryhints
- Hints for the optimizernull
public RangeQuery<O> getRangeQuery(DistanceQuery<O> distanceQuery, java.lang.Object... hints)
RangeIndex
getRangeQuery
in interface RangeIndex<O>
distanceQuery
- Distance queryhints
- Hints for the optimizernull
Copyright © 2019 ELKI Development Team. License information.