31 #ifndef FLANN_INDEX_TESTING_H_
32 #define FLANN_INDEX_TESTING_H_
51 for (
int i=0; i<n; ++i) {
52 for (
int k=0; k<n; ++k) {
53 if (neighbors[i]==groundTruth[k]) {
63 template <
typename Distance>
65 size_t* neighbors,
size_t* groundTruth,
int veclen,
int n,
const Distance& distance)
67 typedef typename Distance::ResultType DistanceType;
70 for (
int i=0; i<n; ++i) {
71 DistanceType den = distance(inputData[groundTruth[i]], target, veclen);
72 DistanceType num = distance(inputData[neighbors[i]], target, veclen);
74 if ((den==0)&&(num==0)) {
85 template <
typename Index,
typename Distance>
88 float& time,
typename Distance::ResultType&
dist,
const Distance& distance,
int skipMatches)
90 typedef typename Distance::ElementType ElementType;
91 typedef typename Distance::ResultType DistanceType;
93 if (matches.
cols<
size_t(nn)) {
95 throw FLANNException(
"Ground truth is not computed for as many neighbors as requested");
100 size_t* indices =
new size_t[nn+skipMatches];
101 DistanceType* dists =
new DistanceType[nn+skipMatches];
106 size_t* neighbors = indices + skipMatches;
109 DistanceType distR = 0;
112 while (t.
value<0.2) {
117 for (
size_t i = 0; i < testData.
rows; i++) {
121 distR += computeDistanceRaport<Distance>(inputData, testData[i], neighbors, matches[i], testData.
cols, nn, distance);
125 time = float(t.
value/repeats);
130 float precicion = (float)correct/(nn*testData.
rows);
135 checks, precicion, time, 1000.0 * time / testData.
rows,
dist);
141 template <
typename Index,
typename Distance>
144 int checks,
float& precision,
const Distance& distance,
int nn = 1,
int skipMatches = 0)
146 typedef typename Distance::ResultType DistanceType;
148 Logger::info(
" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
149 Logger::info(
"---------------------------------------------------------\n");
152 DistanceType
dist = 0;
158 template <
typename Index,
typename Distance>
161 float precision,
int& checks,
const Distance& distance,
int nn = 1,
int skipMatches = 0)
163 typedef typename Distance::ResultType DistanceType;
164 const float SEARCH_EPS = 0.001f;
166 Logger::info(
" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
167 Logger::info(
"---------------------------------------------------------\n");
184 while (p2<precision) {
193 if (
fabs(p2-precision)>SEARCH_EPS) {
200 while (
fabs(realPrecision-precision)>SEARCH_EPS) {
202 if (realPrecision<precision) {
231 template <
typename Index,
typename Distance>
234 float* precisions,
int precisions_length,
const Distance& distance,
int nn = 1,
int skipMatches = 0,
float maxTime = 0)
236 typedef typename Distance::ResultType DistanceType;
238 const float SEARCH_EPS = 0.001;
241 std::sort(precisions, precisions+precisions_length);
244 float precision = precisions[pindex];
246 Logger::info(
" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
247 Logger::info(
"---------------------------------------------------------\n");
263 while (precisions[pindex]<p2 && pindex<precisions_length) {
267 if (pindex==precisions_length) {
272 for (
int i=pindex; i<precisions_length; ++i) {
274 precision = precisions[i];
275 while (p2<precision) {
280 if ((maxTime> 0)&&(time > maxTime)&&(p2<precision))
return;
285 if (
fabs(p2-precision)>SEARCH_EPS) {
292 while (
fabs(realPrecision-precision)>SEARCH_EPS) {
294 if (realPrecision<precision) {
double Distance(const Point3D< Real > &p1, const Point3D< Real > &p2)
int knnSearch(const Matrix< ElementType > &queries, Matrix< size_t > &indices, Matrix< DistanceType > &dists, size_t knn, const SearchParams ¶ms) const
Perform k-nearest neighbor search.
static int info(const char *fmt,...)
__host__ __device__ float2 fabs(float2 v)
static double dist(double x1, double y1, double x2, double y2)
Distance::ResultType computeDistanceRaport(const Matrix< typename Distance::ElementType > &inputData, typename Distance::ElementType *target, size_t *neighbors, size_t *groundTruth, int veclen, int n, const Distance &distance)
float search_with_ground_truth(Index &index, const Matrix< typename Distance::ElementType > &inputData, const Matrix< typename Distance::ElementType > &testData, const Matrix< size_t > &matches, int nn, int checks, float &time, typename Distance::ResultType &dist, const Distance &distance, int skipMatches)
int countCorrectMatches(size_t *neighbors, size_t *groundTruth, int n)
float test_index_checks(Index &index, const Matrix< typename Distance::ElementType > &inputData, const Matrix< typename Distance::ElementType > &testData, const Matrix< size_t > &matches, int checks, float &precision, const Distance &distance, int nn=1, int skipMatches=0)
float test_index_precision(Index &index, const Matrix< typename Distance::ElementType > &inputData, const Matrix< typename Distance::ElementType > &testData, const Matrix< size_t > &matches, float precision, int &checks, const Distance &distance, int nn=1, int skipMatches=0)
void test_index_precisions(Index &index, const Matrix< typename Distance::ElementType > &inputData, const Matrix< typename Distance::ElementType > &testData, const Matrix< int > &matches, float *precisions, int precisions_length, const Distance &distance, int nn=1, int skipMatches=0, float maxTime=0)