2012年4月8日

Reservoir Sampling

摘要: Reservoir Sampling:从N个数中随机抽取k个元素,保证每个元素被选中的概率相等,N不知道有多大。分析:这个问题称为蓄水池抽样,经典方法:Init : a reservoir with the size: kfor(int i = k + 1; i <= N; ++i){ m = random(1, i); if(k >= m) swap the mth value with the ith value;}这个每个元素被选择的概率为k/N,证明网上很多。简单证明:假设现在从第i+1个选择下一个元素,现证明每一个元素被选中的概率为k/(i + 1)。对于第i + 1 个 阅读全文

posted @ 2012-04-08 10:57 buptLizer 阅读(2781) 评论(0) 推荐(0) 编辑

导航