STANN

STANN‎ > ‎User Guide‎ > ‎

SFCNN Specs


To Initialize

sfcnn is a general K-nearest neighbor search data structure.

sfcnn< MyPointType,
             Dimension,
             CoordType >
                      NN(&FirstDataPoint, Size);

  • MyPointType
    • This can be any user defined point type, as long as the
      coordinates can be referenced by the bracket operator.
      For example, vector<double> or float[], are both valid.
  • Dimension  
    • This is the dimension of the points in the data set.
  • CoordType
    • This is the type of coordinate the points use.
      Currently supported types are:
      (unsigned) short, int, long
      short, int, long
      float, double, long double
    • IMPORTANT! Searches on integer types operate
      about 3x faster than floating point types.  If you
      can use them, it is recommended.
  • FirstPoint
    • A pointer to the first point in the input data set
  • Size
    • The size of the input data set

  

To Make A Query

Queries are thread-safe and may be done in
parallel using openmp, posix threads, etc.

NN.ksearch(MyPointType Q,
                       int k,
                       vector<unsigned long> answer,
                       double epsilon)
or

NN.ksearch(MyPointType Q,
                       int k,
                       vector<unsigned long> answer,
                       vector<double> distance,
                       double epsilon)

  • Q
    • A query point of type MyPointType.
  • k
    • The number of nearest neighbors
      to return.  Ie. k=5 will return the 5
      nearest points to Q in the data set
  • answer
    •  This vector will contain the indexes
      of the k nearest data points.  These
      indexes are based off the FirstDataPoint
      given at initialization.  If the points have
      been moved, the indexes will be
      incorrect.
  • distance
    • This vector will contain the squared
      distance from the query point to the
      corresponding data point

  • epsilon
    • This parameter is optional, and defaults
      to 0. This approximation parmater garuntees
      that the distance to the farthest returned
      point is no farther than (1+eplsilon)*(distance
      to actual k nearest neighbor).  To compute
      an exact solution leave it to be 0.