-
Notifications
You must be signed in to change notification settings - Fork 0
/
noisy_location.py
62 lines (48 loc) · 1.68 KB
/
noisy_location.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
#
# It simply adds noise to the receiver locations
# using different methods.
# Also given an option to adjust RSS measurements
#
#
from __future__ import print_function
from localize.localize import *
import os
def calculate_localization_error(recv_list, trans_list, grid_centers, k, verbose=False):
NOISE_VAL = 10.0
error = []
for i in range(len(recv_list)):
curr_recv_list = recv_list[i]
# sample k receivers
sampled_receivers = random.sample(curr_recv_list, k)
# noisy_recv_list = add_location_noise(recv_list[i], NOISE_VAL)
# noisy_recv_list = add_location_noise_vary_privacy(recv_list[i], NOISE_VAL)
# noisy_recv_list = false_location_estimate_rss(sampled_receivers, NOISE_VAL)
noisy_recv_list = random_false_location(recv_list[i], grid=(10, 13, -5, -5))
tx_loc = localize(noisy_recv_list, grid_centers)[0]
e = edist(tx_loc[0], tx_loc[1], trans_list[i][0], trans_list[i][1])
error.append(e)
if verbose:
print("Error:", "{0:.2f}".format(e), "m")
avg_error = np.mean(error)
if verbose:
print("Average Error: ", "{0:.2f}".format(avg_error), "m")
return avg_error
def multirun():
NUM_REC = 43
# read the data
loc, rss = read_dataset()
recv_list, trans_list = get_receiver_snapshots(loc, rss, NUM_REC)
grid_centers = calculate_grid_centers(10, 13, -5, -5, 1.0)
NUM_TRIALS = 100
for j in range(42, 43):
error_list = []
for i in range(NUM_TRIALS):
e = calculate_localization_error(recv_list, trans_list, grid_centers, j)
# print ("TRIAL: ", i, " error: ", e)
error_list.append(e)
print ("After ", NUM_TRIALS, " for group size:", j, " Error: ", np.mean(error_list))
def main():
multirun()
if __name__=='__main__':
main()