Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "nabo/nabo.h"
00033 #include "helpers.h"
00034 #include <iostream>
00035 #include <fstream>
00036 #include <stdexcept>
00037
00038 using namespace std;
00039 using namespace Nabo;
00040
00041 template<typename T>
00042 void doTestEpsilon(const char *fileName, const int K, const int method, const int searchCount)
00043 {
00044 typedef Nabo::NearestNeighbourSearch<T> NNS;
00045 typedef typename NNS::Matrix Matrix;
00046 typedef typename NNS::IndexMatrix IndexMatrix;
00047
00048
00049 const Matrix d(load<T>(fileName));
00050 if (K >= d.cols())
00051 {
00052 cerr << "Requested more nearest neighbour than points in the data set" << endl;
00053 exit(2);
00054 }
00055
00056
00057 const int itCount(method >= 0 ? method : d.cols() * 2);
00058
00059
00060 const Matrix q(createQuery<T>(d, itCount, method));
00061 IndexMatrix indexes_bf(K, q.cols());
00062 Matrix dists2_bf(K, q.cols());
00063
00064 for (unsigned bucketSize = 2; bucketSize < 40; ++bucketSize)
00065 {
00066 Parameters additionalParameters("bucketSize", unsigned(bucketSize));
00067 NNS* nns = NNS::createKDTreeLinearHeap(d, std::numeric_limits<typename NNS::Index>::max(), 0, additionalParameters);
00068
00069 double duration(0);
00070 for (int s = 0; s < searchCount; ++s)
00071 {
00072 timer t;
00073 nns->knn(q, indexes_bf, dists2_bf, K, 0, NNS::ALLOW_SELF_MATCH);
00074 duration += t.elapsed();
00075 }
00076 cout << bucketSize << " " << duration/double(searchCount) << endl;
00077
00078 delete nns;
00079 }
00080 }
00081
00082
00083 int main(int argc, char* argv[])
00084 {
00085 if (argc != 5)
00086 {
00087 cerr << "Usage " << argv[0] << " DATA K METHOD SEARCH_COUNT" << endl;
00088 return 1;
00089 }
00090
00091 const int K(atoi(argv[2]));
00092 const int method(atoi(argv[3]));
00093 const int searchCount(atoi(argv[4]));
00094
00095 cout << "bucketSize average_duration\n";
00096 doTestEpsilon<double>(argv[1], K, method, searchCount);
00097
00098 return 0;
00099 }