提交 7f157ed7 编写于 作者: M Marius Muja

Merge branch 'master' into master_local

macro(GET_OS_INFO)
string(REGEX MATCH "Linux" OS_IS_LINUX ${CMAKE_SYSTEM_NAME})
if(OS_IS_LINUX)
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(FLANN_LIB_INSTALL_DIR "lib64")
else(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(FLANN_LIB_INSTALL_DIR "lib")
endif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
else(OS_IS_LINUX)
set(FLANN_LIB_INSTALL_DIR "lib")
endif(OS_IS_LINUX)
set(FLANN_LIB_INSTALL_DIR "lib")
set(FLANN_INCLUDE_INSTALL_DIR
"include/${PROJECT_NAME_LOWER}-${FLANN_MAJOR_VERSION}.${FLANN_MINOR_VERSION}")
endmacro(GET_OS_INFO)
......
......@@ -482,7 +482,7 @@ optimized for searching lower dimensionality data (for example 3D point clouds)
\begin{Verbatim}[fontsize=\footnotesize]
struct KDTreeSingleIndexParams : public IndexParams
{
KDTreeSingleIndexParams( int max_leaf_size = 10 );
KDTreeSingleIndexParams( int leaf_max_size = 10 );
};
\end{Verbatim}
\begin{description}
......@@ -511,7 +511,7 @@ struct HierarchicalClusteringIndexParams : public IndexParams
{
HierarchicalClusteringIndexParams(int branching = 32,
flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM,
int trees = 4, int leaf_size = 100)
int trees = 4, int leaf_max_size = 100)
};
\end{Verbatim}
\begin{description}
......@@ -874,6 +874,11 @@ struct FLANNParameters {
float memory_weight; /* index memory weigthing factor */
float sample_fraction; /* what fraction of the dataset to use for autotuning */
/* LSH parameters */
unsigned int table_number_; /** The number of hash tables to use */
unsigned int key_size_; /** The length of the key in the hash tables */
unsigned int multi_probe_level_; /** Number of levels to use in multi-probe LSH, 0 for standard LSH */
/* other parameters */
enum flann_log_level_t log_level; /* determines the verbosity of each flann function */
long random_seed; /* random seed to use */
......@@ -1327,14 +1332,15 @@ used:
\subsubsection{Example 1:}
In this example the index is constructed using automatic parameter estimation, requesting 90\% as desired precision and using the default values for the build time and memory usage factors. The index is then used to search for the nearest-neighbors of the points in the testset matrix and finally the index is deleted.
In this example the index is constructed using automatic parameter estimation, requesting 70\% as desired precision and using the default values for the build time and memory usage factors. The index is then used to search for the nearest-neighbors of the points in the testset matrix and finally the index is deleted.
\begin{Verbatim}[fontsize=\footnotesize,frame=single]
dataset = single(rand(128,10000));
testset = single(rand(128,1000));
build_params.target_precision = 0.9;
build_params.algorithm = 'autotuned';
build_params.target_precision = 0.7;
build_params.build_weight = 0.01;
build_params.memory_weight = 0;
......@@ -1435,7 +1441,7 @@ dataset = rand(10000, 128)
testset = rand(1000, 128)
flann = FLANN()
params = flann.build_index(dataset, target_precision=0.9, log_level = "info");
params = flann.build_index(dataset, algorithm="autotuned", target_precision=0.9, log_level = "info");
print params
result, dists = flann.nn_index(testset,5, checks=params["checks"]);
......
......@@ -63,16 +63,7 @@ if (BUILD_CUDA_LIB)
endif()
#debug libraries
add_library(flann_cpp-gd SHARED ${CPP_SOURCES})
set_target_properties(flann_cpp-gd PROPERTIES
COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}
DEFINE_SYMBOL FLANN_EXPORTS
)
add_library(flann_cpp_s-gd STATIC ${CPP_SOURCES})
set_target_properties(flann_cpp_s-gd PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
set_property(TARGET flann_cpp_s-gd PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
......@@ -95,17 +86,6 @@ if (HDF5_FOUND)
endif()
endif()
if (BUILD_CUDA_LIB)
add_library(flann_cuda-gd SHARED ${CPP_SOURCES})
set_target_properties(flann_cuda-gd PROPERTIES
COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG}
DEFINE_SYMBOL FLANN_EXPORTS
)
add_library(flann_cuda_s-gd STATIC ${CPP_SOURCES})
set_target_properties(flann_cuda_s-gd PROPERTIES COMPILE_FLAGS ${CMAKE_CXX_FLAGS_DEBUG})
set_property(TARGET flann_cuda_s-gd PROPERTY COMPILE_DEFINITIONS FLANN_STATIC)
endif()
if (BUILD_C_BINDINGS)
add_library(flann_s STATIC ${C_SOURCES})
......@@ -129,7 +109,6 @@ if (BUILD_C_BINDINGS)
)
endif()
if(WIN32)
if (BUILD_C_BINDINGS)
install (
......@@ -141,7 +120,7 @@ endif(WIN32)
install (
TARGETS flann_cpp flann_cpp_s flann_cpp-gd flann_cpp_s-gd
TARGETS flann_cpp flann_cpp_s
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${FLANN_LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${FLANN_LIB_INSTALL_DIR}
......@@ -149,7 +128,7 @@ install (
if (BUILD_CUDA_LIB)
install (
TARGETS flann_cuda flann_cuda_s flann_cuda-gd flann_cuda_s-gd
TARGETS flann_cuda flann_cuda_s
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${FLANN_LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${FLANN_LIB_INSTALL_DIR}
......
......@@ -56,7 +56,7 @@ struct HierarchicalClusteringIndexParams : public IndexParams
{
HierarchicalClusteringIndexParams(int branching = 32,
flann_centers_init_t centers_init = FLANN_CENTERS_RANDOM,
int trees = 4, int leaf_size = 100)
int trees = 4, int leaf_max_size = 100)
{
(*this)["algorithm"] = FLANN_INDEX_HIERARCHICAL;
// The branching factor used in the hierarchical clustering
......@@ -66,7 +66,7 @@ struct HierarchicalClusteringIndexParams : public IndexParams
// number of parallel trees to build
(*this)["trees"] = trees;
// maximum leaf size
(*this)["leaf_size"] = leaf_size;
(*this)["leaf_max_size"] = leaf_max_size;
}
};
......@@ -101,7 +101,7 @@ public:
branching_ = get_param(index_params_,"branching",32);
centers_init_ = get_param(index_params_,"centers_init", FLANN_CENTERS_RANDOM);
trees_ = get_param(index_params_,"trees",4);
leaf_size_ = get_param(index_params_,"leaf_size",100);
leaf_max_size_ = get_param(index_params_,"leaf_max_size",100);
initCenterChooser();
}
......@@ -123,7 +123,7 @@ public:
branching_ = get_param(index_params_,"branching",32);
centers_init_ = get_param(index_params_,"centers_init", FLANN_CENTERS_RANDOM);
trees_ = get_param(index_params_,"trees",4);
leaf_size_ = get_param(index_params_,"leaf_size",100);
leaf_max_size_ = get_param(index_params_,"leaf_max_size",100);
initCenterChooser();
chooseCenters_->setDataset(inputData);
......@@ -138,7 +138,7 @@ public:
branching_(other.branching_),
trees_(other.trees_),
centers_init_(other.centers_init_),
leaf_size_(other.leaf_size_)
leaf_max_size_(other.leaf_max_size_)
{
initCenterChooser();
......@@ -256,7 +256,7 @@ public:
ar & branching_;
ar & trees_;
ar & centers_init_;
ar & leaf_size_;
ar & leaf_max_size_;
if (Archive::is_loading::value) {
tree_roots_.resize(trees_);
......@@ -273,7 +273,7 @@ public:
index_params_["branching"] = branching_;
index_params_["trees"] = trees_;
index_params_["centers_init"] = centers_init_;
index_params_["leaf_size"] = leaf_size_;
index_params_["leaf_size"] = leaf_max_size_;
}
}
......@@ -485,7 +485,7 @@ private:
*/
void computeClustering(NodePtr node, int* indices, int indices_length)
{
if (indices_length < leaf_size_) { // leaf node
if (indices_length < leaf_max_size_) { // leaf node
node->points.resize(indices_length);
for (int i=0;i<indices_length;++i) {
node->points[i].index = indices[i];
......@@ -638,7 +638,7 @@ private:
std::swap(branching_, other.branching_);
std::swap(trees_, other.trees_);
std::swap(centers_init_, other.centers_init_);
std::swap(leaf_size_, other.leaf_size_);
std::swap(leaf_max_size_, other.leaf_max_size_);
std::swap(chooseCenters_, other.chooseCenters_);
}
......@@ -687,7 +687,7 @@ private:
/**
* Max size of leaf nodes
*/
int leaf_size_;
int leaf_max_size_;
/**
* Algorithm used to choose initial centers
......
......@@ -530,6 +530,8 @@ private:
if (lim1>count/2) index = lim1;
else if (lim2<count/2) index = lim2;
else index = count/2;
assert(index > 0 && index < count);
}
......@@ -544,7 +546,6 @@ private:
*/
void planeSplit(int* ind, int count, int cutfeat, DistanceType cutval, int& lim1, int& lim2)
{
/* Move vector indices for left subtree to front of list. */
int left = 0;
int right = count-1;
for (;; ) {
......@@ -553,9 +554,6 @@ private:
if (left>right) break;
std::swap(ind[left], ind[right]); ++left; --right;
}
/* If either list is empty, it means that all remaining features
* are identical. Split in the middle to maintain a balanced tree.
*/
lim1 = left;
right = count-1;
for (;; ) {
......
......@@ -62,6 +62,7 @@ flann::IndexParams create_parameters(FLANNParameters* p)
params["trees"] = p->trees;
params["leaf_max_size"] = p->leaf_max_size;
}
#ifdef FLANN_USE_CUDA
if (p->algorithm == FLANN_INDEX_KDTREE_CUDA) {
params["leaf_max_size"] = p->leaf_max_size;
......@@ -85,7 +86,7 @@ flann::IndexParams create_parameters(FLANNParameters* p)
params["branching"] = p->branching;
params["centers_init"] = p->centers_init;
params["trees"] = p->trees;
params["leaf_size"] = p->leaf_max_size;
params["leaf_max_size"] = p->leaf_max_size;
}
if (p->algorithm == FLANN_INDEX_LSH) {
......@@ -102,6 +103,57 @@ flann::IndexParams create_parameters(FLANNParameters* p)
void update_flann_parameters(const IndexParams& params, FLANNParameters* flann_params)
{
if (has_param(params,"algorithm")) {
flann_params->algorithm = get_param<flann_algorithm_t>(params,"algorithm");
}
if (has_param(params,"trees")) {
flann_params->trees = get_param<int>(params,"trees");
}
if (has_param(params,"leaf_max_size")) {
flann_params->leaf_max_size = get_param<int>(params,"leaf_max_size");
}
if (has_param(params,"branching")) {
flann_params->branching = get_param<int>(params,"branching");
}
if (has_param(params,"iterations")) {
flann_params->iterations = get_param<int>(params,"iterations");
}
if (has_param(params,"centers_init")) {
flann_params->centers_init = get_param<flann_centers_init_t>(params,"centers_init");
}
if (has_param(params,"target_precision")) {
flann_params->target_precision = get_param<float>(params,"target_precision");
}
if (has_param(params,"build_weight")) {
flann_params->build_weight = get_param<float>(params,"build_weight");
}
if (has_param(params,"memory_weight")) {
flann_params->memory_weight = get_param<float>(params,"memory_weight");
}
if (has_param(params,"sample_fraction")) {
flann_params->sample_fraction = get_param<float>(params,"sample_fraction");
}
if (has_param(params,"table_number")) {
flann_params->table_number_ = get_param<unsigned int>(params,"table_number");
}
if (has_param(params,"key_size")) {
flann_params->key_size_ = get_param<unsigned int>(params,"key_size");
}
if (has_param(params,"multi_probe_level")) {
flann_params->multi_probe_level_ = get_param<unsigned int>(params,"multi_probe_level");
}
if (has_param(params,"log_level")) {
flann_params->log_level = get_param<flann_log_level_t>(params,"log_level");
}
if (has_param(params,"random_seed")) {
flann_params->random_seed = get_param<long>(params,"random_seed");
}
}
void init_flann_parameters(FLANNParameters* p)
{
if (p != NULL) {
......@@ -142,10 +194,10 @@ flann_index_t __flann_build_index(typename Distance::ElementType* dataset, int r
IndexParams params = create_parameters(flann_params);
Index<Distance>* index = new Index<Distance>(Matrix<ElementType>(dataset,rows,cols), params, d);
index->buildIndex();
params = index->getParameters();
if (index->getType()==FLANN_INDEX_AUTOTUNED) {
if (flann_params->algorithm==FLANN_INDEX_AUTOTUNED) {
IndexParams params = index->getParameters();
update_flann_parameters(params,flann_params);
SearchParams search_params = get_param<SearchParams>(params,"search_params");
*speedup = get_param<float>(params,"speedup");
flann_params->checks = search_params.checks;
......
......@@ -6,7 +6,7 @@ function [index, params, speedup] = flann_build_index(dataset, build_params)
% Marius Muja, January 2008
algos = struct( 'linear', 0, 'kdtree', 1, 'kmeans', 2, 'composite', 3, 'kdtree_single', 4, 'saved', 254, 'autotuned', 255 );
algos = struct( 'linear', 0, 'kdtree', 1, 'kmeans', 2, 'composite', 3, 'kdtree_single', 4, 'hierarchical', 5, 'lsh', 6, 'saved', 254, 'autotuned', 255 );
center_algos = struct('random', 0, 'gonzales', 1, 'kmeanspp', 2 );
log_levels = struct('none', 0, 'fatal', 1, 'error', 2, 'warning', 3, 'info', 4);
function value = id2value(map, id)
......
......@@ -87,11 +87,15 @@ static void flannStructToMatlabStruct( const FLANNParameters& flannParams, mxArr
{
mxSetField(mexParams, 0, "algorithm", to_mx_array(flannParams.algorithm));
mxSetField(mexParams, 0, "checks", to_mx_array(flannParams.checks));
mxSetField(mexParams, 0, "cb_index", to_mx_array(flannParams.cb_index));
mxSetField(mexParams, 0, "eps", to_mx_array(flannParams.eps));
mxSetField(mexParams, 0, "trees", to_mx_array(flannParams.trees));
mxSetField(mexParams, 0, "leaf_max_size", to_mx_array(flannParams.trees));
mxSetField(mexParams, 0, "branching", to_mx_array(flannParams.branching));
mxSetField(mexParams, 0, "iterations", to_mx_array(flannParams.iterations));
mxSetField(mexParams, 0, "centers_init", to_mx_array(flannParams.centers_init));
mxSetField(mexParams, 0, "cb_index", to_mx_array(flannParams.cb_index));
}
......@@ -384,7 +388,7 @@ static void _build_index(int nOutArray, mxArray* OutArray[], int nInArray, const
pOut[0] = typedIndex;
if (nOutArray > 1) {
const char* fieldnames[] = {"algorithm", "checks", "trees", "branching", "iterations", "centers_init", "cb_index"};
const char* fieldnames[] = {"algorithm", "checks", "cb_index", "eps", "trees", "leaf_max_size", "branching", "iterations", "centers_init"};
OutArray[1] = mxCreateStructMatrix(1, 1, sizeof(fieldnames)/sizeof(const char*), fieldnames);
flannStructToMatlabStruct(p, OutArray[1]);
}
......
......@@ -121,7 +121,7 @@ class FLANNParameters(CustomStructure):
'random_seed' : -1
}
_translation_ = {
"algorithm" : {"linear" : 0, "kdtree" : 1, "kmeans" : 2, "composite" : 3, "kdtree_simple" : 4, "saved": 254, "autotuned" : 255, "default" : 1},
"algorithm" : {"linear" : 0, "kdtree" : 1, "kmeans" : 2, "composite" : 3, "kdtree_single" : 4, "hierarchical": 5, "lsh": 6, "saved": 254, "autotuned" : 255, "default" : 1},
"centers_init" : {"random" : 0, "gonzales" : 1, "kmeanspp" : 2, "default" : 0},
"log_level" : {"none" : 0, "fatal" : 1, "error" : 2, "warning" : 3, "info" : 4, "default" : 2}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册