当前位置:   article > 正文

Bloom Filter 原理 及C++ 实现_c++ bloom filter有库吗

c++ bloom filter有库吗

布隆过滤器[1](Bloom Filter)是由布隆(Burton Howard Bloom)在1970年提出的。
它实际上是由一个很长的二进制向量和一系列随机映射函数组成,布隆过滤器可以用于检索一个元素是否在一个集合中。

它的优点是空间效率和查询时间都远远超过一般的算法,缺点是有一定的误识别率(假正例False positives,即Bloom Filter报告某一元素存在于某集合中,但是实际上该元素并不在集合中)和删除困难,但是没有识别错误的情形(即假反例False negatives,如果某个元素确实没有在该集合中,那么Bloom Filter 是不会报告该元素存在于集合中的,所以不会漏报)。

 

主要思路是

1. 使用位图或者位数组表示m个0的集合M;

2. 使用K个hash函数将N个元素映射到集合M中的某一位,并使这位为1;

3. 查询时候当给一个query 使用K个hash函数映射后,对应的m为都为1,则存在,否则不存在。

具体思路使用M 位数组表示集合

Bloom filter 会使用K个hash函数 将某一个元素x_i, 映射到M中,如下图所示

判断给定一个元素y在不在这个集合,则用K个hash函数对y做映射,所有位都为1 则存在,否则不存在。

错误率估计

在Chapter 4 “Mining of Massive data”-CMU Anand Rajaraman的书中把错误率的计算:

If a key value is in S, then the element will surely pass through the Bloom filter. However, if the key value is not inS, it might still pass. We need to
understand how to calculate the probability of afalse positive, as a function of n, the bit-array length, mthe number of members of S, and k, the number of
hash functions.
The model to use is throwing darts at targets. Suppose we havextargets
andy darts. Any dart is equally likely to hit any target. After throwing the
darts, how many targets can we expect to be hit at least once?

主要的思路是计算转化为一个飞镖问题,有m个靶位,有n个飞镖,假设每个飞镖有k次机会,(相当于n*k个镖)投中某个特定靶位的概率。

假设我们将hash函数认为是随机的,投镖的过程也是随机的,

那么每次我们投不中特定的靶位的概率为(1-1/m)

投n*k次的话 (1-1/m)^(n*k), 使用

当n*k个镖都投完某一位还为0的概率是p = e^(-kn/m)

 

最优的hash函数个数及位数组的个数:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/556344
推荐阅读
相关标签
  

闽ICP备14008679号