-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBBFRecallAtOne.cpp
74 lines (59 loc) · 2.36 KB
/
BBFRecallAtOne.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* File: BBFRecallAtOne.cpp
* Author Lili Meng (lilimeng1103@gmail.com)
* The Recall of BBF Approximate Search at 1 nearest neighbor for 10 query points from a dataset of 1000 points
*/
#include <iostream>
#include "KD_tree.h"
#include "ReadData1.h"
using namespace std;
int main(int argc, const char * argv[])
{
int K = 1;
vector<vector<double> > dataset;
ReadData rd1("sample_data.txt");
dataset=rd1.allDataPointsVec;
//query_point
vector<double> query_point;
vector<vector<double> > query_point_dataset;
ReadData rd2("query_points.txt");
query_point_dataset=rd2.allDataPointsVec;
KD_tree_node* root;
KD_tree tree;
int max_leaf_size =2;
tree.create_tree(dataset,max_leaf_size);
vector<int> indices1;
vector<double> squared_distances1;
vector<int> trueSearch(10);
for(int i=0; i<query_point_dataset.size(); i++)
{
tree.kNN_query(query_point_dataset[i], K, indices1, squared_distances1);
//cout<<indices1[0]<<endl;
trueSearch[i]=indices1[0];
cout<<trueSearch[i]<<endl;
}
ofstream fout("RecallAtOne.csv");
vector<int> indices2;
vector<double> squared_distances2;
double correct_number[1001][10];
double RecallAtOne[1001];
double sum[1001];
for(int max_searched_leaf_number=1; max_searched_leaf_number<=1000; max_searched_leaf_number++)
/** If the max_epoch is equal or larger than the size of all leaves, the result is the same with the exact kNN search**/
{
for(int j=0; j<query_point_dataset.size(); j++)
{
tree.bbf_kNN_query(query_point_dataset[j], K, indices2, squared_distances2, max_searched_leaf_number);
if(indices2[0]==trueSearch[j])
{
correct_number[max_searched_leaf_number][j]++;
}
sum[max_searched_leaf_number]+=correct_number[max_searched_leaf_number][j];
}
RecallAtOne[max_searched_leaf_number]=sum[max_searched_leaf_number]/10.000;
cout<<max_searched_leaf_number<<"\t"<<setprecision(5)<<RecallAtOne[max_searched_leaf_number]<<endl;
fout<<max_searched_leaf_number<<"\t"<<setprecision(5)<<RecallAtOne[max_searched_leaf_number]<<endl;
// cout<<"The Recall of BBF Approximate Search at 1 nearest neighbor for 10 query points from a dataset of 1000 points is: "<<setprecision(3)<<RecallAtOne<<endl;
}
return 0;
}