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 NNS* nns = NNS::createKDTreeLinearHeap(d, std::numeric_limits<typename NNS::Index>::max(), NNS::TOUCH_STATISTICS);
00065 for (T epsilon = 0; epsilon < 2; epsilon += 0.01)
00066 {
00067 double duration(0);
00068 double touchStats(0);
00069 for (int s = 0; s < searchCount; ++s)
00070 {
00071 boost::timer t;
00072 touchStats += nns->knn(q, indexes_bf, dists2_bf, K, epsilon, NNS::ALLOW_SELF_MATCH);
00073 duration += t.elapsed();
00074 }
00075 cout << epsilon << " " << duration/double(searchCount) << " " << touchStats/double(searchCount) << endl;
00076 }
00077 delete nns;
00078 }
00079
00080
00081 int main(int argc, char* argv[])
00082 {
00083 if (argc != 5)
00084 {
00085 cerr << "Usage " << argv[0] << " DATA K METHOD SEARCH_COUNT" << endl;
00086 return 1;
00087 }
00088
00089 const int K(atoi(argv[2]));
00090 const int method(atoi(argv[3]));
00091 const int searchCount(atoi(argv[4]));
00092
00093
00094
00095 cout << "epsilon average_duration search_count\n";
00096 doTestEpsilon<double>(argv[1], K, method, searchCount);
00097
00098 return 0;
00099 }