Browse Source

Add Sorensen-Dice coefficient

Xi Ruoyao 5 years ago
parent
commit
5185a6d35b
1 changed files with 21 additions and 0 deletions
  1. 21 0
      dsc.py

+ 21 - 0
dsc.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+# Sorensen-Dice coefficient: $\frac{2|X \cap Y|}{|X| + |Y|}
+
+match_wifi_num_crit = 1
+
+def dsc(known_pt, new_pt):
+    a = known_pt.wifi_snr
+    b = new_pt.wifi_snr
+    up = 0
+    for mac in a:
+        if mac in b:
+            up += 1
+    if up < match_wifi_num_crit:
+        return None
+    return 2 * up / (len(a) + len(b))
+
+if __name__ == '__main__':
+    from wifiloc import toplev
+    toplev(infile = "basicdata.csv", sim = dsc, bad_wifi_crit = 5000,
+            sim_crit = 0.0)