knnepsilon.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  NNS* nns = NNS::createKDTreeLinearHeap(d, std::numeric_limits<typename NNS::Index>::max(), NNS::TOUCH_STATISTICS);
65  for (T epsilon = 0; epsilon < 2; epsilon += 0.01)
66  {
67  double duration(0);
68  double touchStats(0);
69  for (int s = 0; s < searchCount; ++s)
70  {
71  timer t;
72  touchStats += nns->knn(q, indexes_bf, dists2_bf, K, epsilon, NNS::ALLOW_SELF_MATCH);
73  duration += t.elapsed();
74  }
75  cout << epsilon << " " << duration/double(searchCount) << " " << touchStats/double(searchCount) << endl;
76  }
77  delete nns;
78 }
79 
80 
81 int main(int argc, char* argv[])
82 {
83  if (argc != 5)
84  {
85  cerr << "Usage " << argv[0] << " DATA K METHOD SEARCH_COUNT" << endl;
86  return 1;
87  }
88 
89  const int K(atoi(argv[2]));
90  const int method(atoi(argv[3]));
91  const int searchCount(atoi(argv[4]));
92 
93  //cout << "Float: (epsilon, average duration)\n";
94  //doTestEpsilon<float>(argv[1], K, method, searchCount);
95  cout << "epsilon average_duration search_count\n";
96  doTestEpsilon<double>(argv[1], K, method, searchCount);
97 
98  return 0;
99 }
Nabo
Namespace for Nabo.
Definition: experimental/kdtree_cpu.cpp:40
epsilon
double epsilon
timer
Definition: helpers.h:128
nabo.h
public interface
doTestEpsilon
void doTestEpsilon(const char *fileName, const int K, const int method, const int searchCount)
Definition: knnepsilon.cpp:42
s
XmlRpcServer s
main
int main(int argc, char *argv[])
Definition: knnepsilon.cpp:81
Nabo::NearestNeighbourSearch
Nearest neighbour search interface, templatized on scalar type.
Definition: nabo.h:258
d
d
helpers.h
test.nns
nns
Definition: test.py:7
std
test.q
q
Definition: test.py:8
t
geometry_msgs::TransformStamped t


mrpt_local_obstacles
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Mon Aug 14 2023 02:09:03