feat: add plots for n m k trends
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
n,m,k,theoretical_fpp,filter_fpp,actual_fpp
|
||||
10000,100000,2,0.03285854,0.03289392,0.03292500
|
||||
10000,100000,3,0.01741059,0.01743016,0.01755500
|
||||
10000,100000,4,0.01181327,0.01185258,0.01231500
|
||||
10000,100000,5,0.00943093,0.00940946,0.00898000
|
||||
10000,100000,6,0.00843621,0.00844959,0.00851000
|
||||
10000,100000,7,0.00819372,0.00818934,0.00823000
|
||||
10000,100000,8,0.00845547,0.00843888,0.00853000
|
||||
10000,100000,9,0.00912699,0.00915585,0.00945500
|
||||
10000,100000,10,0.01018589,0.01023808,0.01031500
|
||||
10000,100000,11,0.01164950,0.01163213,0.01149000
|
||||
10000,100000,12,0.01356057,0.01344405,0.01366000
|
||||
10000,100000,13,0.01598020,0.01592878,0.01558500
|
||||
10000,100000,14,0.01898380,0.01903601,0.01829000
|
||||
10000,100000,15,0.02265812,0.02262230,0.02297000
|
||||
1000,100000,5,0.00000028,0.00000028,0.00000000
|
||||
2000,100000,5,0.00000780,0.00000782,0.00001500
|
||||
3000,100000,5,0.00005244,0.00005258,0.00004000
|
||||
4000,100000,5,0.00019571,0.00019651,0.00019500
|
||||
5000,100000,5,0.00052956,0.00053070,0.00050500
|
||||
7500,100000,5,0.00299029,0.00298418,0.00307500
|
||||
10000,100000,5,0.00943093,0.00944119,0.00924000
|
||||
15000,100000,5,0.04089419,0.04091604,0.04042500
|
||||
20000,100000,5,0.10092519,0.10124248,0.10181000
|
||||
30000,100000,5,0.28297059,0.28242511,0.28079500
|
||||
40000,100000,5,0.48332436,0.48360202,0.48378500
|
||||
60000,100000,5,0.77464850,0.77395500,0.77450000
|
||||
80000,100000,5,0.91171555,0.91254904,0.91244000
|
||||
10000,50000,5,0.10092519,0.10099464,0.10038000
|
||||
10000,60000,5,0.05778111,0.05778597,0.05903000
|
||||
10000,70000,5,0.03465784,0.03474584,0.03495000
|
||||
10000,80000,5,0.02167922,0.02172916,0.02183500
|
||||
10000,90000,5,0.01407034,0.01406240,0.01391000
|
||||
10000,100000,5,0.00943093,0.00943771,0.00954000
|
||||
10000,125000,5,0.00389460,0.00388819,0.00400500
|
||||
10000,150000,5,0.00183031,0.00183603,0.00199000
|
||||
10000,175000,5,0.00094805,0.00094767,0.00087000
|
||||
10000,200000,5,0.00052956,0.00053068,0.00055500
|
||||
10000,250000,5,0.00019571,0.00019591,0.00028500
|
||||
10000,300000,5,0.00008527,0.00008530,0.00009500
|
||||
10000,400000,5,0.00002240,0.00002242,0.00001500
|
||||
10000,600000,5,0.00000327,0.00000327,0.00000500
|
||||
|
@@ -0,0 +1,85 @@
|
||||
#include "bloom_filter/bloom_filter.hpp"
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
std::cerr << "usage: " << argv[0] << " plots/cases.csv\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ifstream csv{argv[1]};
|
||||
std::string line;
|
||||
std::getline(csv, line); // skipping header n,m,k
|
||||
|
||||
std::mt19937_64 rng{}; // no seed so this is deterministic
|
||||
constexpr uint32_t TOTAL_TRIALS = 20;
|
||||
constexpr uint32_t ELEMS_CHECK = 10000;
|
||||
|
||||
std::printf("n,m,k,theoretical_fpp,filter_fpp,actual_fpp\n");
|
||||
|
||||
while (std::getline(csv, line)) {
|
||||
if (line.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::stringstream ss(line);
|
||||
std::string n_str, m_str, k_str;
|
||||
std::getline(ss, n_str, ',');
|
||||
std::getline(ss, m_str, ',');
|
||||
std::getline(ss, k_str, ',');
|
||||
|
||||
uint64_t n = std::stoull(n_str);
|
||||
uint64_t m = std::stoull(m_str);
|
||||
uint32_t k = std::stoul(k_str);
|
||||
|
||||
double sum_theoretical_fpp = 0;
|
||||
double sum_filter_fpp = 0;
|
||||
double sum_actual_fpp = 0;
|
||||
|
||||
for (uint32_t trial = 0; trial < TOTAL_TRIALS; trial++) {
|
||||
uint64_t seed1 = rng(), seed2 = rng();
|
||||
BloomFilter filter{static_cast<size_t>(m), k, seed1, seed2};
|
||||
|
||||
std::unordered_set<uint64_t> actual_inserts;
|
||||
for (uint64_t i = 0; i < n; i++) {
|
||||
uint64_t num = rng();
|
||||
actual_inserts.insert(num);
|
||||
filter.put(&num, sizeof(num));
|
||||
}
|
||||
|
||||
uint32_t fp_count = 0;
|
||||
for (uint32_t i = 0; i < ELEMS_CHECK; i++) {
|
||||
uint64_t test = rng();
|
||||
bool actually_present = actual_inserts.count(test);
|
||||
bool filter_contains = filter.may_contain(&test, sizeof(test));
|
||||
fp_count += !actually_present && filter_contains;
|
||||
}
|
||||
|
||||
double theoretical_fpp =
|
||||
std::pow(1 - std::exp(-static_cast<double>(k) * n / m), k);
|
||||
double filter_fpp = filter.false_positive_probability();
|
||||
double actual_fpp = static_cast<double>(fp_count) / ELEMS_CHECK;
|
||||
|
||||
sum_theoretical_fpp += theoretical_fpp;
|
||||
sum_filter_fpp += filter_fpp;
|
||||
sum_actual_fpp += actual_fpp;
|
||||
}
|
||||
|
||||
std::printf("%llu,%llu,%u,%.8f,%.8f,%.8f\n",
|
||||
static_cast<unsigned long long>(n),
|
||||
static_cast<unsigned long long>(m), k,
|
||||
sum_theoretical_fpp / TOTAL_TRIALS,
|
||||
sum_filter_fpp / TOTAL_TRIALS,
|
||||
sum_actual_fpp / TOTAL_TRIALS);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
n,m,k
|
||||
10000,100000,2
|
||||
10000,100000,3
|
||||
10000,100000,4
|
||||
10000,100000,5
|
||||
10000,100000,6
|
||||
10000,100000,7
|
||||
10000,100000,8
|
||||
10000,100000,9
|
||||
10000,100000,10
|
||||
10000,100000,11
|
||||
10000,100000,12
|
||||
10000,100000,13
|
||||
10000,100000,14
|
||||
10000,100000,15
|
||||
1000,100000,5
|
||||
2000,100000,5
|
||||
3000,100000,5
|
||||
4000,100000,5
|
||||
5000,100000,5
|
||||
7500,100000,5
|
||||
10000,100000,5
|
||||
15000,100000,5
|
||||
20000,100000,5
|
||||
30000,100000,5
|
||||
40000,100000,5
|
||||
60000,100000,5
|
||||
80000,100000,5
|
||||
10000,50000,5
|
||||
10000,60000,5
|
||||
10000,70000,5
|
||||
10000,80000,5
|
||||
10000,90000,5
|
||||
10000,100000,5
|
||||
10000,125000,5
|
||||
10000,150000,5
|
||||
10000,175000,5
|
||||
10000,200000,5
|
||||
10000,250000,5
|
||||
10000,300000,5
|
||||
10000,400000,5
|
||||
10000,600000,5
|
||||
|
Reference in New Issue
Block a user