template class cvflann::LshIndex

Overview

Randomized kd-tree index

Contains the k-d trees and other information for indexing a set of points for nearest-neighbor matching. More…

#include <lsh_index.h>

template <typename Distance>
class LshIndex: public cvflann::NNIndex
{
public:
    // typedefs

    typedef Distance::ResultType DistanceType;
    typedef Distance::ElementType ElementType;

    // structs

    struct SortScoreIndexPairOnSecond;

    // construction

    LshIndex(
        const Matrix<ElementType>& input_data,
        const IndexParams& params = LshIndexParams(),
        Distance d = Distance()
        );

    LshIndex(const LshIndex&);

    // methods

    virtual
    void
    buildIndex();

    virtual
    void
    findNeighbors(
        ResultSet<DistanceType>& result,
        const ElementType* vec,
        const SearchParams&
        );

    virtual
    IndexParams
    getParameters() const;

    virtual
    flann_algorithm_t
    getType() const;

    virtual
    void
    knnSearch(
        const Matrix<ElementType>& queries,
        Matrix<int>& indices,
        Matrix<DistanceType>& dists,
        int knn,
        const SearchParams& params
        );

    virtual
    void
    loadIndex(FILE* stream);

    LshIndex&
    operator=(const LshIndex&);

    virtual
    void
    saveIndex(FILE* stream);

    virtual
    size_t
    size() const;

    virtual
    int
    usedMemory() const;

    virtual
    size_t
    veclen() const;
};

Inherited Members

public:
    // methods

    virtual
    void
    buildIndex() = 0;

    virtual
    void
    findNeighbors(
        ResultSet<DistanceType>& result,
        const ElementType* vec,
        const SearchParams& searchParams
        ) = 0;

    virtual
    IndexParams
    getParameters() const = 0;

    virtual
    flann_algorithm_t
    getType() const = 0;

    virtual
    void
    knnSearch(
        const Matrix<ElementType>& queries,
        Matrix<int>& indices,
        Matrix<DistanceType>& dists,
        int knn,
        const SearchParams& params
        );

    virtual
    void
    loadIndex(FILE* stream) = 0;

    virtual
    int
    radiusSearch(
        const Matrix<ElementType>& query,
        Matrix<int>& indices,
        Matrix<DistanceType>& dists,
        float radius,
        const SearchParams& params
        );

    virtual
    void
    saveIndex(FILE* stream) = 0;

    virtual
    size_t
    size() const = 0;

    virtual
    int
    usedMemory() const = 0;

    virtual
    size_t
    veclen() const = 0;

Detailed Documentation

Randomized kd-tree index

Contains the k-d trees and other information for indexing a set of points for nearest-neighbor matching.

Construction

LshIndex(
    const Matrix<ElementType>& input_data,
    const IndexParams& params = LshIndexParams(),
    Distance d = Distance()
    )

Constructor

Parameters:

input_data dataset with the input features
params parameters passed to the LSH algorithm
d the distance used

Methods

virtual
void
buildIndex()

Builds the index

virtual
void
findNeighbors(
    ResultSet<DistanceType>& result,
    const ElementType* vec,
    const SearchParams&
    )

Find set of nearest neighbors to vec. Their indices are stored inside the result object.

Params: result = the result object in which the indices of the nearest-neighbors are stored vec = the vector for which to search the nearest neighbors maxCheck = the maximum number of restarts (in a best-bin-first manner)

virtual
IndexParams
getParameters() const

Returns:

The index parameters

virtual
flann_algorithm_t
getType() const

Returns:

The index type (kdtree, kmeans,…)

virtual
void
knnSearch(
    const Matrix<ElementType>& queries,
    Matrix<int>& indices,
    Matrix<DistanceType>& dists,
    int knn,
    const SearchParams& params
    )

Perform k-nearest neighbor search.

Parameters:

queries The query points for which to find the nearest neighbors
indices The indices of the nearest neighbors found
dists Distances to the nearest neighbors found
knn Number of nearest neighbors to return
params Search parameters
virtual
void
loadIndex(FILE* stream)

Loads the index from a stream.

Parameters:

stream The stream from which the index is loaded
virtual
void
saveIndex(FILE* stream)

Saves the index to a stream.

Parameters:

stream The stream to save the index to
virtual
size_t
size() const

Returns size of index.

virtual
int
usedMemory() const

Computes the index memory usage Returns: memory used by the index

virtual
size_t
veclen() const

Returns the length of an index feature.