summaryrefslogtreecommitdiffstats
path: root/benchmarks/include
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2023-07-25 11:17:36 -0400
committerDouglas Rumbaugh <dbr4@psu.edu>2023-07-25 11:17:36 -0400
commit37434f5baf632e839dc14b3c7d8745287cb9368a (patch)
tree4b9a77c25b734872a1b815cc7c0bad6258784601 /benchmarks/include
parent9e869d32344d5bd8ee703a0733d80d48d458217c (diff)
downloaddynamic-extension-37434f5baf632e839dc14b3c7d8745287cb9368a.tar.gz
Benchmarks: mtree and vptree benchmark updates
Note: cosine similarity doesn't seem to work for VPTree--I don't think that it is actually a metric, upon further research. At the very least I can't find anyone claiming it is, and I've found several people claiming it isn't. On testing with the Word2Vec data, Euclidean distance works insofar as the M-Tree and VPTree return the same KNN results for test queries, whereas Cosine Similarity does not work.
Diffstat (limited to 'benchmarks/include')
-rw-r--r--benchmarks/include/bench.h3
-rw-r--r--benchmarks/include/bench_utility.h15
2 files changed, 15 insertions, 3 deletions
diff --git a/benchmarks/include/bench.h b/benchmarks/include/bench.h
index 12d0a7e..586ff12 100644
--- a/benchmarks/include/bench.h
+++ b/benchmarks/include/bench.h
@@ -85,7 +85,7 @@ static bool insert_tput_bench(DE &de_index, std::fstream &file, size_t insert_cn
}
template <typename DE, de::RecordInterface R, typename QP, bool PROGRESS=true>
-static bool query_latency_bench(DE &de_index, std::vector<QP> queries, size_t trial_cnt=100) {
+static bool query_latency_bench(DE &de_index, std::vector<QP> queries, size_t trial_cnt=1) {
char progbuf[25];
if constexpr (PROGRESS) {
sprintf(progbuf, "querying:");
@@ -102,6 +102,7 @@ static bool query_latency_bench(DE &de_index, std::vector<QP> queries, size_t tr
auto start = std::chrono::high_resolution_clock::now();
for (size_t j=0; j<queries.size(); j++) {
auto res = de_index.query(&queries[j]);
+
total_results += res.size();
}
auto stop = std::chrono::high_resolution_clock::now();
diff --git a/benchmarks/include/bench_utility.h b/benchmarks/include/bench_utility.h
index 6610ab4..28040be 100644
--- a/benchmarks/include/bench_utility.h
+++ b/benchmarks/include/bench_utility.h
@@ -40,7 +40,7 @@ typedef de::WeightedRecord<key_type, value_type, weight_type> WRec;
typedef de::Record<key_type, value_type> Rec;
const size_t W2V_SIZE = 300;
-typedef de::CosinePoint<double, W2V_SIZE> Word2VecRec;
+typedef de::EuclidPoint<double, W2V_SIZE> Word2VecRec;
typedef de::DynamicExtension<WRec, de::WSS<WRec>, de::WSSQuery<WRec>> ExtendedWSS;
typedef de::DynamicExtension<Rec, de::TrieSpline<Rec>, de::TrieSplineRangeQuery<Rec>> ExtendedTSRQ;
@@ -68,6 +68,17 @@ struct btree_key_extract {
}
};
+struct euclidean_distance {
+ double operator()(const Word2VecRec &first, const Word2VecRec &second) const {
+ double dist = 0;
+ for (size_t i=0; i<W2V_SIZE; i++) {
+ dist += (first.data[i] - second.data[i]) * (first.data[i] - second.data[i]);
+ }
+
+ return std::sqrt(dist);
+ }
+};
+
struct cosine_similarity {
double operator()(const Word2VecRec &first, const Word2VecRec &second) const {
@@ -86,7 +97,7 @@ struct cosine_similarity {
};
typedef tlx::BTree<key_type, btree_record, btree_key_extract> TreeMap;
-typedef mt::mtree<Word2VecRec, cosine_similarity> MTree;
+typedef mt::mtree<Word2VecRec, euclidean_distance> MTree;
static gsl_rng *g_rng;
static std::set<WRec> *g_to_delete;