没有合适的资源?快使用搜索试试~ 我知道了~
flann_manual-1.8.4(FLNN手册).pdf
需积分: 11 17 下载量 106 浏览量
2019-01-07
10:37:04
上传
评论
收藏 279KB PDF 举报
温馨提示
试读
29页
2013版FLNN手册,flann_manual-1.8.4.pdf,flann快速最近邻搜索库的手册,快速入门用法,主要类和方法的介绍等等
资源推荐
资源详情
资源评论
FLANN - Fast Library for Approximate Nearest
Neighbors
User Manual
Marius Muja, mariusm@cs.ubc.ca
David Lowe, lowe@cs.ubc.ca
January 24, 2013
1 Introduction
We can define the nearest neighbor search (NSS) problem in the following way:
given a set of points P = p
1
, p
2
, . . . , p
n
in a metric space X, these points must
be preprocessed in such a way that given a new query point q ∈ X, finding the
point in P that is nearest to q can be done quickly.
The problem of nearest neighbor search is one of major importance in a
variety of applications such as image recognition, data compression, pattern
recognition and classification, machine learning, document retrieval systems,
statistics and data analysis. However, solving this problem in high dimensional
spaces seems to be a very difficult task and there is no algorithm that performs
significantly better than the standard brute-force search. This has lead to an
increasing interest in a class of algorithms that perform approximate nearest
neighbor searches, which have proven to be a good-enough approximation in
most practical applications and in most cases, orders of magnitude faster that
the algorithms performing the exact searches.
FLANN (Fast Library for Approximate Nearest Neighbors) is a library for
performing fast approximate nearest neighbor searches. FLANN is written in
the C++ programming language. FLANN can be easily used in many contexts
through the C, MATLAB and Python bindings provided with the library.
1.1 Quick Start
This section contains small examples of how to use the FLANN library from
different programming languages (C++, C, MATLAB and Python).
• C++
// file flann_example.cpp
#include <flann/flann.hpp>
#include <flann/io/hdf5.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int nn = 3;
flann::Matrix<float> dataset;
flann::Matrix<float> query;
flann::load_from_file(dataset, "dataset.hdf5","dataset");
flann::load_from_file(query, "dataset.hdf5","query");
flann::Matrix<int> indices(new int[query.rows*nn], query.rows, nn);
flann::Matrix<float> dists(new float[query.rows*nn], query.rows, nn);
// construct an randomized kd-tree index using 4 kd-trees
flann::Index<flann::L2<float> > index(dataset, flann::KDTreeIndexParams(4));
index.buildIndex();
// do a knn search, using 128 checks
index.knnSearch(query, indices, dists, nn, flann::SearchParams(128));
flann::save_to_file(indices,"result.hdf5","result");
1
delete[] dataset.ptr();
delete[] query.ptr();
delete[] indices.ptr();
delete[] dists.ptr();
return 0;
}
• C
/* file flann_example.c */
#include "flann.h"
#include <stdio.h>
#include <assert.h>
/* Function that reads a dataset */
float* read_points(char* filename, int *rows, int *cols);
int main(int argc, char** argv)
{
int rows,cols;
int t_rows, t_cols;
float speedup;
/* read dataset points from file dataset.dat */
float* dataset = read_points("dataset.dat", &rows, &cols);
float* testset = read_points("testset.dat", &t_rows, &t_cols);
/* points in dataset and testset should have the same dimensionality */
assert(cols==t_cols);
/* number of nearest neighbors to search */
int nn = 3;
/* allocate memory for the nearest-neighbors indices */
int* result = (int*) malloc(t_rows*nn*sizeof(int));
/* allocate memory for the distances */
float* dists = (float*) malloc(t_rows*nn*sizeof(float));
/* index parameters are stored here */
struct FLANNParameters p = DEFAULT_FLANN_PARAMETERS;
p.algorithm = FLANN_INDEX_AUTOTUNED; /* or FLANN_INDEX_KDTREE, FLANN_INDEX_KMEANS, ... /*
p.target_precision = 0.9; /* want 90% target precision */
/* compute the 3 nearest-neighbors of each point in the testset */
flann_find_nearest_neighbors(dataset, rows, cols, testset, t_rows,
result, dists, nn, &p);
...
free(dataset);
free(testset);
free(result);
free(dists);
return 0;
}
• MATLAB
% create random dataset and test set
dataset = single(rand(128,10000));
testset = single(rand(128,1000));
% define index and search parameters
2
params.algorithm = ’kdtree’;
params.trees = 8;
params.checks = 64;
% perform the nearest-neighbor search
[result, dists] = flann_search(dataset,testset,5,params);
• Python
from pyflann import *
from numpy import *
from numpy.random import *
dataset = rand(10000, 128)
testset = rand(1000, 128)
flann = FLANN()
result,dists = flann.nn(dataset,testset,5,algorithm="kmeans",
branching=32, iterations=7, checks=16);
2 Downloading and compiling FLANN
FLANN can be downloaded from the following address:
http://www.cs.ubc.ca/∼mariusm/flann
After downloading and unpacking, the following files and directories should
be present:
• bin: directory various for scripts and binary files
• doc: directory containg this documentation
• examples: directory containg examples of using FLANN
• src: directory containg the source files
• test: directory containg unit tests for FLANN
To compile the FLANN library the CMake
1
build system is required. Below
is an example of how FLANN can be compiled on Linux (replace x.y.z with the
corresponding version number).
$ cd flann-x.y.z-src
$ mkdir build
$ cd build
$ cmake ..
$ make
On windows the steps are very similar:
1
http://www.cmake.org/
3
> "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
> cd flann-x.y.z-src
> mkdir build
> cd build
> cmake ..
> nmake
There are several compile options that can be configured before FLANN
is compiled, for example the build type (Release, RelWithDebInfo, Debug) or
whether to compile the C, Python or the MATLAB bindings. To change any of
this options use the cmake-gui application after cmake has finished (see figure
1).
> cmake-gui .
Figure 1: Configuring the FLANN compile options
4
剩余28页未读,继续阅读
资源评论
mengdongrenshi1
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功