de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.mktrees.mkcop
Class MkCoPTree<O,D extends NumberDistance<D,?>>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.index.tree.IndexTree<N,E>
      extended by de.lmu.ifi.dbs.elki.index.tree.metrical.MetricalIndexTree<O,D,N,E>
          extended by de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.AbstractMTree<O,D,N,E>
              extended by de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.mktrees.AbstractMkTree<O,D,MkCoPTreeNode<O,D>,MkCoPEntry<D>>
                  extended by de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.mktrees.mkcop.MkCoPTree<O,D>
Type Parameters:
O - Object type
D - Distance type
Direct Known Subclasses:
MkCoPTreeIndex

public class MkCoPTree<O,D extends NumberDistance<D,?>>
extends AbstractMkTree<O,D,MkCoPTreeNode<O,D>,MkCoPEntry<D>>

MkCopTree is a metrical index structure based on the concepts of the M-Tree supporting efficient processing of reverse k nearest neighbor queries for parameter k < kmax.


Field Summary
(package private)  int k_max
          Parameter k.
private  double[] log_k
          The values of log(1),..
private static Logging logger
          The logger for this class.
private  QueryStatistic rkNNStatistics
          Provides some statistics about performed reverse knn-queries.
 
Fields inherited from class de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.AbstractMTree
distanceFunction, distanceQuery, extraIntegrityChecks
 
Fields inherited from class de.lmu.ifi.dbs.elki.index.tree.IndexTree
dirCapacity, dirMinimum, initialized, leafCapacity, leafMinimum
 
Constructor Summary
MkCoPTree(PageFile<MkCoPTreeNode<O,D>> pagefile, DistanceQuery<O,D> distanceQuery, DistanceFunction<O,D> distanceFunction, int k_max)
          Constructor.
 
Method Summary
private  void adjustApproximatedKNNDistances(MkCoPEntry<D> entry, Map<DBID,KNNList<D>> knnLists)
          Adjusts the knn distance in the subtree of the specified root entry.
private  void approximateKnnDistances(MkCoPLeafEntry<D> entry, KNNList<D> knnDistances)
          Computes logarithmic skew (fractal dimension ie. m) and in kappx[0] and kappx[1] the non-logarithmic values of the approximated first and last nearest neighbor distances
private  ApproximationLine approximateLowerHull(ConvexHull convexHull, double[] log_k, double sum_log_k, double sum_log_k2, double[] log_kDist, double sum_log_kDist, double sum_log_k_kDist)
          Approximates the lower hull.
private  ApproximationLine approximateUpperHull_OLD(ConvexHull convexHull, double[] log_k, double sum_log_k, double sum_log_k2, double[] log_kDist, double sum_log_kDist, double sum_log_k_kDist)
           
private  ApproximationLine approximateUpperHull_PAPER(ConvexHull convexHull, double[] log_k, double sum_log_k, double sum_log_k2, double[] log_kDist, double sum_log_kDist, double sum_log_k_kDist)
           
private  ApproximationLine approximateUpperHull(ConvexHull convexHull, double[] log_k, double[] log_kDist)
           
 void clearRkNNStatistics()
          Clears the values of the statistic for performed rknn queries
protected  MkCoPEntry<D> createNewDirectoryEntry(MkCoPTreeNode<O,D> node, DBID routingObjectID, D parentDistance)
          Creates a new directory entry representing the specified node.
protected  MkCoPTreeNode<O,D> createNewDirectoryNode()
          Creates a new directory node with the specified capacity.
protected  MkCoPTreeNode<O,D> createNewLeafNode()
          Creates a new leaf node with the specified capacity.
protected  MkCoPEntry<D> createRootEntry()
          Creates an entry representing the root node.
private  void doReverseKNNQuery(int k, DBID q, List<DistanceResultPair<D>> result, ModifiableDBIDs candidates)
          Performs a reverse knn query.
 int getK_max()
          Returns the value of the k_max parameter.
protected  Logging getLogger()
          Get the (STATIC) logger for this class.
 QueryStatistic getRkNNStatistics()
          Returns the statistic for performed rknn queries.
protected  void initializeCapacities(MkCoPEntry<D> exampleLeaf)
          Determines the maximum and minimum number of entries in a node.
 void insert(MkCoPEntry<D> entry, boolean withPreInsert)
          Inserts the specified object into this M-Tree.
 void insertAll(List<MkCoPEntry<D>> entries)
          Bulk insert.
private  double optimize(int k0, int kmax, double sumx, double sumx2, double xp, double yp, double sumxy, double sumy)
           
protected  void preInsert(MkCoPEntry<D> entry)
          Performs necessary operations before inserting the specified entry.
 List<DistanceResultPair<D>> reverseKNNQuery(DBID id, int k)
          Performs a reverse k-nearest neighbor query for the given object ID.
private  double ssqerr(int k0, int kmax, double[] logk, double[] log_kDist, double m, double t)
           
 
Methods inherited from class de.lmu.ifi.dbs.elki.index.tree.metrical.mtreevariants.AbstractMTree
batchNN, createEmptyRoot, distance, distance, doKNNQuery, getDistanceFactory, getDistanceFunction, getDistanceQuery, getHeight, getLeaves, getSortedEntries, getSortedEntries, toString
 
Methods inherited from class de.lmu.ifi.dbs.elki.index.tree.IndexTree
createHeader, deleteNode, getFile, getNode, getNode, getPageFileStatistics, getPageID, getPageSize, getRoot, getRootEntry, getRootID, getRootPath, initialize, initialize, initializeFromFile, isRoot, postDelete, writeNode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final Logging logger
The logger for this class.


k_max

int k_max
Parameter k.


log_k

private double[] log_k
The values of log(1),..,log(k_max)


rkNNStatistics

private QueryStatistic rkNNStatistics
Provides some statistics about performed reverse knn-queries.

Constructor Detail

MkCoPTree

public MkCoPTree(PageFile<MkCoPTreeNode<O,D>> pagefile,
                 DistanceQuery<O,D> distanceQuery,
                 DistanceFunction<O,D> distanceFunction,
                 int k_max)
Constructor.

Parameters:
pagefile - Page file
distanceQuery - Distance query
distanceFunction - Distance function
k_max - Maximum value of k supported
Method Detail

preInsert

protected void preInsert(MkCoPEntry<D> entry)
Description copied from class: IndexTree
Performs necessary operations before inserting the specified entry.

Overrides:
preInsert in class IndexTree<MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Parameters:
entry - the entry to be inserted
Throws:
UnsupportedOperationException - since this operation is not supported

insert

public void insert(MkCoPEntry<D> entry,
                   boolean withPreInsert)
Description copied from class: AbstractMTree
Inserts the specified object into this M-Tree.

Overrides:
insert in class AbstractMTree<O,D extends NumberDistance<D,?>,MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Parameters:
entry - the entry to be inserted
withPreInsert - if this flag is true, the preInsert method will be called before inserting the object
Throws:
UnsupportedOperationException - since this operation is not supported

insertAll

public void insertAll(List<MkCoPEntry<D>> entries)
Description copied from class: AbstractMTree
Bulk insert.

Overrides:
insertAll in class AbstractMTree<O,D extends NumberDistance<D,?>,MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>

reverseKNNQuery

public List<DistanceResultPair<D>> reverseKNNQuery(DBID id,
                                                   int k)
Performs a reverse k-nearest neighbor query for the given object ID. The query result is in ascending order to the distance to the query object.

Specified by:
reverseKNNQuery in class AbstractMkTree<O,D extends NumberDistance<D,?>,MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Parameters:
id - the query object id
k - the number of nearest neighbors to be returned
Returns:
a List of the query results

getRkNNStatistics

public QueryStatistic getRkNNStatistics()
Returns the statistic for performed rknn queries.

Returns:
the statistic for performed rknn queries

clearRkNNStatistics

public void clearRkNNStatistics()
Clears the values of the statistic for performed rknn queries


getK_max

public int getK_max()
Returns the value of the k_max parameter.

Returns:
the value of the k_max parameter

initializeCapacities

protected void initializeCapacities(MkCoPEntry<D> exampleLeaf)
Determines the maximum and minimum number of entries in a node.

Specified by:
initializeCapacities in class IndexTree<MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Parameters:
exampleLeaf - an object that will be stored in the index

doReverseKNNQuery

private void doReverseKNNQuery(int k,
                               DBID q,
                               List<DistanceResultPair<D>> result,
                               ModifiableDBIDs candidates)
Performs a reverse knn query.

Parameters:
k - the parameter k of the rknn query
q - the id of the query object
result - holds the true results (they need not to be refined)
candidates - holds possible candidates for the result (they need a refinement)

adjustApproximatedKNNDistances

private void adjustApproximatedKNNDistances(MkCoPEntry<D> entry,
                                            Map<DBID,KNNList<D>> knnLists)
Adjusts the knn distance in the subtree of the specified root entry.

Parameters:
entry - the root entry of the current subtree
knnLists - a map of knn lists for each leaf entry

ssqerr

private double ssqerr(int k0,
                      int kmax,
                      double[] logk,
                      double[] log_kDist,
                      double m,
                      double t)

optimize

private double optimize(int k0,
                        int kmax,
                        double sumx,
                        double sumx2,
                        double xp,
                        double yp,
                        double sumxy,
                        double sumy)

approximateKnnDistances

private void approximateKnnDistances(MkCoPLeafEntry<D> entry,
                                     KNNList<D> knnDistances)
Computes logarithmic skew (fractal dimension ie. m) and in kappx[0] and kappx[1] the non-logarithmic values of the approximated first and last nearest neighbor distances

Parameters:
knnDistances - TODO: Spezialbehandlung fuer identische Punkte in DB (insbes. Distanz 0)

approximateLowerHull

private ApproximationLine approximateLowerHull(ConvexHull convexHull,
                                               double[] log_k,
                                               double sum_log_k,
                                               double sum_log_k2,
                                               double[] log_kDist,
                                               double sum_log_kDist,
                                               double sum_log_k_kDist)
Approximates the lower hull.

Parameters:
convexHull -
log_kDist -
sum_log_kDist -
sum_log_k_kDist -

approximateUpperHull

private ApproximationLine approximateUpperHull(ConvexHull convexHull,
                                               double[] log_k,
                                               double[] log_kDist)

approximateUpperHull_PAPER

private ApproximationLine approximateUpperHull_PAPER(ConvexHull convexHull,
                                                     double[] log_k,
                                                     double sum_log_k,
                                                     double sum_log_k2,
                                                     double[] log_kDist,
                                                     double sum_log_kDist,
                                                     double sum_log_k_kDist)

approximateUpperHull_OLD

private ApproximationLine approximateUpperHull_OLD(ConvexHull convexHull,
                                                   double[] log_k,
                                                   double sum_log_k,
                                                   double sum_log_k2,
                                                   double[] log_kDist,
                                                   double sum_log_kDist,
                                                   double sum_log_k_kDist)

createNewLeafNode

protected MkCoPTreeNode<O,D> createNewLeafNode()
Creates a new leaf node with the specified capacity.

Specified by:
createNewLeafNode in class IndexTree<MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Returns:
a new leaf node

createNewDirectoryNode

protected MkCoPTreeNode<O,D> createNewDirectoryNode()
Creates a new directory node with the specified capacity.

Specified by:
createNewDirectoryNode in class IndexTree<MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Returns:
a new directory node

createNewDirectoryEntry

protected MkCoPEntry<D> createNewDirectoryEntry(MkCoPTreeNode<O,D> node,
                                                DBID routingObjectID,
                                                D parentDistance)
Creates a new directory entry representing the specified node.

Specified by:
createNewDirectoryEntry in class AbstractMTree<O,D extends NumberDistance<D,?>,MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Parameters:
node - the node to be represented by the new entry
routingObjectID - the id of the routing object of the node
parentDistance - the distance from the routing object of the node to the routing object of the parent node
Returns:
the newly created directory entry

createRootEntry

protected MkCoPEntry<D> createRootEntry()
Creates an entry representing the root node.

Specified by:
createRootEntry in class IndexTree<MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Returns:
an entry representing the root node

getLogger

protected Logging getLogger()
Description copied from class: IndexTree
Get the (STATIC) logger for this class.

Specified by:
getLogger in class IndexTree<MkCoPTreeNode<O,D extends NumberDistance<D,?>>,MkCoPEntry<D extends NumberDistance<D,?>>>
Returns:
the static logger

Release 0.4.0 (2011-09-20_1324)