-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultihopCalibration.py
More file actions
76 lines (65 loc) · 2.44 KB
/
Copy pathMultihopCalibration.py
File metadata and controls
76 lines (65 loc) · 2.44 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from DataCreator import DataCreator
from SCAN import scan
from MLS import mls
from CalibrationStatistics import CalibrationStatistics
from ResultPlotter import ResultPlotter
import numpy as np
import argparse
import json
'''
Main script for running experiment!
Run "python MultihopCalibration.py --config_file=config.json"
'''
'''
Get the config (json) file, see "config.json" for default one
'''
parser = argparse.ArgumentParser(description='Parse location of config file (json).')
parser.add_argument('--config_file', type=str, default='config.json',
help='path to json config file, see config.json for default')
args = parser.parse_args()
with open(args.config_file) as json_data_file:
config = json.load(json_data_file)
Results = {}
'''
Main loop
'''
for run in range(config['numRuns']):
# we use the run number as random seed
randomSeed = run
# create new data
myDataCreator = DataCreator(config['numSamples'],
config['numSensors'],
config['numHops'],
config['noiseLowerBound'],
config['noiseUpperBound'],
config['calparLowerBound'],
config['calparUpperBound'],
config['phenLowerBound'],
config['phenUpperBound'],
randomSeed)
myDataCreator.create_calibration_points()
# loop of different calibration methods
for m in config['calibrationMethods']:
calMethod = locals()[m]
calB = []
calTestData = []
calStats = []
# loop over the hops, i.e. perform calibration hop-by-hop
for hop in range(config['numHops']):
# get the data for calibration
X,Y = myDataCreator.get_train_data(hop)
if hop == 0:
# in the first hop we calibrate the sensor array to the true values
calB.append(calMethod(X,Y))
else:
# in the following hops (hop > 0) we calibrate the array to the previously calibrated one
calB.append(calMethod(X,virtY))
Xt,GT = myDataCreator.get_test_data(hop)
virtY = calB[hop].dot(Xt)
calTestData.append(virtY)
trueB = myDataCreator.get_true_B(hop)
calStats.append(CalibrationStatistics(virtY,GT,calB[hop],trueB))
Results.update({ m + '_run_'+str(run): calStats})
# plot the results
if config['statsToPlot']:
ResultPlotter(Results,config['statsToPlot'],config['calibrationMethods'],config['numRuns'],config['numHops'])