-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinference.py
More file actions
19 lines (15 loc) · 711 Bytes
/
inference.py
File metadata and controls
19 lines (15 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import math
from features import ext_feat, slt_feat
# Computes posterior probability of spam membership given Bloom filter match using Bayes' rule.
def post_mbshp_prob(bf, item, mi_scores, prior=0.1, threshold=0.01):
selected = slt_feat(ext_feat(item), mi_scores, threshold)
if not selected or not all(bf.contains(f) for f in selected):
return 0.0
p_fp = bf.theoretical_fpr()
return prior / (prior + p_fp * (1 - prior))
# Computes binary conditional entropy of the posterior probability.
def cond_ent(posterior):
if posterior <= 0.0 or posterior >= 1.0:
return 0.0
return -(posterior * math.log2(posterior)
+ (1 - posterior) * math.log2(1 - posterior))