22 #ifndef CPC_CONFIDENCE_HPP_
23 #define CPC_CONFIDENCE_HPP_
28 #include "cpc_sketch.hpp"
33 static const double ICON_ERROR_CONSTANT = 0.693147180559945286;
36 static const int16_t ICON_LOW_SIDE_DATA [33] = {
51 static const int16_t ICON_HIGH_SIDE_DATA [33] = {
66 static const double HIP_ERROR_CONSTANT = 0.588705011257737332;
69 static const int16_t HIP_LOW_SIDE_DATA [33] = {
84 static const int16_t HIP_HIGH_SIDE_DATA [33] = {
99 double get_icon_confidence_lb(
const cpc_sketch_alloc<A>& sketch,
int kappa) {
100 if (sketch.get_num_coupons() == 0)
return 0.0;
101 const int lg_k = sketch.get_lg_k();
102 const long k = 1 << lg_k;
103 if (lg_k < 4)
throw std::logic_error(
"lgk < 4");
104 if (kappa < 1 || kappa > 3)
throw std::invalid_argument(
"kappa must be between 1 and 3");
105 double x = ICON_ERROR_CONSTANT;
106 if (lg_k <= 14) x = ((double) ICON_HIGH_SIDE_DATA[3 * (lg_k - 4) + (kappa - 1)]) / 10000.0;
107 const double rel = x / sqrt(k);
108 const double eps = kappa * rel;
109 const double est = sketch.get_icon_estimate();
110 double result = est / (1.0 + eps);
111 const double check = sketch.get_num_coupons();
112 if (result < check) result = check;
117 double get_icon_confidence_ub(
const cpc_sketch_alloc<A>& sketch,
int kappa) {
118 if (sketch.get_num_coupons() == 0)
return 0.0;
119 const int lg_k = sketch.get_lg_k();
120 const long k = 1 << lg_k;
121 if (lg_k < 4)
throw std::logic_error(
"lgk < 4");
122 if (kappa < 1 || kappa > 3)
throw std::invalid_argument(
"kappa must be between 1 and 3");
123 double x = ICON_ERROR_CONSTANT;
124 if (lg_k <= 14) x = ((double) ICON_LOW_SIDE_DATA[3 * (lg_k - 4) + (kappa - 1)]) / 10000.0;
125 const double rel = x / sqrt(k);
126 const double eps = kappa * rel;
127 const double est = sketch.get_icon_estimate();
128 const double result = est / (1.0 - eps);
133 double get_hip_confidence_lb(
const cpc_sketch_alloc<A>& sketch,
int kappa) {
134 if (sketch.get_num_coupons() == 0)
return 0.0;
135 const int lg_k = sketch.get_lg_k();
136 const long k = 1 << lg_k;
137 if (lg_k < 4)
throw std::logic_error(
"lgk < 4");
138 if (kappa < 1 || kappa > 3)
throw std::invalid_argument(
"kappa must be between 1 and 3");
139 double x = HIP_ERROR_CONSTANT;
140 if (lg_k <= 14) x = ((double) HIP_HIGH_SIDE_DATA[3 * (lg_k - 4) + (kappa - 1)]) / 10000.0;
141 const double rel = x / (sqrt((
double) k));
142 const double eps = ((double) kappa) * rel;
143 const double est = sketch.get_hip_estimate();
144 double result = est / (1.0 + eps);
145 const double check = (double) sketch.get_num_coupons();
146 if (result < check) result = check;
151 double get_hip_confidence_ub(
const cpc_sketch_alloc<A>& sketch,
int kappa) {
152 if (sketch.get_num_coupons() == 0)
return 0.0;
153 const int lg_k = sketch.get_lg_k();
154 const long k = 1 << lg_k;
155 if (lg_k < 4)
throw std::logic_error(
"lgk < 4");
156 if (kappa < 1 || kappa > 3)
throw std::invalid_argument(
"kappa must be between 1 and 3");
157 double x = HIP_ERROR_CONSTANT;
158 if (lg_k <= 14) x = ((double) HIP_LOW_SIDE_DATA[3 * (lg_k - 4) + (kappa - 1)]) / 10000.0;
159 const double rel = x / sqrt(k);
160 const double eps = kappa * rel;
161 const double est = sketch.get_hip_estimate();
162 const double result = est / (1.0 - eps);
DataSketches namespace.
Definition: binomial_bounds.hpp:38