datasketches-cpp
RelativeErrorTables-internal.hpp
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef _RELATIVEERRORTABLES_INTERNAL_HPP_
21 #define _RELATIVEERRORTABLES_INTERNAL_HPP_
22 
23 #include "RelativeErrorTables.hpp"
24 
25 namespace datasketches {
26 
27 //case 0
28 static double HIP_LB[] = //sd 1, 2, 3
29  { //Q(.84134), Q(.97725), Q(.99865) respectively
30  0.207316195, 0.502865572, 0.882303765, //4
31  0.146981579, 0.335426881, 0.557052, //5
32  0.104026721, 0.227683872, 0.365888317, //6
33  0.073614601, 0.156781585, 0.245740374, //7
34  0.05205248, 0.108783763, 0.168030442, //8
35  0.036770852, 0.075727545, 0.11593785, //9
36  0.025990219, 0.053145536, 0.080772263, //10
37  0.018373987, 0.037266176, 0.056271814, //11
38  0.012936253, 0.02613829, 0.039387631, //12
39  };
40 
41 //case 1
42 static double HIP_UB[] = //sd 1, 2, 3
43  { //Q(.15866), Q(.02275), Q(.00135) respectively
44  -0.207805347, -0.355574279, -0.475535095, //4
45  -0.146988328, -0.262390832, -0.360864026, //5
46  -0.103877775, -0.191503663, -0.269311582, //6
47  -0.073452978, -0.138513438, -0.198487447, //7
48  -0.051982806, -0.099703123, -0.144128618, //8
49  -0.036768609, -0.07138158, -0.104430324, //9
50  -0.025991325, -0.050854296, -0.0748143, //10
51  -0.01834533, -0.036121138, -0.05327616, //11
52  -0.012920332, -0.025572893, -0.037896952, //12
53  };
54 
55 //case 2
56 static double NON_HIP_LB[] = //sd 1, 2, 3`
57  { //Q(.84134), Q(.97725), Q(.99865) respectively
58  0.254409839, 0.682266712, 1.304022158, //4
59  0.181817353, 0.443389054, 0.778776219, //5
60  0.129432281, 0.295782195, 0.49252279, //6
61  0.091640655, 0.201175925, 0.323664385, //7
62  0.064858051, 0.138523393, 0.218805328, //8
63  0.045851855, 0.095925072, 0.148635751, //9
64  0.032454144, 0.067009668, 0.102660669, //10
65  0.022921382, 0.046868565, 0.071307398, //11
66  0.016155679, 0.032825719, 0.049677541 //12
67  };
68 
69 //case 3
70 static double NON_HIP_UB[] = //sd 1, 2, 3
71  { //Q(.15866), Q(.02275), Q(.00135) respectively
72  -0.256980172, -0.411905944, -0.52651057, //4
73  -0.182332109, -0.310275547, -0.412660505, //5
74  -0.129314228, -0.230142294, -0.315636197, //6
75  -0.091584836, -0.16834013, -0.236346847, //7
76  -0.06487411, -0.122045231, -0.174112107, //8
77  -0.04591465, -0.08784505, -0.126917615, //9
78  -0.032433119, -0.062897613, -0.091862929, //10
79  -0.022960633, -0.044875401, -0.065736049, //11
80  -0.016186662, -0.031827816, -0.046973459 //12
81  };
82 
83 template<typename A>
84 double RelativeErrorTables<A>::getRelErr(const bool upperBound, const bool oooFlag,
85  const int lgK, const int stdDev) {
86  const int idx = ((lgK - 4) * 3) + (stdDev - 1);
87  const int sw = (oooFlag ? 2 : 0) | (upperBound ? 1 : 0);
88  double f = 0;
89  switch (sw) {
90  case 0 : { // HIP, LB
91  f = HIP_LB[idx];
92  break;
93  }
94  case 1 : { // HIP, UB
95  f = HIP_UB[idx];
96  break;
97  }
98  case 2 : { // NON_HIP, LB
99  f = NON_HIP_LB[idx];
100  break;
101  }
102  case 3 : { // NON_HIP, UB
103  f = NON_HIP_UB[idx];
104  break;
105  }
106  }
107  return f;
108 }
109 
110 }
111 
112 #endif // _RELATIVEERRORTABLES_INTERNAL_HPP_
DataSketches namespace.
Definition: binomial_bounds.hpp:38