diff --git a/algorithms/utils/check_range_recall.h b/algorithms/utils/check_range_recall.h new file mode 100644 index 0000000..cbd4fbb --- /dev/null +++ b/algorithms/utils/check_range_recall.h @@ -0,0 +1,103 @@ +// This code is part of the Problem Based Benchmark Suite (PBBS) +// Copyright (c) 2011 Guy Blelloch and the PBBS team +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights (to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +#pragma once + +#include +#include + +#include "beamSearch.h" +#include "csvfile.h" +#include "parse_results.h" +#include "parlay/parallel.h" +#include "parlay/primitives.h" +#include "types.h" +#include "stats.h" + +template +void checkRangeRecall( + Graph &G, + PointRange &Base_Points, + PointRange &Query_Points, + RangeGroundTruth GT, + RangeParams RP, + long start_point) { + + + parlay::sequence> all_rr; + + parlay::internal::timer t; + float query_time; + stats QueryStats(Query_Points.size()); + + all_rr = RangeSearch(Query_Points, G, Base_Points, QueryStats, start_point, RP); + query_time = t.next_time(); + + + float pointwise_recall = 0.0; + float reported_results = 0.0; + float total_results = 0.0; + float num_nonzero = 0.0; + + //since distances are exact, just have to cross-check number of results + size_t n = Query_Points.size(); + int numCorrect = 0; + for (indexType i = 0; i < n; i++) { + float num_reported_results = all_rr[i].size(); + float num_actual_results = GT[i].size(); + reported_results += num_reported_results; + total_results += num_actual_results; + if(num_actual_results != 0) {pointwise_recall += num_reported_results/num_actual_results; num_nonzero++;} + } + + pointwise_recall /= num_nonzero; + float cumulative_recall = reported_results/total_results; + + float QPS = Query_Points.size() / query_time; + auto stats_ = {QueryStats.dist_stats(), QueryStats.visited_stats()}; + + std::cout << "For "; + RP.print(); + std::cout << ", Pointwise Recall = " << pointwise_recall << ", Cumulative Recall = " << cumulative_recall << ", QPS = " << QPS << std::endl; + + +} + + +template +void range_search_wrapper(Graph &G, PointRange &Base_Points, + PointRange &Query_Points, + RangeGroundTruth GT, double rad, + indexType start_point=0){ + + std::vector beams; + + beams = {10, 20, 30, 40, 50, 100, 1000, 2000, 3000}; + + for(long b: beams){ + RangeParams RP(rad, b); + checkRangeRecall(G, Base_Points, Query_Points, GT, RP, start_point); + } + + + +} diff --git a/data_tools/compute_range_groundtruth.cpp b/data_tools/compute_range_groundtruth.cpp index 2dc6b15..331dcde 100644 --- a/data_tools/compute_range_groundtruth.cpp +++ b/data_tools/compute_range_groundtruth.cpp @@ -133,7 +133,6 @@ int main(int argc, char* argv[]) { PointRange> B = PointRange>(bFile); PointRange> Q = PointRange>(qFile); answers = compute_range_groundtruth>>(B, Q, r); - write_nonzero_elts>, uint8_t>(answers, Q, std::string(gFile)); } else if(df == "mips"){ PointRange> B = PointRange>(bFile); PointRange> Q = PointRange>(qFile); @@ -151,7 +150,7 @@ int main(int argc, char* argv[]) { answers = compute_range_groundtruth>>(B, Q, r); } } - // write_rangeres(answers, std::string(gFile)); + write_rangeres(answers, std::string(gFile)); return 0;