-
Notifications
You must be signed in to change notification settings - Fork 2
/
evalConfidence.c
129 lines (108 loc) · 3.82 KB
/
evalConfidence.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2018, Kevin Lang, Oath Research
/*
gcc -O3 -Wall -pedantic -o evalConfidence u32Table.c fm85Util.c fm85.c iconEstimator.c fm85Confidence.c fm85Compression.c fm85Merging.c fm85Testing.c evalConfidence.c
*/
/*******************************************************/
#include "common.h"
#include "fm85Util.h"
#include "u32Table.h"
#include "fm85.h"
#include "iconEstimator.h"
#include "fm85Confidence.h"
#include "fm85Compression.h"
#include "fm85Merging.h"
#include "fm85Testing.h"
/***************************************************************/
Long * chooseTargetNs (Long maxN, Long * returnLen) {
Long num = 0;
Long cur = 0;
while (cur < maxN) {
Long nxt = 17 * cur / 16;
cur += 1;
if (nxt > cur) cur = nxt;
num += 1;
}
Long len = num;
*returnLen = len;
num = 0;
cur = 0;
Long * arr = malloc (len * sizeof(Long));
while (cur < maxN) {
Long nxt = 17 * cur / 16;
cur += 1;
if (nxt > cur) cur = nxt;
arr[num] = cur;
num += 1;
}
return (arr);
}
/***************************************************************/
int main (int argc, char ** argv)
{
Short lgK;
Long numTrials;
int kappa;
U64 twoHashes[2];
Long trialNo;
Long targetI;
Long itemI;
if (argc != 3) {
fprintf (stderr, "Usage: %s log_k numTrials\n", argv[0]);
return(-1);
}
fm85Init ();
lgK = atoi(argv[1]);
numTrials = atol(argv[2]);
Long k = 1LL << lgK;
Long numTargetNs;
Long * targetNs = chooseTargetNs(1000LL * k, &numTargetNs);
Long maxN = targetNs[numTargetNs-1];
Long *iconOutLoCount[4] = {NULL, NULL, NULL, NULL};
Long *iconOutHiCount[4] = {NULL, NULL, NULL, NULL};
Long *hipOutLoCount[4] = {NULL, NULL, NULL, NULL};
Long *hipOutHiCount[4] = {NULL, NULL, NULL, NULL};
for (kappa = 1; kappa <= 3; kappa++) {
iconOutLoCount[kappa] = calloc(numTargetNs, sizeof(Long)); // zero filled
iconOutHiCount[kappa] = calloc(numTargetNs, sizeof(Long));
hipOutLoCount[kappa] = calloc(numTargetNs, sizeof(Long));
hipOutHiCount[kappa] = calloc(numTargetNs, sizeof(Long));
}
for (trialNo = 0; trialNo < numTrials; trialNo++) {
FM85 * sketch = fm85Make (lgK);
targetI = 0;
for (itemI = 1; itemI <= maxN; itemI++) {
getTwoRandomHashes (twoHashes);
fm85Update (sketch, twoHashes[0], twoHashes[1]);
if (itemI == targetNs[targetI]) {
double dn = (double) targetNs[targetI];
for (kappa = 1; kappa <= 3; kappa++) {
if (dn < getIconConfidenceLB(sketch, kappa)) { iconOutLoCount[kappa][targetI]++; }
if (dn > getIconConfidenceUB(sketch, kappa)) { iconOutHiCount[kappa][targetI]++; }
if (dn < getHIPConfidenceLB(sketch, kappa)) { hipOutLoCount[kappa][targetI]++; }
if (dn > getHIPConfidenceUB(sketch, kappa)) { hipOutHiCount[kappa][targetI]++; }
}
targetI++;
}
}
fm85Free(sketch);
}
for (targetI = 0; targetI < numTargetNs; targetI++) {
printf ("%lld\t%lld", targetNs[targetI], k);
printf ("\t%.9f\t%.9f\t%.9f\t%.9f",
((double) iconOutLoCount[2][targetI]) / ((double) numTrials),
((double) iconOutHiCount[2][targetI]) / ((double) numTrials),
((double) hipOutLoCount[2][targetI]) / ((double) numTrials),
((double) hipOutHiCount[2][targetI]) / ((double) numTrials));
printf ("\t%.9f\t%.9f\t%.9f\t%.9f",
((double) iconOutLoCount[1][targetI]) / ((double) numTrials),
((double) iconOutHiCount[1][targetI]) / ((double) numTrials),
((double) hipOutLoCount[1][targetI]) / ((double) numTrials),
((double) hipOutHiCount[1][targetI]) / ((double) numTrials));
printf ("\t%.9f\t%.9f\t%.9f\t%.9f",
((double) iconOutLoCount[3][targetI]) / ((double) numTrials),
((double) iconOutHiCount[3][targetI]) / ((double) numTrials),
((double) hipOutLoCount[3][targetI]) / ((double) numTrials),
((double) hipOutHiCount[3][targetI]) / ((double) numTrials));
printf ("\n");
}
}