-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.py
62 lines (49 loc) · 2.59 KB
/
Configuration.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
import ConfigParser
import os
import SelfDrivingError
class Configuration:
dqn_gamma = 0
dqn_hidden_neurons = 0
dqn_learning_rate = 0
dqn_temperature = 0
dqn_sample_size = 0
reward_decay = 0
reward_distance = 0
config_parser = None
file_location = ""
def __init__(self):
pass
def load(self, config_filename="default.ini"):
self.config_parser = ConfigParser.ConfigParser()
self.file_location = os.path.join(os.path.dirname(__file__), 'config', config_filename)
if not os.path.isfile(self.file_location):
raise SelfDrivingError("Invalid configuration file location [{}]".format(self.file_location))
self.config_parser.read(self.file_location)
self.dqn_gamma = float(self.config_parser.get('dqn', 'gamma'))
self.dqn_hidden_neurons = int(self.config_parser.get('dqn', 'nb_hidden_neurons'))
self.dqn_learning_rate = float(self.config_parser.get('dqn', 'learning_rate'))
self.dqn_temperature = float(self.config_parser.get('dqn', 'temperature'))
self.dqn_sample_size = int(self.config_parser.get('dqn', 'sample_size'))
self.reward_decay = float(self.config_parser.get('rewards', 'decay_reward'))
self.reward_distance = float(self.config_parser.get('rewards', 'distance_reward'))
def update(self, widget_dict):
self.dqn_gamma = float(widget_dict['dqn']['gamma'])
self.dqn_hidden_neurons = int(widget_dict['dqn']['nb_hidden_neurons'])
self.dqn_learning_rate = float(widget_dict['dqn']['learning_rate'])
self.dqn_temperature = float(widget_dict['dqn']['temperature'])
self.dqn_sample_size = int(widget_dict['dqn']['sample_size'])
self.reward_decay = float(widget_dict['rewards']['decay_reward'])
self.reward_distance = float(widget_dict['rewards']['distance_reward'])
self.save()
def save(self):
self.config_parser.set('dqn', 'gamma', self.dqn_gamma)
self.config_parser.set('dqn', 'nb_hidden_neurons', self.dqn_hidden_neurons)
self.config_parser.set('dqn', 'learning_rate', self.dqn_learning_rate)
self.config_parser.set('dqn', 'temperature', self.dqn_temperature)
self.config_parser.set('dqn', 'sample_size', self.dqn_sample_size)
self.config_parser.set('rewards', 'decay_reward', self.reward_decay)
self.config_parser.set('rewards', 'distance_reward', self.reward_distance)
print("Saving config to [{}]".format(self.file_location))
config_file = open(self.file_location, 'w+')
self.config_parser.write(config_file)
config_file.close()