@@ -7,6 +7,8 @@ class Hyperparameters(object):
77 """
88
99 def __init__ (self ):
10+ """Hyper parameters initialiser setting default values"""
11+
1012 self .__learning_rate = 0.001
1113 self .__hidden_size = {
1214 "front_layers" : [64 ],
@@ -26,6 +28,8 @@ def __init__(self):
2628 self .__network_type = "lstm"
2729
2830 def __eq__ (self , other ):
31+ """Comparator for Hyperparameters objects"""
32+
2933 if isinstance (other , Hyperparameters ):
3034 return all ([
3135 self .__learning_rate == other .learning_rate ,
@@ -172,22 +176,53 @@ def network_type(self, value):
172176 self .__network_type = value
173177
174178 def to_json (self ):
179+ """Serialise hyper parameters into JSON string
180+
181+ Returns:
182+ string -- The serialised hyper parameters in JSON
183+ """
175184 return json .dumps (self , default = lambda o : o .__dict__ , sort_keys = True , indent = 4 )
176185
177186 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+ """
178192 with open (file_path , "w" , encoding = "utf8" ) as file :
179193 file .write (self .to_json ())
180194
181195 def clone (self ):
196+ """Make a cloned hyper parameters object
197+
198+ Returns:
199+ Hyperparameters -- The cloned Hyperparameters object.
200+ """
182201 return self .from_json (self .to_json ())
183202
184203 @classmethod
185204 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+ """
186213 hp = cls ()
187214 hp .__dict__ = json .loads (json_str )
188215 return hp
189216
190217 @classmethod
191218 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+ """
192227 with open (file_path , "r" , encoding = "utf8" ) as file :
193228 return cls .from_json (file .read ())
0 commit comments