コード例 #1
0
ファイル: shll.py プロジェクト: leelakrishna/hyperloglog
    def __init__(self, error_rate, window, lpfm=None):
        """
        Implementes a Sliding HyperLogLog

        error_rate = abs_err / cardinality
        """

        self.window = window

        if lpfm is not None:
            m = len(lpfm)
            p = int(round(math.log(m, 2)))

            if (1 << p) != m:
                raise ValueError('List length is not power of 2')
            self.LPFM = lpfm

        else:
            if not (0 < error_rate < 1):
                raise ValueError("Error_Rate must be between 0 and 1.")

            # error_rate = 1.04 / sqrt(m)
            # m = 2 ** p

            p = int(math.ceil(math.log((1.04 / error_rate)**2, 2)))
            m = 1 << p
            self.LPFM = [None for i in range(m)]

        self.alpha = get_alpha(p)
        self.p = p
        self.m = m
コード例 #2
0
ファイル: shll.py プロジェクト: JohnEmhoff/hyperloglog
    def __init__(self, error_rate, window, lpfm=None):
        """
        Implementes a Sliding HyperLogLog

        error_rate = abs_err / cardinality
        """

        self.window = window

        if lpfm is not None:
            m = len(lpfm)
            p = int(round(math.log(m, 2)))

            if (1 << p) != m:
                raise ValueError("List length is not power of 2")
            self.LPFM = lpfm

        else:
            if not (0 < error_rate < 1):
                raise ValueError("Error_Rate must be between 0 and 1.")

            # error_rate = 1.04 / sqrt(m)
            # m = 2 ** p

            p = int(math.ceil(math.log((1.04 / error_rate) ** 2, 2)))
            m = 1 << p
            self.LPFM = [None for i in range(m)]

        self.alpha = get_alpha(p)
        self.p = p
        self.m = m
コード例 #3
0
ファイル: test_hll.py プロジェクト: JohnEmhoff/hyperloglog
 def test_alpha(self):
     alpha = [get_alpha(b) for b in range(4, 10)]
     self.assertEqual(alpha, [0.673, 0.697, 0.709, 0.7152704932638152, 0.7182725932495458, 0.7197831133217303])
コード例 #4
0
 def test_alpha(self):
     alpha = [get_alpha(b) for b in range(4, 10)]
     self.assertEqual(alpha, [
         0.673, 0.697, 0.709, 0.7152704932638152, 0.7182725932495458,
         0.7197831133217303
     ])