-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.cpp
82 lines (65 loc) · 2.63 KB
/
main.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
75
76
77
78
79
80
81
82
/**
* @file main.cpp
*
* @breif An implementation of the B-Tree part of the learned indices paper
*
* @date 1/05/2018
* @author Ben Caine
*/
#include "utils/DataGenerators.h"
#include "RecursiveModelIndex.h"
#include <algorithm>
int main() {
NetworkParameters firstStageParams;
firstStageParams.batchSize = 256;
firstStageParams.maxNumEpochs = 25000;
firstStageParams.learningRate = 0.01;
firstStageParams.numNeurons = 8;
NetworkParameters secondStageParams;
secondStageParams.batchSize = 64;
secondStageParams.maxNumEpochs = 1000;
secondStageParams.learningRate = 0.01;
RecursiveModelIndex<int, int, 128> recursiveModelIndex(firstStageParams, secondStageParams, 256, 1e6);
btree::btree_map<int, int> btreeMap;
const size_t datasetSize = 10000;
float maxValue = 1e4;
auto values = getIntegerLognormals<int, datasetSize>(maxValue);
for (auto val : values) {
recursiveModelIndex.insert(val, val + 1);
btreeMap.insert({val, val + 1});
}
recursiveModelIndex.train();
std::vector<double> rmiDurations;
std::vector<double> btreeDurations;
for (unsigned int ii = 0; ii < datasetSize; ii += 500) {
auto startTime = std::chrono::system_clock::now();
auto result = recursiveModelIndex.find(values[ii]);
auto endTime = std::chrono::system_clock::now();
std::chrono::duration<double> duration = endTime - startTime;
rmiDurations.push_back(duration.count());
if (result) {
std::cout << result.get().first << ", " << result.get().second << std::endl;
} else {
std::cout << "Failed to find value that should be there" << std::endl;
}
startTime = std::chrono::system_clock::now();
auto btreeResult = btreeMap.find(values[ii]);
endTime = std::chrono::system_clock::now();
duration = endTime - startTime;
btreeDurations.push_back(duration.count());
}
auto summaryStats = [](const std::vector<double> &durations) {
double average = std::accumulate(durations.cbegin(), durations.cend() - 1, 0.0) / durations.size();
auto minmax = std::minmax(durations.cbegin(), durations.cend() - 1);
std::cout << "Min: " << *minmax.first << std::endl;
std::cout << "Average: " << average << std::endl;
std::cout << "Max: " << *minmax.second << std::endl;
};
std::cout << std::endl << std::endl;
std::cout << "Recursive Model Index Timings" << std::endl;
summaryStats(rmiDurations);
std::cout << std::endl << std::endl;
std::cout << "BTree Timings" << std::endl;
summaryStats(btreeDurations);
return 0;
}