@@ -7,6 +7,8 @@ class Hyperparameters(object):
7
7
"""
8
8
9
9
def __init__ (self ):
10
+ """Hyper parameters initialiser setting default values"""
11
+
10
12
self .__learning_rate = 0.001
11
13
self .__hidden_size = {
12
14
"front_layers" : [64 ],
@@ -26,6 +28,8 @@ def __init__(self):
26
28
self .__network_type = "lstm"
27
29
28
30
def __eq__ (self , other ):
31
+ """Comparator for Hyperparameters objects"""
32
+
29
33
if isinstance (other , Hyperparameters ):
30
34
return all ([
31
35
self .__learning_rate == other .learning_rate ,
@@ -172,22 +176,53 @@ def network_type(self, value):
172
176
self .__network_type = value
173
177
174
178
def to_json (self ):
179
+ """Serialise hyper parameters into JSON string
180
+
181
+ Returns:
182
+ string -- The serialised hyper parameters in JSON
183
+ """
175
184
return json .dumps (self , default = lambda o : o .__dict__ , sort_keys = True , indent = 4 )
176
185
177
186
def to_file (self , file_path ):
187
+ """Serialise hyper parameters into JSON and save the content to a file
188
+
189
+ Arguments:
190
+ file_path {string} -- The path to the file containing saved hyper parameters.
191
+ """
178
192
with open (file_path , "w" , encoding = "utf8" ) as file :
179
193
file .write (self .to_json ())
180
194
181
195
def clone (self ):
196
+ """Make a cloned hyper parameters object
197
+
198
+ Returns:
199
+ Hyperparameters -- The cloned Hyperparameters object.
200
+ """
182
201
return self .from_json (self .to_json ())
183
202
184
203
@classmethod
185
204
def from_json (cls , json_str ):
205
+ """Deserialise JSON string into a Hyperparameters object
206
+
207
+ Arguments:
208
+ json_str {string} -- Hyper parameters in JSON.
209
+
210
+ Returns:
211
+ Hyperparameters -- The deserialised Hyperparameters object.
212
+ """
186
213
hp = cls ()
187
214
hp .__dict__ = json .loads (json_str )
188
215
return hp
189
216
190
217
@classmethod
191
218
def from_file (cls , file_path ):
219
+ """Deserialise a file content into a Hyperparameters object
220
+
221
+ Arguments:
222
+ file_path {string} -- The path to the file containing hyper parameters.
223
+
224
+ Returns:
225
+ Hyperparameters -- The deserialised Hyperparameters object.
226
+ """
192
227
with open (file_path , "r" , encoding = "utf8" ) as file :
193
228
return cls .from_json (file .read ())
0 commit comments