Skip to content

Commit b382413

Browse files
authored
Merge pull request #55 from AL-JiongYang/appmc6
Release ApproxMC6
2 parents 1cba322 + 03829cb commit b382413

File tree

4 files changed

+65
-76
lines changed

4 files changed

+65
-76
lines changed

src/appmc_constants.cpp

-67
Original file line numberDiff line numberDiff line change
@@ -69,73 +69,6 @@ Constants::Constants() {
6969
"3600,1,11,13,20,25,26,54,57,63,72,79,81,88,91,105,108,115,122,129,145,153,161,170,191,204,231,246,280,301,351,381,458,508,641,736,1039,1308,",
7070
}};
7171

72-
iterationConfidences = {{
73-
0.64, 0.704512, 0.7491026944, 0.783348347699,
74-
0.81096404252, 0.833869604432, 0.853220223135, 0.869779929746,
75-
0.884087516258, 0.896540839559, 0.907443973174, 0.917035558936,
76-
0.92550684748, 0.933013712405, 0.939684956024, 0.945628233538,
77-
0.950934391703, 0.955680718969, 0.9599334282, 0.963749585636,
78-
0.967178632062, 0.970263598173, 0.973042086923, 0.975547075737,
79-
0.977807577642, 0.979849190627, 0.98169455749, 0.98336375333,
80-
0.984874614022, 0.98624301618, 0.987483116952, 0.988607560325,
81-
0.989627655353, 0.990553530695, 0.991394269076, 0.992158024647,
82-
0.99285212571, 0.993483164877, 0.994057078393, 0.994579216081,
83-
0.995054403148, 0.995486994909, 0.995880925327, 0.996239750132,
84-
0.996566685198, 0.99686464074, 0.99713625183, 0.997383905666,
85-
0.997609765964, 0.997815794807, 0.998003772226, 0.998175313784,
86-
0.998331886363, 0.998474822355, 0.998605332446, 0.998724517108,
87-
0.998833376973, 0.998932822179, 0.999023680805, 0.999106706494,
88-
0.999182585332, 0.999251942072, 0.999315345767, 0.999373314859,
89-
0.999426321798, 0.999474797213, 0.99951913371, 0.999559689296,
90-
0.9995967905, 0.999630735199, 0.99966179518, 0.999690218475,
91-
0.999716231474, 0.999740040852, 0.999761835313, 0.999781787183,
92-
0.999800053855, 0.999816779104, 0.999832094286, 0.999846119426,
93-
0.999858964211, 0.999870728891, 0.999881505109, 0.999891376644,
94-
0.999900420098, 0.999908705519, 0.999916296969, 0.99992325304,
95-
0.999929627331, 0.999935468875, 0.999940822533, 0.999945729354,
96-
0.999950226904, 0.999954349561, 0.999958128793, 0.999961593401,
97-
0.999964769754, 0.999967681991, 0.999970352216, 0.999972800666,
98-
0.999975045876, 0.999977104817, 0.999978993036, 0.999980724771,
99-
0.999982313065, 0.999983769866, 0.999985106122, 0.99998633186,
100-
0.99998745627, 0.999988487774, 0.999989434086, 0.999990302279,
101-
0.999991098834, 0.99999182969, 0.999992500293, 0.999993115634,
102-
0.999993680288, 0.999994198449, 0.999994673963, 0.999995110355,
103-
0.999995510858, 0.999995878437, 0.999996215809, 0.999996525467,
104-
0.999996809697, 0.999997070596, 0.999997310086, 0.999997529931,
105-
0.999997731749, 0.999997917023, 0.999998087116, 0.999998243274,
106-
0.999998386645, 0.999998518279, 0.99999863914, 0.999998750113,
107-
0.999998852009, 0.999998945574, 0.999999031492, 0.999999110388,
108-
0.99999918284, 0.999999249374, 0.999999310476, 0.999999366591,
109-
0.999999418127, 0.999999465459, 0.99999950893, 0.999999548857,
110-
0.99999958553, 0.999999619214, 0.999999650153, 0.999999678573,
111-
0.999999704678, 0.999999728658, 0.999999750687, 0.999999770922,
112-
0.999999789512, 0.999999806589, 0.999999822278, 0.999999836692,
113-
0.999999849933, 0.999999862099, 0.999999873277, 0.999999883546,
114-
0.999999892982, 0.999999901651, 0.999999909617, 0.999999916936,
115-
0.999999923661, 0.999999929841, 0.999999935519, 0.999999940737,
116-
0.999999945532, 0.999999949938, 0.999999953987, 0.999999957708,
117-
0.999999961128, 0.99999996427, 0.999999967158, 0.999999969812,
118-
0.999999972252, 0.999999974493, 0.999999976554, 0.999999978447,
119-
0.999999980188, 0.999999981788, 0.999999983258, 0.999999984609,
120-
0.999999985851, 0.999999986993, 0.999999988043, 0.999999989007,
121-
0.999999989894, 0.999999990709, 0.999999991458, 0.999999992147,
122-
0.99999999278, 0.999999993362, 0.999999993897, 0.999999994389,
123-
0.999999994841, 0.999999995257, 0.999999995639, 0.99999999599,
124-
0.999999996313, 0.99999999661, 0.999999996883, 0.999999997134,
125-
0.999999997364, 0.999999997577, 0.999999997772, 0.999999997951,
126-
0.999999998116, 0.999999998267, 0.999999998407, 0.999999998535,
127-
0.999999998653, 0.999999998761, 0.999999998861, 0.999999998952,
128-
0.999999999036, 0.999999999114, 0.999999999185, 0.999999999251,
129-
0.999999999311, 0.999999999366, 0.999999999417, 0.999999999464,
130-
0.999999999507, 0.999999999547, 0.999999999583, 0.999999999616,
131-
0.999999999647, 0.999999999676, 0.999999999702, 0.999999999726,
132-
0.999999999748, 0.999999999768, 0.999999999786, 0.999999999804,
133-
0.999999999819, 0.999999999834, 0.999999999847, 0.999999999859,
134-
0.999999999871, 0.999999999881, 0.999999999891, 0.999999999899,
135-
0.999999999907, 0.999999999915, 0.999999999922, 0.999999999928,
136-
0.999999999934, 0.999999999939, 0.999999999944, 0.999999999948
137-
}};
138-
13972
readInSparseValues();
14073
}
14174

src/appmc_constants.h

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class Constants
5555
Constants();
5656
vector<double> probval;
5757
vector<VarMap> index_var_maps;
58-
vector<double> iterationConfidences;
5958

6059
private:
6160
vector<string> sparseprobvalues;

src/counter.cpp

+63-7
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ void Counter::simplify()
333333
solver->set_full_bve(0);
334334
}
335335

336+
// compute the error bound
337+
double Counter::calc_error_bound(uint32_t t, double p)
338+
{
339+
double curr = pow(p, t);
340+
double sum = curr;
341+
for (auto k=t-1; k>=std::ceil(double(t)/2); k--) {
342+
curr *= double((k+1))/(t-k) * (1-p)/p;
343+
sum += curr;
344+
}
345+
346+
return sum;
347+
}
348+
336349
//Set up probabilities, threshold and measurements
337350
void Counter::set_up_probs_threshold_measurements(
338351
uint32_t& measurements, SparseData& sparse_data)
@@ -363,12 +376,31 @@ void Counter::set_up_probs_threshold_measurements(
363376
);
364377

365378
verb_print(1, "[appmc] threshold set to " << threshold << " sparse: " << (int)using_sparse);
366-
measurements = (int)std::ceil(std::log2(3.0/conf.delta)*17);
367-
for (int count = 0; count < 256; count++) {
368-
if (constants.iterationConfidences[count] >= 1 - conf.delta) {
369-
measurements = count*2+1;
370-
break;
371-
}
379+
380+
double p_L = 0;
381+
if (conf.epsilon < sqrt(2)-1) {
382+
p_L = 0.262;
383+
} else if (conf.epsilon < 1) {
384+
p_L = 0.157;
385+
} else if (conf.epsilon < 3) {
386+
p_L = 0.085;
387+
} else if (conf.epsilon < 4*sqrt(2)-1) {
388+
p_L = 0.055;
389+
} else {
390+
p_L = 0.023;
391+
}
392+
393+
double p_U = 0;
394+
if (conf.epsilon < 3) {
395+
p_U = 0.169;
396+
} else {
397+
p_U = 0.044;
398+
}
399+
400+
for (measurements = 1; ; measurements+=2) {
401+
if (calc_error_bound(measurements, p_L) + calc_error_bound(measurements, p_U) <= conf.delta) {
402+
break;
403+
}
372404
}
373405
}
374406

@@ -417,6 +449,30 @@ ApproxMC::SolCount Counter::calc_est_count()
417449
ApproxMC::SolCount ret_count;
418450
if (num_hash_list.empty() || num_count_list.empty()) return ret_count;
419451

452+
// round model counts
453+
if (num_hash_list[0] > 0) {
454+
double pivot = 9.84*(1.0+(1.0/conf.epsilon))*(1.0+(1.0/conf.epsilon));
455+
for (auto cnt_it = num_count_list.begin(); cnt_it != num_count_list.end(); cnt_it++) {
456+
if (conf.epsilon < sqrt(2)-1) {
457+
if (*cnt_it < sqrt(1+2*conf.epsilon)/2 * pivot) {
458+
*cnt_it = sqrt(1+2*conf.epsilon)/2 * pivot;
459+
}
460+
} else if (conf.epsilon < 1) {
461+
if (*cnt_it < pivot / sqrt(2)) {
462+
*cnt_it = pivot / sqrt(2);
463+
}
464+
} else if (conf.epsilon < 3) {
465+
if (*cnt_it < pivot) {
466+
*cnt_it = pivot;
467+
}
468+
} else if (conf.epsilon < 4*sqrt(2)-1) {
469+
*cnt_it = pivot;
470+
} else {
471+
*cnt_it = sqrt(2)*pivot;
472+
}
473+
}
474+
}
475+
420476
const auto min_hash = find_min(num_hash_list);
421477
auto cnt_it = num_count_list.begin();
422478
for (auto hash_it = num_hash_list.begin()
@@ -431,7 +487,7 @@ ApproxMC::SolCount Counter::calc_est_count()
431487
*cnt_it *= pow(2, (*hash_it) - min_hash);
432488
}
433489
ret_count.valid = true;
434-
ret_count.cellSolCount = find_median(num_count_list);
490+
ret_count.cellSolCount = std::round(find_median(num_count_list));
435491
ret_count.hashCount = min_hash;
436492

437493
return ret_count;

src/counter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ class Counter {
168168
void read_stdin(SATSolver* solver2);
169169
int find_best_sparse_match();
170170
void set_up_probs_threshold_measurements(uint32_t& measurements, SparseData& sparse_data);
171+
double calc_error_bound(uint32_t t, double p);
171172

172173
//Data so we can output temporary count when catching the signal
173174
vector<uint64_t> num_hash_list;
174-
vector<int64_t> num_count_list;
175+
vector<double> num_count_list;
175176
template<class T> T find_median(const vector<T>& nums);
176177
template<class T> T find_min(const vector<T>& nums);
177178

0 commit comments

Comments
 (0)