123456789101112131415161718192021 |
- #!/usr/bin/env python3
- def cosine_sim(known_point, new_point):
- from math import sqrt
- up, d1, d2 = 0.0, 0.0, 0.0
- a, b = known_point, new_point
- for key in a.wifi_snr:
- d1 += a.wifi_snr[key] * a.wifi_snr[key]
- if key in b.wifi_snr:
- up += a.wifi_snr[key] * b.wifi_snr[key]
- for key in b.wifi_snr:
- d2 += b.wifi_snr[key] * b.wifi_snr[key]
- if up == 0:
- return None
- else:
- return up / sqrt(d1) / sqrt(d2)
- if __name__ == '__main__':
- from wifiloc import toplev
- toplev(infile = "basicdata.csv", sim = cosine_sim, bad_wifi_crit = 5000,
- sim_crit = 0.0)
|