knnbucketsize.cpp
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2010--2011, Stephane Magnenat, ASL, ETHZ, Switzerland
4 You can contact the author at <stephane at magnenat dot net>
5 
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10  * Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15  * Neither the name of the <organization> nor the
16  names of its contributors may be used to endorse or promote products
17  derived from this software without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL ETH-ASL BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 */
31 
32 #include "nabo/nabo.h"
33 #include "helpers.h"
34 #include <iostream>
35 #include <fstream>
36 #include <stdexcept>
37 
38 using namespace std;
39 using namespace Nabo;
40 
41 template<typename T>
42 void doTestEpsilon(const char *fileName, const int K, const int method, const int searchCount)
43 {
45  typedef typename NNS::Matrix Matrix;
46  typedef typename NNS::IndexMatrix IndexMatrix;
47 
48  // check if file is ok
49  const Matrix d(load<T>(fileName));
50  if (K >= d.cols())
51  {
52  cerr << "Requested more nearest neighbour than points in the data set" << endl;
53  exit(2);
54  }
55 
56  // check methods together
57  const int itCount(method >= 0 ? method : d.cols() * 2);
58 
59  // create big query
60  const Matrix q(createQuery<T>(d, itCount, method));
61  IndexMatrix indexes_bf(K, q.cols());
62  Matrix dists2_bf(K, q.cols());
63 
64  for (unsigned bucketSize = 2; bucketSize < 40; ++bucketSize)
65  {
66  Parameters additionalParameters("bucketSize", unsigned(bucketSize));
67  NNS* nns = NNS::createKDTreeLinearHeap(d, std::numeric_limits<typename NNS::Index>::max(), 0, additionalParameters);
68 
69  double duration(0);
70  for (int s = 0; s < searchCount; ++s)
71  {
72  timer t;
73  nns->knn(q, indexes_bf, dists2_bf, K, 0, NNS::ALLOW_SELF_MATCH);
74  duration += t.elapsed();
75  }
76  cout << bucketSize << " " << duration/double(searchCount) << endl;
77 
78  delete nns;
79  }
80 }
81 
82 
83 int main(int argc, char* argv[])
84 {
85  if (argc != 5)
86  {
87  cerr << "Usage " << argv[0] << " DATA K METHOD SEARCH_COUNT" << endl;
88  return 1;
89  }
90 
91  const int K(atoi(argv[2]));
92  const int method(atoi(argv[3]));
93  const int searchCount(atoi(argv[4]));
94 
95  cout << "bucketSize average_duration\n";
96  doTestEpsilon<double>(argv[1], K, method, searchCount);
97 
98  return 0;
99 }
Nearest neighbour search interface, templatized on scalar type.
Definition: nabo.h:258
Definition: any.hpp:450
nns
Definition: test.py:7
Definition: helpers.h:128
void doTestEpsilon(const char *fileName, const int K, const int method, const int searchCount)
Parameter vector.
Definition: nabo.h:231
Namespace for Nabo.
public interface
double elapsed() const
Definition: helpers.h:135
int main(int argc, char *argv[])
q
Definition: test.py:8


libnabo
Author(s): Stéphane Magnenat
autogenerated on Mon Feb 28 2022 22:41:38